Alert map location fix (#14380)

* Update devices in alert-logs to init_select2

* Fix function ->exists

* Add init_select2 to location filter in ports

* fixes

* Fixed alerts rule system not filtering by location
This commit is contained in:
Kayck Matias
2022-09-23 16:15:46 -03:00
committed by GitHub
parent b993f38903
commit 64dcfcb8cc
4 changed files with 14 additions and 50 deletions

View File

@@ -181,14 +181,15 @@ class AlertUtil
LEFT JOIN alert_device_map d ON a.id=d.rule_id AND (a.invert_map = 0 OR a.invert_map = 1 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 alert_location_map l ON a.id=l.rule_id AND (a.invert_map = 0 OR a.invert_map = 1 AND l.location_id IN (SELECT DISTINCT location_id FROM devices WHERE device_id = ?))
LEFT JOIN devices ld ON l.location_id=ld.location_id AND ld.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))
(d.device_id IS NULL AND g.group_id IS NULL AND l.location_id IS NULL)
OR (a.invert_map = 0 AND (d.device_id=? OR dg.device_id=? OR ld.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) AND (ld.device_id != ? OR ld.device_id IS NULL))
)';
$params = [$device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id];
$params = [$device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id, $device_id];
return dbFetchRows($query, $params);
}

View File

@@ -54,13 +54,9 @@ $common_output[] = '<div class="panel panel-default panel-condensed">
</div>
';
if (isset($_POST['device_id'])) {
$selected_device = '<option value="' . (int) $_POST['device_id'] . '" selected="selected">';
$selected_device .= htmlentities($_POST['hostname']) . '</option>';
} else {
$selected_device = $device_id;
$_POST['device_id'] = $device_id;
}
$device = DeviceCache::get((int) $vars['device_id']);
$device_selected = json_encode($device->exists ? ['id' => $device->device_id, 'text' => $device->displayName()] : '');
if (isset($_POST['state'])) {
$selected_state = '<option value="' . htmlspecialchars($_POST['state']) . '" selected="selected">';
$selected_state .= array_search((int) $_POST['state'], $alert_states) . '</option>';
@@ -112,9 +108,7 @@ if (isset($vars['fromdevice']) && ! $vars['fromdevice']) {
<label> \
<strong>Device&nbsp;</strong> \
</label> \
<select name="device_id" id="device_id" class="form-control input-sm" style="min-width: 175px;"> \
' . $selected_device . ' \
</select> \
<select name="device_id" id="device_id" class="form-control input-sm" style="min-width: 175px;"></select> \
</div> \
';
}
@@ -204,23 +198,6 @@ $common_output[] = '<div class="form-group"> \
});
});
$("#device_id").select2({
allowClear: true,
placeholder: "All Devices",
ajax: {
url: \'ajax_list.php\',
delay: 250,
data: function (params) {
return {
type: \'devices\',
search: params.term,
limit: 8,
page: params.page || 1
};
}
}
}).on(\'select2:select\', function (e) {
$(\'#hostname\').val(e.params.data.text);
});
init_select2("#device_id", "device", {}, ' . $device_selected . ' , "All Devices");
</script>
';

View File

@@ -201,24 +201,7 @@ if ((isset($vars['searchbar']) && $vars['searchbar'] != 'hide') || ! isset($vars
$output .= "<div style='text-align:left;'>";
$output .= "<input title='Port Description' type='text' name='ifAlias' id='ifAlias' class='form-control input-sm' " . $ifaliasvalue . " placeholder='Port Description'>&nbsp;";
$output .= "<select title='Location' name='location' id='location' class='form-control input-sm'>&nbsp;";
$output .= "<option value=''>All Locations</option>";
foreach (getlocations() as $location_row) {
$location = $location_row['location'];
$location_id = $location_row['id'];
if ($location) {
if (isset($vars['location']) && $location_id == $vars['location']) {
$locationselected = 'selected';
} else {
$locationselected = '';
}
$ui_location = strlen($location) > 15 ? substr($location, 0, 15) . '...' : $location;
$output .= "<option value='$location_id' $locationselected>" . clean_bootgrid($ui_location) . '</option>';
}
}
$output .= '</select>&nbsp;';
$output .= "<select title='Location' name='location' id='location' class='form-control input-sm'></select>&nbsp;";
$ignorecheck = isset($vars['ignore']) ? 'checked' : '';
$disabledcheck = isset($vars['disabled']) ? 'checked' : '';

View File

@@ -18,6 +18,8 @@ $errors_visible = var_export($vars['format'] == 'list_detail' || isset($vars['er
$no_refresh = true;
$device = DeviceCache::get((int) $vars['device_id']);
$device_selected = json_encode($device->exists ? ['id' => $device->device_id, 'text' => $device->displayName()] : '');
$location = \App\Models\Location::find((int) $vars['location']);
$location_selected = json_encode(! empty($location) ? ['id' => $location->id, 'text' => $location->location] : '');
if (isset($vars['errors'])) {
$error_sort = ' data-order="desc"';
@@ -133,5 +135,6 @@ var grid = $("#ports").bootgrid({
$(".actionBar").append("<div class=\"pull-left\"><?php echo $output; ?></div>");
init_select2('#device_id', 'device', {}, <?php echo $device_selected ?>, 'All Devices');
init_select2('#location', 'location', {}, <?php echo $location_selected ?>, 'All Locations');
</script>