mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
updated alert template mapping to own table
This commit is contained in:
@@ -20,12 +20,22 @@ if(!is_numeric($_POST['template_id'])) {
|
||||
echo('ERROR: No template selected');
|
||||
exit;
|
||||
} else {
|
||||
if(dbUpdate(array('rule_id' => mres($_POST['rule_id'])), 'alert_templates', '`id`=?', array($_POST['template_id'])) >= 0) {
|
||||
echo('Alert rules have been attached to this template.');
|
||||
exit;
|
||||
} else {
|
||||
echo('ERROR: Alert rules have not been attached to this template.');
|
||||
exit;
|
||||
$rules = preg_split("/,/",mres($_POST['rule_id']));
|
||||
$success = FALSE;
|
||||
foreach ($rules as $rule_id) {
|
||||
$db_id = dbInsert(array('alert_rule_id' => $rule_id, 'alert_templates_id' => mres($_POST['template_id'])), 'alert_template_map');
|
||||
if ($db_id > 0) {
|
||||
$success = TRUE;
|
||||
$ids[] = $db_id;
|
||||
} else {
|
||||
echo('ERROR: Alert rules have not been attached to this template.');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($success === TRUE) {
|
||||
dbDelete('alert_template_map',"id NOT IN (".implode(',',$ids).")");
|
||||
echo "Alert rules have been attached to this template. $template_map_ids";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,9 @@ if(is_admin() === false) {
|
||||
$template_id = ($_POST['template_id']);
|
||||
|
||||
if(is_numeric($template_id) && $template_id > 0) {
|
||||
$template = dbFetchCell("SELECT `rule_id` FROM `alert_templates` WHERE `id` = ? LIMIT 1",array($template_id));
|
||||
$rule_id = split(",", $template);
|
||||
$output = array('rule_id'=>$rule_id);
|
||||
foreach (dbFetchRows("SELECT `alert_rule_id` FROM `alert_template_map` WHERE `alert_templates_id` = ?",array($template_id)) as $rule) {
|
||||
$rules[] = $rule['alert_rule_id'];
|
||||
}
|
||||
$output = array('rule_id'=>$rules);
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user