Exemplo n.º 1
0
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;
    }
}
Exemplo n.º 2
0
function template_save_edit()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post('id'));
    input_validate_input_number(get_request_var_post('thold_type'));
    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('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('thold_warning_type'));
    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('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('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'));
    input_validate_input_number(get_request_var_post('repeat_alert'));
    input_validate_input_number(get_request_var_post('data_type'));
    input_validate_input_number(get_request_var_post('cdef'));
    input_validate_input_number(get_request_var_post('notify_warning'));
    input_validate_input_number(get_request_var_post('notify_alert'));
    /* ==================================================== */
    /* clean up date1 string */
    if (isset($_POST['name'])) {
        $_POST['name'] = trim(str_replace(array("\\", "'", '"'), '', get_request_var_post('name')));
    }
    /* save: data_template */
    $save['id'] = $_POST['id'];
    $save['hash'] = get_hash_thold_template($save['id']);
    $save['name'] = $_POST['name'];
    $save['thold_type'] = $_POST['thold_type'];
    // High / Low
    $save['thold_hi'] = $_POST['thold_hi'];
    $save['thold_low'] = $_POST['thold_low'];
    $save['thold_fail_trigger'] = $_POST['thold_fail_trigger'];
    // Time Based
    $save['time_hi'] = $_POST['time_hi'];
    $save['time_low'] = $_POST['time_low'];
    $save['time_fail_trigger'] = $_POST['time_fail_trigger'];
    $save['time_fail_length'] = $_POST['time_fail_length'];
    if (isset($_POST['thold_fail_trigger']) && $_POST['thold_fail_trigger'] != '') {
        $save['thold_fail_trigger'] = $_POST['thold_fail_trigger'];
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_fail_trigger'] = 5;
        }
    }
    /***  Warnings  ***/
    // High / Low Warnings
    $save['thold_warning_hi'] = $_POST['thold_warning_hi'];
    $save['thold_warning_low'] = $_POST['thold_warning_low'];
    $save['thold_warning_fail_trigger'] = $_POST['thold_warning_fail_trigger'];
    // Time Based Warnings
    $save['time_warning_hi'] = $_POST['time_warning_hi'];
    $save['time_warning_low'] = $_POST['time_warning_low'];
    $save['time_warning_fail_trigger'] = $_POST['time_warning_fail_trigger'];
    $save['time_warning_fail_length'] = $_POST['time_warning_fail_length'];
    if (isset($_POST['thold_warning_fail_trigger']) && $_POST['thold_warning_fail_trigger'] != '') {
        $save['thold_warning_fail_trigger'] = $_POST['thold_warning_fail_trigger'];
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_warning_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_warning_fail_trigger'] = 5;
        }
    }
    if (isset($_POST['thold_enabled'])) {
        $save['thold_enabled'] = 'on';
    } else {
        $save['thold_enabled'] = 'off';
    }
    if (isset($_POST['exempt'])) {
        $save['exempt'] = 'on';
    } else {
        $save['exempt'] = 'off';
    }
    if (isset($_POST['restored_alert'])) {
        $save['restored_alert'] = 'on';
    } else {
        $save['restored_alert'] = 'off';
    }
    if (isset($_POST['bl_ref_time_range']) && $_POST['bl_ref_time_range'] != '') {
        $save['bl_ref_time_range'] = $_POST['bl_ref_time_range'];
    } else {
        $alert_bl_timerange_def = read_config_option('alert_bl_timerange_def');
        if ($alert_bl_timerange_def != '' && is_numeric($alert_bl_timerange_def)) {
            $save['bl_ref_time_range'] = $alert_bl_timerange_def;
        } else {
            $save['bl_ref_time_range'] = 10800;
        }
    }
    $save['bl_pct_down'] = $_POST['bl_pct_down'];
    $save['bl_pct_up'] = $_POST['bl_pct_up'];
    if (isset($_POST['bl_fail_trigger']) && $_POST['bl_fail_trigger'] != '') {
        $save['bl_fail_trigger'] = $_POST['bl_fail_trigger'];
    } else {
        $alert_bl_trigger = read_config_option('alert_bl_trigger');
        if ($alert_bl_trigger != '' && is_numeric($alert_bl_trigger)) {
            $save['bl_fail_trigger'] = $alert_bl_trigger;
        } else {
            $save['bl_fail_trigger'] = 3;
        }
    }
    if (isset($_POST['repeat_alert']) && $_POST['repeat_alert'] != '') {
        $save['repeat_alert'] = $_POST['repeat_alert'];
    } else {
        $alert_repeat = read_config_option('alert_repeat');
        if ($alert_repeat != '' && is_numeric($alert_repeat)) {
            $save['repeat_alert'] = $alert_repeat;
        } else {
            $save['repeat_alert'] = 12;
        }
    }
    $save['notify_extra'] = $_POST['notify_extra'];
    $save['notify_warning_extra'] = $_POST['notify_warning_extra'];
    $save['notify_warning'] = $_POST['notify_warning'];
    $save['notify_alert'] = $_POST['notify_alert'];
    $save['cdef'] = $_POST['cdef'];
    $save['data_type'] = $_POST['data_type'];
    $save['percent_ds'] = $_POST['percent_ds'];
    $save['expression'] = $_POST['expression'];
    if (!is_error_message()) {
        $id = sql_save($save, 'thold_template');
        if ($id) {
            raise_message(1);
            if (isset($_POST['notify_accounts']) && is_array($_POST['notify_accounts'])) {
                thold_save_template_contacts($id, $_POST['notify_accounts']);
            } elseif (!isset($_POST['notify_accounts'])) {
                thold_save_template_contacts($id, array());
            }
            thold_template_update_thresholds($id);
            plugin_thold_log_changes($id, 'modified_template', $save);
        } else {
            raise_message(2);
        }
    }
    if (is_error_message() || empty($_POST['id'])) {
        header('Location: thold_templates.php?action=edit&id=' . (empty($id) ? $_POST['id'] : $id));
    } else {
        header('Location: thold_templates.php');
    }
}
Exemplo n.º 3
0
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');
    }
}
Exemplo n.º 4
0
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();
            $insert['name'] = $desc . ' [' . $data_source_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['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");
    }
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
function autocreate($hostid)
{
    $c = 0;
    $message = '';
    $rralist = db_fetch_assoc("SELECT id, data_template_id FROM data_local where host_id='{$hostid}'");
    if (!count($rralist)) {
        $_SESSION['thold_message'] = '<font size=-2>No thresholds were created.</font>';
        return 0;
    }
    foreach ($rralist as $row) {
        $local_data_id = $row['id'];
        $data_template_id = $row['data_template_id'];
        $existing = db_fetch_assoc('SELECT id FROM thold_data WHERE rra_id = ' . $local_data_id . ' AND data_id = ' . $data_template_id);
        $template = db_fetch_assoc('SELECT * FROM thold_template WHERE data_template_id = ' . $data_template_id);
        if (count($existing) == 0 && count($template)) {
            $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 local_graph_id, graph_template_id FROM graph_templates_item WHERE task_item_id={$rrdlookup} and local_graph_id <> '' LIMIT 1");
            $graph = isset($grapharr['local_graph_id']) ? $grapharr['local_graph_id'] : '';
            if ($graph) {
                for ($y = 0; $y < count($template); $y++) {
                    $data_source_name = $template[$y]['data_source_name'];
                    $insert = array();
                    $desc = db_fetch_cell('SELECT name_cache FROM data_template_data WHERE local_data_id=' . $local_data_id . ' LIMIT 1');
                    $insert['name'] = $desc . ' [' . $data_source_name . ']';
                    $insert['host_id'] = $hostid;
                    $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_warning_hi'] = $template[$y]['thold_warning_hi'];
                    $insert['thold_warning_low'] = $template[$y]['thold_warning_low'];
                    $insert['thold_warning_fail_trigger'] = $template[$y]['thold_warning_fail_trigger'];
                    $insert['thold_hi'] = $template[$y]['thold_hi'];
                    $insert['thold_low'] = $template[$y]['thold_low'];
                    $insert['thold_fail_trigger'] = $template[$y]['thold_fail_trigger'];
                    $insert['thold_enabled'] = $template[$y]['thold_enabled'];
                    $insert['bl_ref_time_range'] = $template[$y]['bl_ref_time_range'];
                    $insert['bl_pct_down'] = $template[$y]['bl_pct_down'];
                    $insert['bl_pct_up'] = $template[$y]['bl_pct_up'];
                    $insert['bl_fail_trigger'] = $template[$y]['bl_fail_trigger'];
                    $insert['bl_alert'] = $template[$y]['bl_alert'];
                    $insert['repeat_alert'] = $template[$y]['repeat_alert'];
                    $insert['notify_extra'] = $template[$y]['notify_extra'];
                    $insert['notify_warning_extra'] = $template[$y]['notify_warning_extra'];
                    $insert['warning_phones_extra'] = $template[$y]['warning_phones_extra'];
                    $insert['alert_phones_extra'] = $template[$y]['alert_phones_extra'];
                    $insert['alert_command'] = $template[$y]['alert_command'];
                    $insert['warning_command'] = $template[$y]['warning_command'];
                    $insert['notify_warning'] = $template[$y]['notify_warning'];
                    $insert['notify_alert'] = $template[$y]['notify_alert'];
                    $insert['cdef'] = $template[$y]['cdef'];
                    $insert['template'] = $template[$y]['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, 'auto_created', " {$tname} [{$name}]");
                                $message .= "Created threshold for the Graph '<i>{$tname}</i>' using the Data Source '<i>{$name}</i>'<br>";
                                $c++;
                            }
                        } else {
                            foreach ($existing as $r) {
                                $id = $r['id'];
                                $l = db_fetch_assoc("SELECT name FROM thold_data WHERE id={$id}");
                                $name = $l[0]['name'];
                                if ($name != $insert['name']) {
                                    db_execute("UPDATE thold_data SET name = '" . $insert['name'] . "' WHERE id={$id}");
                                    plugin_thold_log_changes($id, "updated_name: {$name} => " . $insert['name']);
                                    $message .= "Updated threshold {$id}: changed name from '<i>{$name}</i>' to '<i>" . $insert['name'] . "</i>'<br>";
                                    $c++;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $_SESSION['thold_message'] = "<font size=-2>{$message}</font>";
    return $c;
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
function autocreate($host_id)
{
    $created = 0;
    $message = '';
    $host_template_id = db_fetch_cell_prepared('SELECT host_template_id FROM host WHERE id = ?', array($host_id));
    $template_list = array_rekey(db_fetch_assoc_prepared('SELECT tt.data_template_id 
		FROM thold_template AS tt
		INNER JOIN plugin_thold_host_template AS ptht
		ON tt.id=ptht.thold_template_id
		WHERE ptht.host_template_id = ?', array($host_template_id)), 'data_template_id', 'data_template_id');
    if (!count($template_list)) {
        $_SESSION['thold_message'] = '<font size=-2>' . __('No Thresholds Templates associated with the Host\'s Template.') . '</font>';
        return 0;
    }
    $rralist = db_fetch_assoc_prepared('SELECT id, data_template_id 
		FROM data_local 
		WHERE host_id = ? 
		AND data_template_id IN (' . implode(',', $template_list) . ')', array($host_id));
    foreach ($rralist as $row) {
        $local_data_id = $row['id'];
        $data_template_id = $row['data_template_id'];
        $thold_template_ids = db_fetch_assoc_prepared('SELECT id FROM thold_template WHERE data_template_id = ?', array($data_template_id));
        if (sizeof($thold_template_ids)) {
            foreach ($thold_template_ids as $ttid) {
                $thold_template_id = $ttid['id'];
                $template = db_fetch_row_prepared('SELECT * FROM thold_template WHERE id = ?', array($thold_template_id));
                $existing = db_fetch_row_prepared('SELECT td.id 
					FROM thold_data AS td
					INNER JOIN data_template_rrd AS dtr
					ON dtr.id=td.data_template_rrd_id
					WHERE td.local_data_id = ?
					AND td.data_template_id = ?
					AND td.thold_template_id = ?
					AND td.thold_type = ?
					AND dtr.data_source_name = ?', array($local_data_id, $data_template_id, $thold_template_id, $template['thold_type'], $template['data_source_name']));
                if (!sizeof($existing)) {
                    $data_template_rrd_id = db_fetch_cell_prepared('SELECT id 
						FROM data_template_rrd 
						WHERE local_data_id = ?
						AND data_source_name = ?
						ORDER BY id LIMIT 1', array($local_data_id, $template['data_source_name']));
                    $graph = db_fetch_row_prepared('SELECT local_graph_id, graph_template_id 
						FROM graph_templates_item 
						WHERE task_item_id = ? 
						AND local_graph_id > 0 
						LIMIT 1', array($data_template_rrd_id));
                    if (sizeof($graph)) {
                        $data_source_name = $template['data_source_name'];
                        $desc = db_fetch_cell_prepared('SELECT name_cache FROM data_template_data WHERE local_data_id = ? LIMIT 1', array($local_data_id));
                        $insert = array();
                        $insert['id'] = 0;
                        $insert['name'] = $desc . ' [' . $data_source_name . ']';
                        $insert['local_data_id'] = $local_data_id;
                        $insert['data_template_rrd_id'] = $data_template_rrd_id;
                        $insert['local_graph_id'] = $graph['local_graph_id'];
                        $insert['graph_template_id'] = $graph['graph_template_id'];
                        $insert['data_template_id'] = $data_template_id;
                        $insert['thold_hi'] = $template['thold_hi'];
                        $insert['thold_low'] = $template['thold_low'];
                        $insert['thold_fail_trigger'] = $template['thold_fail_trigger'];
                        $insert['time_hi'] = $template['time_hi'];
                        $insert['time_low'] = $template['time_low'];
                        $insert['time_fail_trigger'] = $template['time_fail_trigger'];
                        $insert['time_fail_length'] = $template['time_fail_length'];
                        $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['thold_warning_fail_count'] = $template['thold_warning_fail_count'];
                        $insert['time_warning_hi'] = $template['time_warning_hi'];
                        $insert['time_warning_low'] = $template['time_warning_low'];
                        $insert['time_warning_fail_trigger'] = $template['time_warning_fail_trigger'];
                        $insert['time_warning_fail_length'] = $template['time_warning_fail_length'];
                        $insert['thold_alert'] = 0;
                        $insert['thold_enabled'] = $template['thold_enabled'];
                        $insert['thold_type'] = $template['thold_type'];
                        $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_fail_count'] = $template['bl_fail_count'];
                        $insert['bl_alert'] = $template['bl_alert'];
                        $insert['repeat_alert'] = $template['repeat_alert'];
                        $insert['notify_default'] = $template['notify_default'];
                        $insert['notify_extra'] = $template['notify_extra'];
                        $insert['notify_warning_extra'] = $template['notify_warning_extra'];
                        $insert['notify_warning'] = $template['notify_warning'];
                        $insert['notify_alert'] = $template['notify_alert'];
                        $insert['host_id'] = $host_id;
                        $insert['cdef'] = $template['cdef'];
                        $insert['percent_ds'] = $template['percent_ds'];
                        $insert['expression'] = $template['expression'];
                        $insert['thold_template_id'] = $template['id'];
                        $insert['template_enabled'] = 'on';
                        $id = sql_save($insert, 'thold_data');
                        if ($id) {
                            $graph_name = get_graph_title($graph['local_graph_id']);
                            thold_template_update_threshold($id, $insert['thold_template_id']);
                            plugin_thold_log_changes($id, 'auto_created', $insert['name']);
                            $message .= __('Created threshold for the Graph \'<i>%s</i>\' using the Data Source \'<i>%s</i>\'', $graph_name, $data_source_name) . "<br>";
                            $created++;
                        }
                    }
                }
            }
        }
    }
    $_SESSION['thold_message'] = "<font size=-2>{$message}</font>";
    return $created;
}