Assign invalid device_id if a rule is created with a mapping.

Update rule to invalidate `device_id` if a map has been assigned afterwards.
Update rule to restore `device_id` if no more maps are assigned to it.
Remove all maps (if any) if a rule is deleted.
Fixed SQL-schema
This commit is contained in:
f0o
2015-04-04 11:37:07 +00:00
parent 00954ff4d6
commit 441c27a7d4
5 changed files with 45 additions and 18 deletions
+9 -2
View File
@@ -26,7 +26,7 @@ if( empty($rule) || empty($target) ) {
} else {
$raw = $rule;
$rule = dbFetchCell('SELECT id FROM alert_rules WHERE name = ?',array($rule));
if( !is_numeric($target) && $target[0] != "g" ) {
if( !is_numeric($rule) ) {
array_unshift($ret, "ERROR: Could not find rule for '".$raw."'");
} else {
$raw = $target;
@@ -35,7 +35,7 @@ if( empty($rule) || empty($target) ) {
} else {
$target = dbFetchCell('SELECT device_id FROM devices WHERE hostname = ?',array($target));
}
if( !is_numeric($target) && $target[0] != "g" ) {
if( !is_numeric(str_replace('g','',$target)) ) {
array_unshift($ret, "ERROR: Could not find entry for '".$raw."'");
} else {
if(is_numeric($map_id) && $map_id > 0) {
@@ -51,6 +51,13 @@ if( empty($rule) || empty($target) ) {
array_unshift($ret,"ERROR: Failed to add Map: <i>".$rule." = ".$target."</i>");
}
}
if( ($tmp=dbFetchCell('SELECT device_id FROM alert_rules WHERE id = ?',array($rule))) && $tmp[0] != ":" ) {
if(dbUpdate(array('device_id' => ':'.$tmp), 'alert_rules', 'id=?',array($rule)) >= 0) {
$ret[] = "Edited Rule: <i>".$rule." device_id = ':".$tmp."'</i>";
} else {
array_unshift($ret,"ERROR: Failed to edit Rule: <i>".$rule.": device_id = ':".$tmp."'</i>");
}
}
}
}
}