function thold_graphs_action_execute($action) { global $config, $form_array; include_once $config['base_path'] . '/plugins/thold/thold_functions.php'; if ($action == 'plugin_thold_create') { $selected_items = unserialize(stripslashes($_POST["selected_items"])); $message = ""; input_validate_input_number($_POST["thold_template_id"]); $template = db_fetch_row("SELECT * FROM thold_template WHERE id=" . $_POST["thold_template_id"]); for ($i = 0; $i < count($selected_items); $i++) { /* ================= input validation ================= */ input_validate_input_number($selected_items[$i]); /* ==================================================== */ $graph = $selected_items[$i]; $temp = db_fetch_row("SELECT dtr.*\r\n\t\t\t\t FROM data_template_rrd AS dtr\r\n\t\t\t\t LEFT JOIN graph_templates_item AS gti\r\n\t\t\t\t ON gti.task_item_id=dtr.id\r\n\t\t\t\t LEFT JOIN graph_local AS gl\r\n\t\t\t\t ON gl.id=gti.local_graph_id\r\n\t\t\t\t WHERE gl.id={$graph}"); $data_template_id = $temp['data_template_id']; $local_data_id = $temp['local_data_id']; $data_source = db_fetch_row("SELECT * FROM data_local WHERE id=" . $local_data_id); $data_template_id = $data_source['data_template_id']; $existing = db_fetch_assoc('SELECT id FROM thold_data WHERE rra_id=' . $local_data_id . ' AND data_id=' . $data_template_id); if (count($existing) == 0 && count($template)) { if ($graph) { $rrdlookup = db_fetch_cell("SELECT id FROM data_template_rrd\r\n\t\t\t\t\t\tWHERE local_data_id={$local_data_id}\r\n\t\t\t\t\t\tORDER BY id\r\n\t\t\t\t\t\tLIMIT 1"); $grapharr = db_fetch_row("SELECT graph_template_id\r\n\t\t\t\t\t\tFROM graph_templates_item\r\n\t\t\t\t\t\tWHERE task_item_id={$rrdlookup}\r\n\t\t\t\t\t\tAND local_graph_id={$graph}"); $data_source_name = $template['data_source_name']; $insert = array(); $name = thold_format_name($template, $graph, $local_data_id, $data_source_name); $insert['name'] = $name; $insert['host_id'] = $data_source['host_id']; $insert['rra_id'] = $local_data_id; $insert['graph_id'] = $graph; $insert['data_template'] = $data_template_id; $insert['graph_template'] = $grapharr['graph_template_id']; $insert['thold_hi'] = $template['thold_hi']; $insert['thold_low'] = $template['thold_low']; $insert['thold_fail_trigger'] = $template['thold_fail_trigger']; $insert['thold_enabled'] = $template['thold_enabled']; $insert['bl_ref_time_range'] = $template['bl_ref_time_range']; $insert['bl_pct_down'] = $template['bl_pct_down']; $insert['bl_pct_up'] = $template['bl_pct_up']; $insert['bl_fail_trigger'] = $template['bl_fail_trigger']; $insert['bl_alert'] = $template['bl_alert']; $insert['repeat_alert'] = $template['repeat_alert']; $insert['notify_extra'] = $template['notify_extra']; $insert['alert_phones_extra'] = $template['alert_phones_extra']; $insert['cdef'] = $template['cdef']; $insert['template'] = $template['id']; $insert['template_enabled'] = 'on'; $rrdlist = db_fetch_assoc("SELECT id, data_input_field_id FROM data_template_rrd where local_data_id='{$local_data_id}' and data_source_name='{$data_source_name}'"); $int = array('id', 'data_template_id', 'data_source_id', 'thold_fail_trigger', 'bl_ref_time_range', 'bl_pct_down', 'bl_pct_up', 'bl_fail_trigger', 'bl_alert', 'repeat_alert', 'cdef'); foreach ($rrdlist as $rrdrow) { $data_rrd_id = $rrdrow['id']; $insert['data_id'] = $data_rrd_id; $existing = db_fetch_assoc("SELECT id FROM thold_data WHERE rra_id='{$local_data_id}' AND data_id='{$data_rrd_id}'"); if (count($existing) == 0) { $insert['id'] = 0; $id = sql_save($insert, 'thold_data'); if ($id) { thold_template_update_threshold($id, $insert['template']); $l = db_fetch_assoc("SELECT name FROM data_template where id={$data_template_id}"); $tname = $l[0]['name']; $name = $data_source_name; if ($rrdrow['data_input_field_id'] != 0) { $l = db_fetch_assoc('SELECT name FROM data_input_fields where id=' . $rrdrow['data_input_field_id']); $name = $l[0]['name']; } plugin_thold_log_changes($id, 'created', " {$tname} [{$name}]"); $message .= "Created threshold for the Graph '<i>{$tname}</i>' using the Data Source '<i>{$name}</i>'<br>"; } } } } } } if (strlen($message)) { $_SESSION['thold_message'] = "<font size=-2>{$message}</font>"; } else { $_SESSION['thold_message'] = "<font size=-2>Threshold(s) Already Exist - No Thresholds Created</font>"; } raise_message('thold_created'); } else { return $action; } }
function thold_add_graphs_action_execute() { global $config; include_once $config['base_path'] . '/plugins/thold/thold_functions.php'; $host_id = get_filter_request_var('host_id'); $local_graph_id = get_filter_request_var('local_data_id'); $thold_template_id = get_filter_request_var('thold_template_id'); $message = ''; $template = db_fetch_row_prepared('SELECT * FROM thold_template WHERE id = ?', array($thold_template_id)); $temp = db_fetch_row_prepared('SELECT dtr.* FROM data_template_rrd AS dtr LEFT JOIN graph_templates_item AS gti ON gti.task_item_id=dtr.id LEFT JOIN graph_local AS gl ON gl.id=gti.local_graph_id WHERE gl.id = ?', array($local_graph_id)); $data_template_id = $temp['data_template_id']; $local_data_id = $temp['local_data_id']; $data_source = db_fetch_row_prepared('SELECT * FROM data_local WHERE id = ?', array($local_data_id)); $data_template_id = $data_source['data_template_id']; /* allow duplicate thresholds, but only from differing templates */ $existing = db_fetch_assoc('SELECT id FROM thold_data WHERE local_data_id=' . $local_data_id . ' AND data_template_rrd_id=' . $data_template_id . ' AND thold_template_id=' . $template['id'] . " AND template_enabled='on'"); if (count($existing) == 0 && count($template)) { if ($local_graph_id) { $rrdlookup = db_fetch_cell("SELECT id FROM data_template_rrd WHERE local_data_id={$local_data_id} ORDER BY id LIMIT 1"); $grapharr = db_fetch_row("SELECT graph_template_id FROM graph_templates_item WHERE task_item_id={$rrdlookup} AND local_graph_id = {$local_graph_id}"); $desc = db_fetch_cell_prepared('SELECT name_cache FROM data_template_data WHERE local_data_id = ? LIMIT 1', array($local_data_id)); $data_source_name = $template['data_source_name']; $insert = array(); $name = thold_format_name($template, $local_graph_id, $local_data_id, $data_source_name); $insert['name'] = $name; $insert['host_id'] = $data_source['host_id']; $insert['local_data_id'] = $local_data_id; $insert['local_graph_id'] = $local_graph_id; $insert['data_template_id'] = $data_template_id; $insert['graph_template_id'] = $grapharr['graph_template_id']; $insert['thold_hi'] = $template['thold_hi']; $insert['thold_low'] = $template['thold_low']; $insert['thold_fail_trigger'] = $template['thold_fail_trigger']; $insert['thold_enabled'] = $template['thold_enabled']; $insert['thold_warning_hi'] = $template['thold_warning_hi']; $insert['thold_warning_low'] = $template['thold_warning_low']; $insert['thold_warning_fail_trigger'] = $template['thold_warning_fail_trigger']; $insert['bl_ref_time_range'] = $template['bl_ref_time_range']; $insert['bl_pct_down'] = $template['bl_pct_down']; $insert['bl_pct_up'] = $template['bl_pct_up']; $insert['bl_fail_trigger'] = $template['bl_fail_trigger']; $insert['bl_alert'] = $template['bl_alert']; $insert['repeat_alert'] = $template['repeat_alert']; $insert['notify_extra'] = $template['notify_extra']; $insert['cdef'] = $template['cdef']; $insert['thold_template_id'] = $template['id']; $insert['template_enabled'] = 'on'; $rrdlist = db_fetch_assoc("SELECT id, data_input_field_id\n\t\t\t\tFROM data_template_rrd\n\t\t\t\tWHERE local_data_id='{$local_data_id}'\n\t\t\t\tAND data_source_name='{$data_source_name}'"); $int = array('id', 'data_template_id', 'data_source_id', 'thold_fail_trigger', 'bl_ref_time_range', 'bl_pct_down', 'bl_pct_up', 'bl_fail_trigger', 'bl_alert', 'repeat_alert', 'cdef'); foreach ($rrdlist as $rrdrow) { $data_rrd_id = $rrdrow['id']; $insert['data_template_rrd_id'] = $data_rrd_id; $existing = db_fetch_assoc("SELECT id\n\t\t\t\t\tFROM thold_data\n\t\t\t\t\tWHERE local_data_id='{$local_data_id}'\n\t\t\t\t\tAND data_template_rrd_id='{$data_rrd_id}'\n\t\t\t\t\tAND thold_template_id='" . $template['id'] . "' AND template_enabled='on'"); if (count($existing) == 0) { $insert['id'] = 0; $id = sql_save($insert, 'thold_data'); if ($id) { thold_template_update_threshold($id, $insert['template']); $l = db_fetch_assoc("SELECT name FROM data_template where id={$data_template_id}"); $tname = $l[0]['name']; $name = $data_source_name; if ($rrdrow['data_input_field_id'] != 0) { $l = db_fetch_assoc('SELECT name FROM data_input_fields where id=' . $rrdrow['data_input_field_id']); $name = $l[0]['name']; } plugin_thold_log_changes($id, 'created', " {$tname} [{$name}]"); $message .= "Created threshold for the Graph '<i>{$tname}</i>' using the Data Source '<i>{$name}</i>'<br>"; } } } } } if (strlen($message)) { $_SESSION['thold_message'] = "<font size=-2>{$message}</font>"; } else { $_SESSION['thold_message'] = "<font size=-2>" . __('Threshold(s) Already Exists - No Thresholds Created') . "</font>"; } raise_message('thold_message'); if (isset($_SESSION['graph_return'])) { $return_to = $_SESSION['graph_return']; unset($_SESSION['graph_return']); kill_session_var('graph_return'); header('Location: ' . $return_to . (strpos($return_to, '?') !== false ? '&' : '?') . 'header=false'); } else { header('Location:' . $config['url_path'] . 'plugins/thold/thold.php?header=false'); } }
function do_thold() { global $host_id; $tholds = array(); while (list($var, $val) = each($_POST)) { if (preg_match("/^chk_(.*)\$/", $var, $matches)) { $del = $matches[1]; $rra = db_fetch_cell("SELECT local_data_id FROM thold_data WHERE id={$del}"); input_validate_input_number($del); $tholds[$del] = $rra; } } switch (get_nfilter_request_var('drp_action')) { case 1: // Delete foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { plugin_thold_log_changes($del, 'deleted', array('id' => $del)); db_execute("DELETE FROM thold_data WHERE id={$del}"); db_execute('DELETE FROM plugin_thold_threshold_contact WHERE thold_id=' . $del); db_execute('DELETE FROM plugin_thold_log WHERE threshold_id=' . $del); } } break; case 2: // Disabled foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { plugin_thold_log_changes($del, 'disabled_threshold', array('id' => $del)); db_execute("UPDATE thold_data SET thold_enabled='off' WHERE id={$del}"); } } break; case 3: // Enabled foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { plugin_thold_log_changes($del, 'enabled_threshold', array('id' => $del)); db_execute("UPDATE thold_data SET thold_enabled='on' WHERE id={$del}"); } } break; case 4: // Reapply Suggested Name foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { $thold = db_fetch_row("SELECT * FROM thold_data WHERE id={$del}"); /* check if thold templated */ if ($thold['template_enabled'] == "on") { $template = db_fetch_row_prepared("SELECT * FROM thold_template WHERE id = ?", array($thold["template"])); $name = thold_format_name($template, $thold["local_graph_id"], $thold["data_template_rrd_id"], $template['data_source_name']); plugin_thold_log_changes($del, 'reapply_name', array('id' => $del)); db_execute("UPDATE thold_data SET name='{$name}' WHERE id={$del}"); } } } break; case 5: // Propagate Template foreach ($tholds as $thold_id => $rra) { if (thold_user_auth_threshold($rra)) { $template = db_fetch_row("SELECT td.template id, td.template_enabled enabled\n\t\t\t\t\t\tFROM thold_data td\n\t\t\t\t\t\tINNER JOIN thold_template tt ON tt.id = td.template\n\t\t\t\t\t\tWHERE td.id = {$thold_id}"); if (isset($template['id']) && $template['id'] != 0 && $template['enabled'] != 'on') { thold_template_update_threshold($thold_id, $template['id']); plugin_thold_log_changes($thold_id, 'modified', array('id' => $thold_id, 'template_enabled' => 'on')); } } } break; } if (isset($host_id) && $host_id != '') { header('Location:thold.php?header=false&host_id=' . $host_id); } else { header('Location:thold.php?header=false'); } exit; }
function thold_add_graphs_action_execute() { global $config, $host, $graph; include_once $config['base_path'] . '/plugins/thold/thold_functions.php'; $message = ""; input_validate_input_number($_REQUEST["thold_template_id"]); $template = db_fetch_row("SELECT * FROM thold_template WHERE id=" . $_REQUEST["thold_template_id"]); $temp = db_fetch_row("SELECT dtr.*\r\n\t\t FROM data_template_rrd AS dtr\r\n\t\t LEFT JOIN graph_templates_item AS gti\r\n\t\t ON gti.task_item_id=dtr.id\r\n\t\t LEFT JOIN graph_local AS gl\r\n\t\t ON gl.id=gti.local_graph_id\r\n\t\t WHERE gl.id={$graph}"); $data_template_id = $temp['data_template_id']; $local_data_id = $temp['local_data_id']; $data_source = db_fetch_row("SELECT * FROM data_local WHERE id=" . $local_data_id); $data_template_id = $data_source['data_template_id']; /* allow duplicate thresholds, but only from differing templates */ $existing = db_fetch_assoc('SELECT id FROM thold_data WHERE rra_id=' . $local_data_id . ' AND data_id=' . $data_template_id . ' AND template=' . $template['id'] . " AND template_enabled='on'"); if (count($existing) == 0 && count($template)) { if ($graph) { $rrdlookup = db_fetch_cell("SELECT id FROM data_template_rrd WHERE local_data_id={$local_data_id} order by id LIMIT 1"); $grapharr = db_fetch_row("SELECT graph_template_id FROM graph_templates_item WHERE task_item_id={$rrdlookup} and local_graph_id = {$graph}"); $desc = db_fetch_cell('SELECT name_cache FROM data_template_data WHERE local_data_id=' . $local_data_id . ' LIMIT 1'); $data_source_name = $template['data_source_name']; $insert = array(); $name = thold_format_name($template, $graph, $local_data_id, $data_source_name); $insert['name'] = $name; $insert['host_id'] = $data_source['host_id']; $insert['rra_id'] = $local_data_id; $insert['graph_id'] = $graph; $insert['data_template'] = $data_template_id; $insert['graph_template'] = $grapharr['graph_template_id']; $insert['thold_hi'] = $template['thold_hi']; $insert['thold_low'] = $template['thold_low']; $insert['thold_fail_trigger'] = $template['thold_fail_trigger']; $insert['thold_enabled'] = $template['thold_enabled']; $insert['thold_warning_hi'] = $template['thold_warning_hi']; $insert['thold_warning_low'] = $template['thold_warning_low']; $insert['thold_warning_fail_trigger'] = $template['thold_warning_fail_trigger']; $insert['bl_ref_time_range'] = $template['bl_ref_time_range']; $insert['bl_pct_down'] = $template['bl_pct_down']; $insert['bl_pct_up'] = $template['bl_pct_up']; $insert['bl_fail_trigger'] = $template['bl_fail_trigger']; $insert['bl_alert'] = $template['bl_alert']; $insert['repeat_alert'] = $template['repeat_alert']; $insert['notify_extra'] = $template['notify_extra']; $insert['alert_phones_extra'] = $template['alert_phones_extra']; $insert['alert_command'] = $template['alert_command']; $insert['warning_command'] = $template['warning_command']; $insert['cdef'] = $template['cdef']; $insert['template'] = $template['id']; $insert['template_enabled'] = 'on'; $rrdlist = db_fetch_assoc("SELECT id, data_input_field_id \r\n\t\t\t\tFROM data_template_rrd \r\n\t\t\t\tWHERE local_data_id='{$local_data_id}' \r\n\t\t\t\tAND data_source_name='{$data_source_name}'"); $int = array('id', 'data_template_id', 'data_source_id', 'thold_fail_trigger', 'bl_ref_time_range', 'bl_pct_down', 'bl_pct_up', 'bl_fail_trigger', 'bl_alert', 'repeat_alert', 'cdef'); foreach ($rrdlist as $rrdrow) { $data_rrd_id = $rrdrow['id']; $insert['data_id'] = $data_rrd_id; $existing = db_fetch_assoc("SELECT id \r\n\t\t\t\t\tFROM thold_data \r\n\t\t\t\t\tWHERE rra_id='{$local_data_id}' \r\n\t\t\t\t\tAND data_id='{$data_rrd_id}'\r\n\t\t\t\t\tAND template='" . $template['id'] . "' AND template_enabled='on'"); if (count($existing) == 0) { $insert['id'] = 0; $id = sql_save($insert, 'thold_data'); if ($id) { thold_template_update_threshold($id, $insert['template']); $l = db_fetch_assoc("SELECT name FROM data_template where id={$data_template_id}"); $tname = $l[0]['name']; $name = $data_source_name; if ($rrdrow['data_input_field_id'] != 0) { $l = db_fetch_assoc('SELECT name FROM data_input_fields where id=' . $rrdrow['data_input_field_id']); $name = $l[0]['name']; } plugin_thold_log_changes($id, 'created', " {$tname} [{$name}]"); $message .= "Created threshold for the Graph '<i>{$tname}</i>' using the Data Source '<i>{$name}</i>'<br>"; } } } } } if (strlen($message)) { $_SESSION['thold_message'] = "<font size=-2>{$message}</font>"; } else { $_SESSION['thold_message'] = "<font size=-2>Threshold(s) Already Exists - No Thresholds Created</font>"; } raise_message('thold_created'); if (isset($_SESSION["graph_return"])) { $return_to = $_SESSION["graph_return"]; unset($_SESSION["graph_return"]); kill_session_var("graph_return"); header('Location: ' . $return_to); } else { header("Location:" . $config['url_path'] . "plugins/thold/listthold.php\n\n"); } }
function do_thold() { /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { $rows = db_fetch_assoc("\r\n SELECT thold_data.id FROM thold_data\r\n INNER JOIN user_auth_perms ON thold_data.host_id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3'"); foreach ($rows as $row) { $thold_data[] = $row["id"]; } } /* modify for multi user end */ global $hostid; $tholds = array(); while (list($var, $val) = each($_POST)) { if (ereg("^chk_(.*)\$", $var, $matches)) { $del = $matches[1]; /* modify for multi user start */ if (!in_array($del, $thold_data)) { access_denied(); } /* modify for multi user end */ $rra = db_fetch_cell("SELECT rra_id FROM thold_data WHERE id={$del}"); input_validate_input_number($del); $tholds[$del] = $rra; } } switch ($_POST['drp_action']) { case 1: // Delete foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { plugin_thold_log_changes($del, 'deleted', array('id' => $del)); db_execute("DELETE FROM thold_data WHERE id={$del}"); db_execute('DELETE FROM plugin_thold_threshold_contact WHERE thold_id=' . $del); db_execute('DELETE FROM plugin_thold_log WHERE threshold_id=' . $del); } } break; case 2: // Disabled foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { plugin_thold_log_changes($del, 'disabled_threshold', array('id' => $del)); db_execute("UPDATE thold_data SET thold_enabled='off' WHERE id={$del}"); } } break; case 3: // Enabled foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { plugin_thold_log_changes($del, 'enabled_threshold', array('id' => $del)); db_execute("UPDATE thold_data SET thold_enabled='on' WHERE id={$del}"); } } break; case 4: // Reapply Suggested Name foreach ($tholds as $del => $rra) { if (thold_user_auth_threshold($rra)) { $thold = db_fetch_row("SELECT * FROM thold_data WHERE id={$del}"); /* check if thold templated */ if ($thold['template_enabled'] == "on") { $template = db_fetch_row("SELECT * FROM thold_template WHERE id=" . $thold["template"]); $name = thold_format_name($template, $thold["graph_id"], $thold["data_id"], $template['data_source_name']); plugin_thold_log_changes($del, 'reapply_name', array('id' => $del)); db_execute("UPDATE thold_data SET name='{$name}' WHERE id={$del}"); } } } break; } if (isset($hostid) && $hostid != '') { Header('Location:listthold.php?hostid=$hostid'); } else { Header('Location:listthold.php'); } exit; }
function save_thold() { global $banner; $host_id = get_filter_request_var('host_id'); $local_data_id = get_filter_request_var('local_data_id'); $local_graph_id = get_filter_request_var('local_graph_id'); $data_template_rrd_id = get_filter_request_var('data_template_rrd_id'); $template_enabled = isset_request_var('template_enabled') && get_nfilter_request_var('template_enabled') == 'on' ? 'on' : ''; if ($template_enabled == 'on') { if (!thold_user_auth_threshold($local_data_id)) { $banner = "<span class='textError'>" . __('Permission Denied') . "</span>"; $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return; } $data = db_fetch_row_prepared('SELECT id, thold_template_id FROM thold_data WHERE local_data_id = ? AND data_template_rrd_id = ?', array($local_data_id, $data_template_rrd_id)); thold_template_update_threshold($data['id'], $data['thold_template_id']); $banner = "<span class='textInfo'>" . __('Record Updated') . "</span>"; plugin_thold_log_changes($data['id'], 'modified', array('id' => $data['id'], 'template_enabled' => 'on')); $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return get_filter_request_var('id'); } if (isset_request_var('id')) { /* Do Some error Checks */ $banner = "<span class='textError'>"; if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_hi', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_low', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_fail_trigger') != 0) { $banner .= __('You must specify either "High Alert Threshold" or "Low Alert Threshold" or both!<br>RECORD NOT UPDATED!</span>'); $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return get_filter_request_var('id'); } if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_warning_hi', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_warning_low', FILTER_VALIDATE_FLOAT) == '' && get_filter_request_var('thold_warning_fail_trigger') != 0) { $banner .= __('You must specify either "High Warning Threshold" or "Low Warning Threshold" or both!<br>RECORD NOT UPDATED!</span>'); $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return get_filter_request_var('id'); } if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_hi', FILTER_VALIDATE_FLOAT) != '' && get_filter_request_var('thold_low', FILTER_VALIDATE_FLOAT) != '' && round(get_filter_request_var('thold_low'), 4) >= round(get_filter_request_var('thold_hi'), 4)) { $banner .= __('Impossible thresholds: "High Threshold" smaller than or equal to "Low Threshold"<br>RECORD NOT UPDATED!</span>'); $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return get_filter_request_var('id'); } if (get_filter_request_var('thold_type') == 0 && get_filter_request_var('thold_warning_hi', FILTER_VALIDATE_FLOAT) != '' && get_filter_request_var('thold_warning_low', FILTER_VALIDATE_FLOAT) != '' && round(get_filter_request_var('thold_warning_low'), 4) >= round(get_filter_request_var('thold_warning_hi'), 4)) { $banner .= __('Impossible thresholds: "High Warning Threshold" smaller than or equal to "Low Warning Threshold"<br>RECORD NOT UPDATED!</span>'); $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return get_filter_request_var('id'); } if (get_filter_request_var('thold_type') == 1) { $banner .= __('With baseline thresholds enabled.'); if (!thold_mandatory_field_ok('bl_ref_time_range', 'Time reference in the past')) { $banner .= '</span>'; $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return get_filter_request_var('id'); } if (isempty_request_var('bl_pct_down') && isempty_request_var('bl_pct_up')) { $banner .= __('You must specify either "Baseline Deviation UP" or "Baseline Deviation DOWN" or both!<br>RECORD NOT UPDATED!</span>'); $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return get_filter_request_var('id'); } } } $save = array(); if (isset_request_var('id')) { $save['id'] = get_filter_request_var('id'); } else { $save['id'] = '0'; $save['thold_template_id'] = ''; } get_filter_request_var('thold_hi', FILTER_VALIDATE_FLOAT); get_filter_request_var('thold_low', FILTER_VALIDATE_FLOAT); get_filter_request_var('thold_fail_trigger'); get_filter_request_var('thold_warning_hi', FILTER_VALIDATE_FLOAT); get_filter_request_var('thold_warning_low', FILTER_VALIDATE_FLOAT); get_filter_request_var('thold_warning_fail_trigger'); get_filter_request_var('repeat_alert'); get_filter_request_var('cdef'); get_filter_request_var('local_data_id'); get_filter_request_var('data_template_rrd_id'); get_filter_request_var('thold_type'); get_filter_request_var('time_hi', FILTER_VALIDATE_FLOAT); get_filter_request_var('time_low', FILTER_VALIDATE_FLOAT); get_filter_request_var('time_fail_trigger'); get_filter_request_var('time_fail_length'); get_filter_request_var('time_warning_hi', FILTER_VALIDATE_FLOAT); get_filter_request_var('time_warning_low', FILTER_VALIDATE_FLOAT); get_filter_request_var('time_warning_fail_trigger'); get_filter_request_var('time_warning_fail_length'); get_filter_request_var('data_type'); get_filter_request_var('notify_warning'); get_filter_request_var('notify_alert'); get_filter_request_var('bl_ref_time_range'); get_filter_request_var('bl_pct_down', FILTER_VALIDATE_FLOAT); get_filter_request_var('bl_pct_up', FILTER_VALIDATE_FLOAT); get_filter_request_var('bl_fail_trigger'); if (isset_request_var('snmp_event_category')) { set_request_var('snmp_event_category', trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('snmp_event_category')))); } if (isset_request_var('snmp_event_severity')) { get_filter_request_var('snmp_event_severity'); } if (isset_request_var('snmp_event_warning_severity')) { get_filter_request_var('snmp_event_warning_severity'); } if (!isempty_request_var('name')) { $name = str_replace(array("\\", '"', "'"), '', get_nfilter_request_var('name')); } elseif (isset_request_var('data_template_rrd_id')) { $data_source_name = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array(get_request_var('data_template_rrd_id'))); $data_template = db_fetch_row_prepared('SELECT * FROM data_template_data WHERE id = ?', array(get_request_var('data_template_id'))); $local_data_id = get_request_var('local_data_id'); $local_graph_id = get_request_var('local_graph_id'); $name = thold_format_name($data_template, $local_graph_id, $local_data_id, $data_source_name); } $save['name'] = trim_round_request_var('name'); $save['host_id'] = $host_id; $save['data_template_rrd_id'] = get_request_var('data_template_rrd_id'); $save['local_data_id'] = get_request_var('local_data_id'); $save['thold_enabled'] = isset_request_var('thold_enabled') ? 'on' : 'off'; $save['exempt'] = isset_request_var('exempt') ? 'on' : ''; $save['restored_alert'] = isset_request_var('restored_alert') ? 'on' : ''; $save['thold_type'] = get_request_var('thold_type'); $save['template_enabled'] = isset_request_var('template_enabled') ? 'on' : ''; // High / Low $save['thold_hi'] = trim_round_request_var('thold_hi', 4); $save['thold_low'] = trim_round_request_var('thold_low', 4); $save['thold_fail_trigger'] = isempty_request_var('thold_fail_trigger') ? read_config_option('alert_trigger') : get_nfilter_request_var('thold_fail_trigger'); // Time Based $save['time_hi'] = trim_round_request_var('time_hi', 4); $save['time_low'] = trim_round_request_var('time_low', 4); $save['time_fail_trigger'] = isempty_request_var('time_fail_trigger') ? read_config_option('thold_warning_time_fail_trigger') : get_nfilter_request_var('time_fail_trigger'); $save['time_fail_length'] = isempty_request_var('time_fail_length') ? read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1 : get_nfilter_request_var('time_fail_length'); // Warning High / Low $save['thold_warning_hi'] = trim_round_request_var('thold_warning_hi', 4); $save['thold_warning_low'] = trim_round_request_var('thold_warning_low', 4); $save['thold_warning_fail_trigger'] = isempty_request_var('thold_warning_fail_trigger') ? read_config_option('alert_trigger') : get_nfilter_request_var('thold_warning_fail_trigger'); // Warning Time Based $save['time_warning_hi'] = trim_round_request_var('time_warning_hi', 4); $save['time_warning_low'] = trim_round_request_var('time_warning_low', 4); $save['time_warning_fail_trigger'] = isempty_request_var('time_warning_fail_trigger') ? read_config_option('thold_warning_time_fail_trigger') : get_nfilter_request_var('time_warning_fail_trigger'); $save['time_warning_fail_length'] = isempty_request_var('time_warning_fail_length') ? read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1 : get_nfilter_request_var('time_warning_fail_length'); // Baseline $save['bl_thold_valid'] = '0'; $save['bl_ref_time_range'] = isempty_request_var('bl_ref_time_range') ? read_config_option('alert_bl_timerange_def') : get_nfilter_request_var('bl_ref_time_range'); $save['bl_pct_down'] = trim_round_request_var('bl_pct_down'); $save['bl_pct_up'] = trim_round_request_var('bl_pct_up'); $save['bl_fail_trigger'] = isempty_request_var('bl_fail_trigger') ? read_config_option("alert_bl_trigger") : get_nfilter_request_var('bl_fail_trigger'); $save['repeat_alert'] = trim_round_request_var('repeat_alert'); // Notification $save['notify_extra'] = trim_round_request_var('notify_extra'); $save['notify_warning_extra'] = trim_round_request_var('notify_warning_extra'); $save['notify_warning'] = trim_round_request_var('notify_warning'); $save['notify_alert'] = trim_round_request_var('notify_alert'); // Data Manipulation $save['data_type'] = get_nfilter_request_var('data_type'); if (isset_request_var('percent_ds')) { $save['percent_ds'] = get_nfilter_request_var('percent_ds'); } else { $save['percent_ds'] = ''; } $save['cdef'] = trim_round_request_var('cdef'); if (isset_request_var('expression')) { $save['expression'] = get_nfilter_request_var('expression'); } else { $save['expression'] = ''; } // SNMP Information $save['snmp_event_category'] = trim_round_request_var('snmp_event_category'); $save['snmp_event_severity'] = isset_request_var('snmp_event_severity') ? get_nfilter_request_var('snmp_event_severity') : 4; $save['snmp_event_warning_severity'] = isset_request_var('snmp_event_warning_severity') ? get_nfilter_request_var('snmp_event_warning_severity') : 3; /* Get the Data Template, Graph Template, and Graph */ $rrdsql = db_fetch_row('SELECT id, data_template_id FROM data_template_rrd WHERE local_data_id=' . $save['local_data_id'] . ' ORDER BY id'); $rrdlookup = $rrdsql['id']; $grapharr = db_fetch_row("SELECT local_graph_id, graph_template_id \n\t\tFROM graph_templates_item \n\t\tWHERE task_item_id={$rrdlookup} \n\t\tAND local_graph_id <> '' \n\t\tLIMIT 1"); $save['local_graph_id'] = $grapharr['local_graph_id']; $save['graph_template_id'] = $grapharr['graph_template_id']; $save['data_template_id'] = $rrdsql['data_template_id']; if (!thold_user_auth_threshold($save['local_data_id'])) { $banner = "<span class='textError'>Permission Denied</span>"; $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return ''; } $id = sql_save($save, 'thold_data'); if (isset_request_var('notify_accounts') && is_array(get_nfilter_request_var('notify_accounts'))) { thold_save_threshold_contacts($id, get_nfilter_request_var('notify_accounts')); } elseif (!isset_request_var('notify_accounts')) { thold_save_threshold_contacts($id, array()); } if ($id) { plugin_thold_log_changes($id, 'modified', $save); $thold = db_fetch_row_prepared('SELECT * FROM thold_data WHERE id= ?', array($id)); if ($thold['thold_type'] == 1) { thold_check_threshold($thold); } set_request_var('id', $id); } else { set_request_var('id', '0'); } $banner = "<span class='textInfo'>" . __('Record Updated') . "</span>"; $_SESSION['thold_message'] = $banner; raise_message('thold_message'); return $id; }