Revert "Add alert rule option to invert devices and groups "map to" list (#10954)" (#11036)

This reverts commit 7a8d0b9e09.
This commit is contained in:
Kevin Krumm
2020-01-16 01:42:53 -06:00
committed by PipoCanaja
parent 7a8d0b9e09
commit 10b42137e9
6 changed files with 12 additions and 71 deletions

View File

@@ -175,16 +175,12 @@ class AlertUtil
public static function getRules($device_id)
{
$query = "SELECT DISTINCT a.* FROM alert_rules a
LEFT JOIN alert_device_map d ON a.id=d.rule_id AND d.device_id = ?
LEFT JOIN alert_group_map g ON a.id=g.rule_id AND (a.invert_map = 0 OR a.invert_map = 1 AND g.group_id IN (SELECT DISTINCT device_group_id FROM device_group_device WHERE device_id = ?))
LEFT JOIN device_group_device dg ON g.group_id=dg.device_group_id AND dg.device_id = ?
WHERE a.disabled = 0 AND (
(d.device_id IS NULL AND g.group_id IS NULL)
OR (a.invert_map = 0 AND (d.device_id=? OR dg.device_id=?))
OR (a.invert_map = 1 AND (d.device_id != ? OR d.device_id IS NULL) AND (dg.device_id != ? OR dg.device_id IS NULL))
)";
LEFT JOIN alert_device_map d ON a.id=d.rule_id
LEFT JOIN alert_group_map g ON a.id=g.rule_id
LEFT JOIN device_group_device dg ON g.group_id=dg.device_group_id
WHERE a.disabled = 0 AND ((d.device_id IS NULL AND g.group_id IS NULL) OR d.device_id=? OR dg.device_id=?)";
$params = [$device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id];
$params = [$device_id, $device_id];
return dbFetchRows($query, $params);
}

View File

@@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddInvertMapToAlertRules extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('alert_rules', function (Blueprint $table) {
$table->boolean('invert_map')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('alert_rules', function (Blueprint $table) {
$table->dropColumn(['invert_map']);
});
}
}

View File

@@ -58,7 +58,6 @@ $invert = mres(isset($_POST['invert']) ? $_POST['invert'] : null);
$name = mres($_POST['name']);
$proc = mres($_POST['proc']);
$recovery = ($vars['recovery']);
$invert_map = mres(isset($_POST['invert_map']) ? $_POST['invert_map'] : null);
$severity = mres($_POST['severity']);
if (!is_numeric($count)) {
@@ -82,12 +81,6 @@ if ($invert == 'on') {
$recovery = empty($recovery) ? $recovery = false : true;
if ($invert_map == 'on') {
$invert_map = true;
} else {
$invert_map = false;
}
$extra = array(
'mute' => $mute,
'count' => $count,
@@ -108,8 +101,7 @@ if (is_numeric($rule_id) && $rule_id > 0) {
'name' => $name,
'proc' => $proc,
'query' => $query,
'builder' => $builder_json,
'invert_map' => $invert_map
'builder' => $builder_json
),
'alert_rules',
'id=?',
@@ -136,8 +128,7 @@ if (is_numeric($rule_id) && $rule_id > 0) {
'name' => $name,
'proc' => $proc,
'query' => $query,
'builder' => $builder_json,
'invert_map' => $invert_map
'builder' => $builder_json
), 'alert_rules');
if ($rule_id) {

View File

@@ -77,6 +77,5 @@ if (is_array($rule)) {
'builder' => $builder,
'severity' => $rule['severity'],
'adv_query' => $rule['query'],
'invert_map' => $rule['invert_map'],
]);
}

View File

@@ -98,7 +98,7 @@ if (Auth::user()->hasGlobalAdmin()) {
<div class='col-sm-2' title="Show alert status in the webui, but do not issue notifications.">
<input type="checkbox" name="mute" id="mute">
</div>
<label for='invert' class='col-sm-3 col-md-3 control-label' title="Alert when this rule doesn't match." style="vertical-align: top;">Invert rule match: </label>
<label for='invert' class='col-sm-3 col-md-2 control-label' title="Alert when this rule doesn't match." style="vertical-align: top;">Invert match: </label>
<div class='col-sm-2' title="Alert when this rule doesn't match.">
<input type='checkbox' name='invert' id='invert'>
</div>
@@ -109,15 +109,11 @@ if (Auth::user()->hasGlobalAdmin()) {
<input type='checkbox' name='recovery' id='recovery'>
</div>
</div>
<div class="form-group form-inline">
<label for='maps' class='col-sm-3 col-md-2 control-label' title="Restricts this alert rule to the selected devices and groups.">Match devices and groups list: </label>
<div class="col-sm-7" style="width: 56%;">
<div class="form-group" title="Restricts this alert rule to the selected devices or groups.">
<label for='maps' class='col-sm-3 col-md-2 control-label'>Map To: </label>
<div class="col-sm-9 col-md-10">
<select id="maps" name="maps[]" class="form-control" multiple="multiple"></select>
</div>
<div>
<label for='invert_map' class='col-md-1' style="width: 14.1333%;" text-align="left" title="If ON, alert rule check will run on all devices except the selected devices and groups.">All devices except in list: </label>
<input type='checkbox' name='invert_map' id='invert_map'>
</div>
</div>
<div class="form-group" title="Restricts this alert rule to specified transports.">
<label for="transports" class="col-sm-3 col-md-2 control-label">Transports: </label>
@@ -296,7 +292,6 @@ if (Auth::user()->hasGlobalAdmin()) {
$("#invert").bootstrapSwitch('state', false);
$("#recovery").bootstrapSwitch('state', true);
$("#override_query").bootstrapSwitch('state', false);
$("#invert_map").bootstrapSwitch('state', false);
$(this).find("input[type=text]").val("");
$('#count').val('-1');
$('#delay').val('1m');
@@ -370,12 +365,12 @@ if (Auth::user()->hasGlobalAdmin()) {
if (extra.adv_query) {
$('#adv_query').val(extra.adv_query);
}
$("[name='mute']").bootstrapSwitch('state', extra.mute);
$("[name='invert']").bootstrapSwitch('state', extra.invert);
if (typeof extra.recovery == 'undefined') {
extra.recovery = true;
}
if (typeof extra.options == 'undefined') {
extra.options = new Array();
}
@@ -383,13 +378,6 @@ if (Auth::user()->hasGlobalAdmin()) {
extra.options.override_query = false;
}
$("[name='recovery']").bootstrapSwitch('state', extra.recovery);
if (rule.invert_map == 1) {
$("[name='invert_map']").bootstrapSwitch('state', true);
}else{
$("[name='invert_map']").bootstrapSwitch('state', false);
}
$("[name='override_query']").bootstrapSwitch('state', extra.options.override_query);
} else {
$('#count').val('-1');

View File

@@ -75,7 +75,6 @@ alert_rules:
- { Field: query, Type: text, 'Null': false, Extra: '' }
- { Field: builder, Type: text, 'Null': false, Extra: '' }
- { Field: proc, Type: varchar(80), 'Null': true, Extra: '' }
- { Field: invert_map, Type: tinyint(1), 'Null': false, Extra: '', Default: '0' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [id], Unique: true, Type: BTREE }
name: { Name: name, Columns: [name], Unique: true, Type: BTREE }