Example #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;
    }
}
Example #2
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');
    }
}
Example #3
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");
    }
}
Example #4
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;
}
Example #5
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;
}
Example #6
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;
}