} /* modify for multi user end */ $rra = $_REQUEST['rra']; $hostid = db_fetch_assoc('select host_id from thold_data where rra_id=' . $rra); if (isset($hostid[0]['host_id'])) { $hostid = $hostid[0]['host_id']; } else { $hostid = db_fetch_assoc('select host_id from poller_item where local_data_id=' . $rra); if (isset($hostid[0]['host_id'])) { $hostid = $hostid[0]['host_id']; } } if (is_array($hostid)) { $hostid = ''; } if (!thold_user_auth_threshold($rra)) { include_once $config['include_path'] . '/top_header.php'; print '<font size=+1 color=red>Access Denied - You do not have permissions to access that threshold.</font>'; include_once $config['include_path'] . '/bottom_footer.php'; exit; } } else { $_REQUEST['rra'] = ''; $rra = ''; if (isset($_REQUEST['hostid'])) { /* modify for multi user start */ if (!check_host($_REQUEST['hostid'])) { access_denied(); } /* modify for multi user end */ $hostid = $_REQUEST['hostid'];
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 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 $rra, $banner, $hostid; $template_enabled = isset($_POST['template_enabled']) && $_POST['template_enabled'] == 'on' ? $_POST['template_enabled'] : 'off'; if ($template_enabled == 'on') { input_validate_input_number($_POST['rra']); input_validate_input_number($_POST['data_template_rrd_id']); $rra_id = $_POST['rra']; if (!thold_user_auth_threshold($rra_id)) { $banner = '<font color=red><strong>Permission Denied</strong></font>'; return; } $data_id = $_POST['data_template_rrd_id']; $data = db_fetch_row("SELECT id, template FROM thold_data WHERE rra_id = {$rra_id} AND data_id = {$data_id}"); thold_template_update_threshold($data['id'], $data['template']); $banner = '<font color=green><strong>Record Updated</strong></font>'; plugin_thold_log_changes($data['id'], 'modified', array('id' => $data['id'], 'template_enabled' => 'on')); return true; } /* Make sure this is defined */ $_POST['thold_enabled'] = isset($_POST['thold_enabled']) ? 'on' : 'off'; $_POST['template_enabled'] = isset($_POST['template_enabled']) ? 'on' : 'off'; /* Do Some error Checks */ $banner = '<font color=red><strong>'; if ($_POST['thold_type'] == 0 && (!isset($_POST['thold_hi']) || trim($_POST['thold_hi']) == '') && ($_POST['thold_type'] == 0 && (!isset($_POST['thold_low']) || trim($_POST['thold_low']) == ''))) { $banner .= 'You must specify either "High Threshold" or "Low Threshold" or both!<br>RECORD NOT UPDATED!</strong></font>'; return; } //if (($_POST['thold_type'] == 0) && (isset($_POST['thold_hi'])) && // (isset($_POST['thold_low'])) && (trim($_POST['thold_hi']) != '') && // (trim($_POST['thold_low']) != '') && (round($_POST['thold_low'],4) >= round($_POST['thold_hi'],4))) { // $banner .= 'Impossible thresholds: "High Threshold" smaller than or equal to "Low Threshold"<br>RECORD NOT UPDATED!</strong></font>'; // return; //} if ($_POST['thold_type'] == 1) { $banner .= 'With baseline thresholds enabled '; if (!thold_mandatory_field_ok('bl_ref_time_range', 'Time reference in the past')) { return; } if ((!isset($_POST['bl_pct_down']) || trim($_POST['bl_pct_down']) == '') && (!isset($_POST['bl_pct_up']) || trim($_POST['bl_pct_up']) == '')) { $banner .= 'You must specify either "Baseline Deviation UP" or "Baseline Deviation DOWN" or both!<br>RECORD NOT UPDATED!</strong></font>'; return; } } $existing = db_fetch_assoc('SELECT id FROM thold_data WHERE rra_id = ' . $rra . ' AND data_id = ' . $_POST['data_template_rrd_id']); $save = array(); if (count($existing)) { $save['id'] = $existing[0]['id']; } else { $save['id'] = 0; $save['template'] = ''; } input_validate_input_number(get_request_var_post('thold_hi')); input_validate_input_number(get_request_var_post('thold_low')); input_validate_input_number(get_request_var_post('thold_fail_trigger')); input_validate_input_number(get_request_var_post('thold_warning_hi')); input_validate_input_number(get_request_var_post('thold_warning_low')); input_validate_input_number(get_request_var_post('thold_warning_fail_trigger')); input_validate_input_number(get_request_var_post('repeat_alert')); input_validate_input_number(get_request_var_post('cdef')); input_validate_input_number($_POST['rra']); input_validate_input_number($_POST['data_template_rrd_id']); input_validate_input_number(get_request_var_post('thold_type')); input_validate_input_number(get_request_var_post('time_hi')); input_validate_input_number(get_request_var_post('time_low')); input_validate_input_number(get_request_var_post('time_fail_trigger')); input_validate_input_number(get_request_var_post('time_fail_length')); input_validate_input_number(get_request_var_post('time_warning_hi')); input_validate_input_number(get_request_var_post('time_warning_low')); input_validate_input_number(get_request_var_post('time_warning_fail_trigger')); input_validate_input_number(get_request_var_post('time_warning_fail_length')); input_validate_input_number(get_request_var_post('data_type')); input_validate_input_number(get_request_var_post('notify_warning')); input_validate_input_number(get_request_var_post('notify_alert')); input_validate_input_number(get_request_var_post('bl_ref_time_range')); input_validate_input_number(get_request_var_post('bl_pct_down')); input_validate_input_number(get_request_var_post('bl_pct_up')); input_validate_input_number(get_request_var_post('bl_fail_trigger')); $_POST['name'] = str_replace(array("\\", '"', "'"), '', $_POST['name']); $save['name'] = trim($_POST['name']) == '' ? '' : $_POST['name']; $save['host_id'] = $hostid; $save['data_id'] = $_POST['data_template_rrd_id']; $save['rra_id'] = $_POST['rra']; $save['thold_enabled'] = isset($_POST['thold_enabled']) ? $_POST['thold_enabled'] : ''; $save['exempt'] = isset($_POST['exempt']) ? $_POST['exempt'] : 'off'; $save['restored_alert'] = isset($_POST['restored_alert']) ? $_POST['restored_alert'] : 'off'; $save['thold_type'] = $_POST['thold_type']; // High / Low $save['thold_hi'] = trim($_POST['thold_hi']) == '' ? '' : round($_POST['thold_hi'], 4); $save['thold_low'] = trim($_POST['thold_low']) == '' ? '' : round($_POST['thold_low'], 4); $save['thold_fail_trigger'] = trim($_POST['thold_fail_trigger']) == '' ? read_config_option('alert_trigger') : $_POST['thold_fail_trigger']; // Time Based $save['time_hi'] = trim($_POST['time_hi']) == '' ? '' : round($_POST['time_hi'], 4); $save['time_low'] = trim($_POST['time_low']) == '' ? '' : round($_POST['time_low'], 4); $save['time_fail_trigger'] = trim($_POST['time_fail_trigger']) == '' ? read_config_option('thold_warning_time_fail_trigger') : $_POST['time_fail_trigger']; $save['time_fail_length'] = trim($_POST['time_fail_length']) == '' ? read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1 : $_POST['time_fail_length']; // Warning High / Low $save['thold_warning_hi'] = trim($_POST['thold_warning_hi']) == '' ? '' : round($_POST['thold_warning_hi'], 4); $save['thold_warning_low'] = trim($_POST['thold_warning_low']) == '' ? '' : round($_POST['thold_warning_low'], 4); $save['thold_warning_fail_trigger'] = trim($_POST['thold_warning_fail_trigger']) == '' ? read_config_option('alert_trigger') : $_POST['thold_warning_fail_trigger']; // Warning Time Based $save['time_warning_hi'] = trim($_POST['time_warning_hi']) == '' ? '' : round($_POST['time_warning_hi'], 4); $save['time_warning_low'] = trim($_POST['time_warning_low']) == '' ? '' : round($_POST['time_warning_low'], 4); $save['time_warning_fail_trigger'] = trim($_POST['time_warning_fail_trigger']) == '' ? read_config_option('thold_warning_time_fail_trigger') : $_POST['time_warning_fail_trigger']; $save['time_warning_fail_length'] = trim($_POST['time_warning_fail_length']) == '' ? read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1 : $_POST['time_warning_fail_length']; // Baseline $save['bl_thold_valid'] = '0'; $save['bl_ref_time_range'] = trim($_POST['bl_ref_time_range']) == '' ? read_config_option('alert_bl_timerange_def') : $_POST['bl_ref_time_range']; $save['bl_pct_down'] = trim($_POST['bl_pct_down']) == '' ? '' : $_POST['bl_pct_down']; $save['bl_pct_up'] = trim($_POST['bl_pct_up']) == '' ? '' : $_POST['bl_pct_up']; $save['bl_fail_trigger'] = trim($_POST['bl_fail_trigger']) == '' ? read_config_option("alert_bl_trigger") : $_POST['bl_fail_trigger']; $save['repeat_alert'] = trim($_POST['repeat_alert']) == '' ? '' : $_POST['repeat_alert']; $save['notify_extra'] = trim($_POST['notify_extra']) == '' ? '' : $_POST['notify_extra']; $save['notify_warning_extra'] = trim($_POST['notify_warning_extra']) == '' ? '' : $_POST['notify_warning_extra']; $save['alert_phones_extra'] = trim($_POST['alert_phones_extra']) == '' ? '' : $_POST['alert_phones_extra']; $save['warning_phones_extra'] = trim($_POST['warning_phones_extra']) == '' ? '' : $_POST['warning_phones_extra']; $save['alert_command'] = $_POST['alert_command'] == '' ? '' : $_POST['alert_command']; $save['warning_command'] = $_POST['warning_command'] == '' ? '' : $_POST['warning_command']; $save['notify_warning'] = $_POST['notify_warning']; $save['notify_alert'] = $_POST['notify_alert']; $save['cdef'] = trim($_POST['cdef']) == '' ? '' : $_POST['cdef']; $save['template_enabled'] = $_POST['template_enabled']; $save['data_type'] = $_POST['data_type']; if (isset($_POST['percent_ds'])) { $save['percent_ds'] = $_POST['percent_ds']; } else { $save['percent_ds'] = ''; } if (isset($_POST['expression'])) { $save['expression'] = $_POST['expression']; } else { $save['expression'] = ''; } /* 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['rra_id'] . ' ORDER BY id'); $rrdlookup = $rrdsql['id']; $grapharr = db_fetch_row("SELECT local_graph_id, graph_template_id FROM graph_templates_item WHERE task_item_id={$rrdlookup} and local_graph_id <> '' LIMIT 1"); $save['graph_id'] = $grapharr['local_graph_id']; $save['graph_template'] = $grapharr['graph_template_id']; $save['data_template'] = $rrdsql['data_template_id']; if (!thold_user_auth_threshold($save['rra_id'])) { $banner = '<font color=red><strong>Permission Denied</strong></font>'; return; } $id = sql_save($save, 'thold_data'); if (isset($_POST['notify_accounts']) && is_array($_POST['notify_accounts'])) { thold_save_threshold_contacts($id, $_POST['notify_accounts']); } elseif (!isset($_POST['notify_accounts'])) { thold_save_threshold_contacts($id, array()); } if ($id) { plugin_thold_log_changes($id, 'modified', $save); $thold = db_fetch_row("SELECT * FROM thold_data WHERE id={$id}"); $ds = db_fetch_cell('SELECT data_source_name FROM data_template_rrd WHERE id=' . $thold['data_id']); if ($thold["thold_type"] == 1) { thold_check_threshold($thold['rra_id'], $thold['data_id'], $ds, $thold['lastread'], $thold['cdef']); } } $banner = '<font color=green><strong>Record Updated</strong></font>'; }
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; }