示例#1
0
function plgexample_check_all_thresholds () {
	global $config;
	include_once($config['base_path'] . '/plugins/thold/thold_functions.php');
	$tholds = do_hook_function('thold_get_live_hosts', db_fetch_assoc("SELECT * FROM thold_data WHERE thold_enabled = 'on' AND tcheck = 1"));
	$total_tholds = sizeof($tholds);
	foreach ($tholds as $thold) {
		$ds = db_fetch_cell('SELECT data_source_name FROM data_template_rrd WHERE id=' . $thold['data_id']);
		thold_check_threshold ($thold['rra_id'], $thold['data_id'], $ds, $thold['lastread'], $thold['cdef']);
	}
#	db_execute('UPDATE thold_data SET tcheck = 0');

	return $total_tholds;
}
示例#2
0
                }
                break;
            case 3:
                if ($thold_data['expression'] != '') {
                    $currentval = thold_calculate_expression($thold_data, $currentval, $rrd_reindexed, $rrd_time_reindexed);
                }
                break;
        }
        if (is_numeric($currentval)) {
            $currentval = round($currentval, 4);
        } else {
            $currentval = '';
        }
        db_execute("UPDATE thold_data SET \n\t\t\ttcheck=1, lastread='{$currentval}',\n\t\t\tlasttime='" . date('Y-m-d H:i:s', $currenttime) . "',\n\t\t\toldvalue='" . $item[$thold_data['name']] . "'\n\t\t\tWHERE id = " . $thold_data['thold_id']);
    }
    /* check all thresholds */
    $sql_query = "SELECT td.*\n\t\tFROM plugin_thold_daemon_data AS tdd\n\t\tINNER JOIN thold_data AS td\n\t\tON td.id = tdd.id\n\t\tLEFT JOIN data_template_rrd AS dtr\n\t\tON dtr.id = td.data_template_rrd_id\n\t\tWHERE tdd.pid = '{$pid}' \n\t\tAND td.thold_enabled='on' \n\t\tAND td.tcheck=1";
    $tholds = do_hook_function('thold_get_live_hosts', db_fetch_assoc($sql_query));
    $total_tholds = sizeof($tholds);
    foreach ($tholds as $thold) {
        thold_check_threshold($thold);
    }
    db_execute("UPDATE thold_data SET thold_data.thold_server_pid = '', tcheck=0 WHERE thold_data.thold_server_pid = '{$pid}'");
    db_execute("DELETE FROM `plugin_thold_daemon_data` WHERE `pid` = '{$pid}'");
    db_execute("UPDATE `plugin_thold_daemon_processes` SET `end` = " . time() . ", `processed_items` = " . $total_tholds);
}
function display_help()
{
    print "tbd  ... blablabla ...";
    exit;
}
示例#3
0
function thold_check_all_thresholds()
{
    global $config;
    include $config['base_path'] . '/plugins/thold/includes/arrays.php';
    include_once $config['base_path'] . '/plugins/thold/thold_functions.php';
    $sql_query = "SELECT td.*, dtr.data_source_name\n\t\tFROM thold_data AS td\n\t\tLEFT JOIN data_template_rrd AS dtr\n\t\tON dtr.id=td.data_template_rrd_id\n\t\tWHERE td.thold_enabled='on' AND td.tcheck=1";
    $tholds = do_hook_function('thold_get_live_hosts', db_fetch_assoc($sql_query));
    $total_tholds = sizeof($tholds);
    foreach ($tholds as $thold) {
        thold_check_threshold($thold);
    }
    db_execute('UPDATE thold_data SET tcheck=0');
    return $total_tholds;
}
示例#4
0
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 &quot;High Threshold&quot; or &quot;Low Threshold&quot; 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: &quot;High Threshold&quot; smaller than or equal to &quot;Low Threshold&quot;<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 &quot;Baseline Deviation UP&quot; or &quot;Baseline Deviation DOWN&quot; 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>';
}
示例#5
0
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 &quot;High Alert Threshold&quot; or &quot;Low Alert Threshold&quot; 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 &quot;High Warning Threshold&quot; or &quot;Low Warning Threshold&quot; 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: &quot;High Threshold&quot; smaller than or equal to &quot;Low Threshold&quot;<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: &quot;High Warning Threshold&quot; smaller than or equal to &quot;Low Warning Threshold&quot;<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 &quot;Baseline Deviation UP&quot; or &quot;Baseline Deviation DOWN&quot; 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;
}