mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Location based Alert Rule (#11128)
* Location base Alert Rule * travis fix
This commit is contained in:
@@ -103,7 +103,7 @@ $extra_json = json_encode($extra);
|
||||
if (is_numeric($rule_id) && $rule_id > 0) {
|
||||
if (dbUpdate(
|
||||
array(
|
||||
'severity' => $severity,
|
||||
'severity' => $severity,
|
||||
'extra' => $extra_json,
|
||||
'name' => $name,
|
||||
'proc' => $proc,
|
||||
@@ -157,8 +157,11 @@ if (is_numeric($rule_id) && $rule_id > 0) {
|
||||
if (is_numeric($rule_id) && $rule_id > 0) {
|
||||
$devices = [];
|
||||
$groups = [];
|
||||
$locations = [];
|
||||
foreach ((array)$vars['maps'] as $item) {
|
||||
if (starts_with($item, 'g')) {
|
||||
if (starts_with($item, 'l')) {
|
||||
$locations[] = (int)substr($item, 1);
|
||||
} elseif (starts_with($item, 'g')) {
|
||||
$groups[] = (int)substr($item, 1);
|
||||
} else {
|
||||
$devices[] = (int)$item;
|
||||
@@ -167,6 +170,7 @@ if (is_numeric($rule_id) && $rule_id > 0) {
|
||||
|
||||
dbSyncRelationship('alert_device_map', 'rule_id', $rule_id, 'device_id', $devices);
|
||||
dbSyncRelationship('alert_group_map', 'rule_id', $rule_id, 'group_id', $groups);
|
||||
dbSyncRelationship('alert_location_map', 'rule_id', $rule_id, 'location_id', $locations);
|
||||
|
||||
//Update transport groups and transports - can't use dbSyncRelationship
|
||||
$transports = [];
|
||||
@@ -178,7 +182,7 @@ if (is_numeric($rule_id) && $rule_id > 0) {
|
||||
$transports[] = (int)$item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetch transport/group mappings already in db
|
||||
$sql = "SELECT `transport_or_group_id` FROM `alert_transport_map` WHERE `target_type`='single' AND `rule_id`=?";
|
||||
$db_transports = dbFetchColumn($sql, [$rule_id]);
|
||||
|
||||
@@ -33,6 +33,7 @@ if (!is_numeric($vars['alert_id'])) {
|
||||
if (dbDelete('alert_rules', '`id` = ?', array($vars['alert_id']))) {
|
||||
dbDelete('alert_device_map', 'rule_id=?', [$vars['alert_id']]);
|
||||
dbDelete('alert_group_map', 'rule_id=?', [$vars['alert_id']]);
|
||||
dbDelete('alert_location_map', 'rule_id=?', [$vars['alert_id']]);
|
||||
dbDelete('alert_transport_map', 'rule_id=?', [$vars['alert_id']]);
|
||||
dbDelete('alert_template_map', 'alert_rule_id=?', [$vars['alert_id']]);
|
||||
echo $alert_msg_prefix . ' has been deleted.';
|
||||
|
||||
@@ -35,6 +35,10 @@ if (is_numeric($alert_id) && $alert_id > 0) {
|
||||
foreach ($groups as $group) {
|
||||
$maps[] = ['id' => 'g' . $group['group_id'], 'text' => $group['name']];
|
||||
}
|
||||
$locations = dbFetchRows('SELECT `location_id`, `location` FROM `alert_location_map` LEFT JOIN `locations` ON `locations`.`id`=`alert_location_map`.`location_id` WHERE `rule_id`=?', [$alert_id]);
|
||||
foreach ($locations as $location) {
|
||||
$maps[] = ['id' => 'l' . $location['location_id'], 'text' => $location['location']];
|
||||
}
|
||||
|
||||
$transports = [];
|
||||
$members = dbFetchRows('SELECT `transport_or_group_id`, `transport_name`, `transport_type` FROM `alert_transport_map` LEFT JOIN `alert_transports` ON `transport_or_group_id` = `transport_id` WHERE `target_type`="single" AND `rule_id`=?', [$alert_id]);
|
||||
|
||||
Reference in New Issue
Block a user