function thold_graphs_action_prepare($save) { global $colors, $config; if ($save["drp_action"] == "plugin_thold_create") { /* get the valid thold templates * remove those hosts that do not have any valid templates */ $templates = ""; $found_list = ""; $not_found = ""; if (sizeof($save["graph_array"])) { foreach ($save["graph_array"] as $item) { $data_template_id = db_fetch_cell("SELECT dtr.data_template_id\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={$item}"); if ($data_template_id != "") { if (sizeof(db_fetch_assoc("SELECT id FROM thold_template WHERE data_template_id={$data_template_id}"))) { $found_list .= "<li>" . get_graph_title($item) . "</li>"; if (strlen($templates)) { $templates .= ", {$data_template_id}"; } else { $templates = "{$data_template_id}"; } } else { $not_found .= "<li>" . get_graph_title($item) . "</li>"; } } else { $not_found .= "<li>" . get_graph_title($item) . "</li>"; } } } if (strlen($templates)) { $sql = "SELECT id, name FROM thold_template WHERE data_template_id IN (" . $templates . ") ORDER BY name"; } else { $sql = "SELECT id, name FROM thold_template ORDER BY name"; } print "\t<tr>\r\n\t\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>"; if (strlen($found_list)) { if (strlen($not_found)) { print "<p>The following Graphs have no Threshold Templates associated with them</p>"; print "<ul>" . $not_found . "</ul>"; } print "<p>Are you sure you wish to create Thresholds for these Graphs?</p>\r\n\t\t\t\t\t<ul>" . $found_list . "</ul>\r\n\t\t\t\t\t</td>\r\n\t\t\t\t</tr>\n\r\n\t\t\t\t"; $form_array = array('general_header' => array('friendly_name' => 'Available Threshold Templates', 'method' => 'spacer'), 'thold_template_id' => array('method' => 'drop_sql', 'friendly_name' => 'Select a Threshold Template', 'description' => '', 'none_value' => 'None', 'value' => 'None', 'sql' => $sql)); draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } else { if (strlen($not_found)) { print "<p>There are no Threshold Templates associated with the following Graphs</p>"; print "<ul>" . $not_found . "</ul>"; } } } else { return $save; } }
function graph_edit() { global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { // graph add if ($_GET["id"] == "") { if ($_GET["host_id"] != -1) { input_validate_input_number(get_request_var("host_id")); if (!check_host($_GET["host_id"])) { access_denied(); } } // graph edit } else { $permission = check_graph($_GET["id"]); if ($permission != GRAPH_PRIVATE && $permission != GRAPH_PRIVATE + GRAPH_PUBLIC) { access_denied(); } } } /* modify for multi user end */ $use_graph_template = true; if (!empty($_GET["id"])) { $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs_template = db_fetch_row("select * from graph_templates_graph where id={$local_graph_template_graph_id}"); $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]); $header_label = "[edit: " . htmlspecialchars(get_graph_title($_GET["id"])) . "]"; if ($graphs["graph_template_id"] == "0") { $use_graph_template = false; } } else { $header_label = "[new]"; $use_graph_template = false; } /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { unset($_GET["debug"]); } /* modify for multi user end */ /* handle debug mode */ if (isset($_GET["debug"])) { if ($_GET["debug"] == "0") { kill_session_var("graph_debug_mode"); } elseif ($_GET["debug"] == "1") { $_SESSION["graph_debug_mode"] = true; } } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print htmlspecialchars(get_graph_title($_GET["id"])); ?> </td> <td class="textInfo" align="right" valign="top"> <?php /* modify for multi user start */ if ($_SESSION["permission"] == ACCESS_ADMINISTRATOR) { ?> <span style="color: #c16921;">*<a href='<?php print htmlspecialchars("graphs.php?action=graph_edit&id=" . (isset($_GET["id"]) ? $_GET["id"] : "0") . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1")); ?> '>Turn <strong><?php print isset($_SESSION["graph_debug_mode"]) ? "Off" : "On"; ?> </strong> Graph Debug Mode.</a></span><br> <?php } if (!empty($graphs["graph_template_id"]) && $_SESSION["permission"] == ACCESS_ADMINISTRATOR) { ?> <span style="color: #c16921;">*<a href='<?php print htmlspecialchars("graph_templates.php?action=template_edit&id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")); ?> '>Edit Graph Template.</a></span><br><?php } /* modify for multi user end */ if (!empty($_GET["host_id"]) || !empty($host_id)) { ?> <span style="color: #c16921;">*<a href='<?php print htmlspecialchars("host.php?action=edit&id=" . (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id)); ?> '>Edit Host.</a></span><br><?php } ?> </td> </tr> </table> <br> <?php } html_start_box("<strong>Graph Template Selection</strong> {$header_label}", "100%", $colors["header"], "3", "center", ""); $form_array = array("graph_template_id" => array("method" => "drop_sql", "friendly_name" => "Selected Graph Template", "description" => "Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied.", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0", "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name"), "host_id" => array("method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id, "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["id"] : "0"), "local_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_id"] : "0"), "local_graph_template_graph_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0"), "_graph_template_id" => array("method" => "hidden", "value" => isset($graphs) ? $graphs["graph_template_id"] : "0"), "_host_id" => array("method" => "hidden", "value" => isset($host_id) ? $host_id : "0")); /* modify for multi user start */ if ($_SESSION["permission"] < ACCESS_ADMINISTRATOR) { unset($form_array["graph_template_id"]["none_value"]); $form_array["graph_template_id"]["sql"] = "SELECT graph_templates.id,graph_templates.name FROM graph_templates WHERE name NOT LIKE '%@system' ORDER BY name"; unset($form_array["host_id"]["none_value"]); $form_array["host_id"]["sql"] = "\r\n SELECT host.id,CONCAT_WS('',host.description,' (',host.hostname,')') AS name FROM host \r\n INNER JOIN user_auth_perms ON host.id = user_auth_perms.item_id AND user_auth_perms.user_id = '" . $_SESSION["sess_user_id"] . "' AND user_auth_perms.type = '3' \r\n ORDER BY host.description,host.hostname"; } /* modify for multi user end */ draw_edit_form(array("config" => array(), "fields" => $form_array)); html_end_box(); /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs["graph_template_id"])) { html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", ""); draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0); draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true); html_end_box(); } /* graph item list goes here */ if (!empty($_GET["id"]) && empty($graphs["graph_template_id"])) { item(); } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="<?php print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . $_GET["id"] . "&rra_id=" . read_graph_config_option("default_rra_id")); ?> " alt=""> </td> <?php if (isset($_SESSION["graph_debug_mode"]) && isset($_GET["id"])) { $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; $graph_data_array["print_source"] = 1; ?> <td> <span class="textInfo">RRDTool Command:</span><br> <pre><?php print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array); ?> </pre> <span class="textInfo">RRDTool Says:</span><br> <?php unset($graph_data_array["print_source"]); ?> <pre><?php print @rrdtool_function_graph($_GET["id"], 1, $graph_data_array); ?> </pre> </td> <?php } ?> </tr> </table> <br> <?php } if ((isset($_GET["id"]) || isset($_GET["new"])) && empty($graphs["graph_template_id"])) { html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", ""); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]["value"] = isset($graphs) ? $graphs[$field_name] : ""; $form_array[$field_name]["form_id"] = isset($graphs) ? $graphs["id"] : "0"; if (!($use_graph_template == false || $graphs_template["t_" . $field_name] == "on")) { $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"]; $form_array[$field_name]["description"] = ""; } } draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); html_end_box(); } if (isset($_GET["id"]) || isset($_GET["new"])) { form_hidden_box("save_component_graph", "1", ""); form_hidden_box("save_component_input", "1", ""); } else { form_hidden_box("save_component_graph_new", "1", ""); } form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button("graphs.php"); //Now we need some javascript to make it dynamic ?> <script language="JavaScript"> dynamic(); function dynamic() { //alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'"); //alert("Log is '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } function changeScaleLog() { //alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } </script> <?php }
function thold_add_graphs_action_prepare() { global $config; $local_graph_id = get_filter_request_var('local_graph_id'); top_header(); html_start_box(__('Create Threshold from Template'), '60%', '', '3', 'center', ''); form_start('thold.php?action=add'); /* get the valid thold templates * remove those hosts that do not have any valid templates */ $templates = ''; $found_list = ''; $not_found = ''; $data_template_id = db_fetch_cell("SELECT dtr.data_template_id\n\t\t FROM data_template_rrd AS dtr\n\t\t LEFT JOIN graph_templates_item AS gti\n\t\t ON gti.task_item_id=dtr.id\n\t\t LEFT JOIN graph_local AS gl\n\t\t ON gl.id=gti.local_graph_id\n\t\t WHERE gl.id={$local_graph_id}"); if ($data_template_id != '') { if (sizeof(db_fetch_assoc("SELECT id FROM thold_template WHERE data_template_id={$data_template_id}"))) { $found_list .= '<li>' . get_graph_title($local_graph_id) . '</li>'; if (strlen($templates)) { $templates .= ", {$data_template_id}"; } else { $templates = "{$data_template_id}"; } } else { $not_found .= '<li>' . get_graph_title($local_graph_id) . '</li>'; } } else { $not_found .= '<li>' . get_graph_title($local_graph_id) . '</li>'; } if (strlen($templates)) { $sql = 'SELECT id, name FROM thold_template WHERE data_template_id IN (' . $templates . ') ORDER BY name'; } else { $sql = 'SELECT id, name FROM thold_template ORDER BY name'; } print "<tr><td colspan='2' class='textArea'>\n"; if (strlen($found_list)) { if (strlen($not_found)) { print '<p>' . __('The following Graph has no Threshold Templates associated with them.') . '</p>'; print '<ul>' . $not_found . '</ul>'; } print '<p>' . __('Are you sure you wish to create Thresholds for this Graph?') . ' <ul>' . $found_list . "</ul>\n\t\t\t</td>\n\t\t</tr>\n"; if (isset_request_var('tree_id')) { get_filter_request_var('tree_id'); } else { set_request_var('tree_id', ''); } if (isset_request_var('leaf_id')) { get_filter_request_var('leaf_id'); } else { set_request_var('leaf_id', ''); } $form_array = array('general_header' => array('friendly_name' => __('Available Threshold Templates'), 'method' => 'spacer'), 'thold_template_id' => array('method' => 'drop_sql', 'friendly_name' => __('Select a Threshold Template'), 'description' => '', 'none_value' => __('None'), 'value' => __('None'), 'sql' => $sql), 'usetemplate' => array('method' => 'hidden', 'value' => 1), 'local_graph_id' => array('method' => 'hidden', 'value' => $local_graph_id)); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); } else { if (strlen($not_found)) { print '<p>' . __('There are no Threshold Templates associated with the following Graph.') . '</p>'; print '<ul>' . $not_found . '</ul>'; } $form_array = array('general_header' => array('friendly_name' => __('Please select an action'), 'method' => 'spacer'), 'doaction' => array('method' => 'drop_array', 'friendly_name' => __('Threshold Action'), 'description' => __('You may either create a new Threshold Template, or an non-templated Threshold from this screen.'), 'value' => 'None', 'array' => array(1 => __('Create a new Threshold'), 2 => __('Create a Threshold Template'))), 'usetemplate' => array('method' => 'hidden', 'value' => 1), 'local_graph_id' => array('method' => 'hidden', 'value' => $local_graph_id)); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); } if (!strlen($not_found)) { $save_html = "<input type='submit' value='" . __('Continue') . "'>"; print "<tr>\n\t\t\t<td colspan='2' class='saveRow'>\n\t\t\t\t<input type='hidden' id='action' value='actions'>\n\t\t\t\t<input type='button' onClick='cactiReturnTo()' value='" . __('Cancel') . "' title='" . __('Cancel') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n"; } else { $save_html = "<input type='submit' value='" . __('Continue') . "'>"; print "<tr>\n\t\t\t<td colspan='2' class='saveRow'>\n\t\t\t\t<input type='button' onClick='cactiReturnTo()' value='" . __('Cancel') . "' title='" . __('Cancel') . "'>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n"; } html_end_box(); print "<script type='text/javascript'>\$(function() { applySkin() ;});</script>"; bottom_footer(); }
/* make sure the graph requested exists (sanity) */ if (!(db_fetch_cell("select local_graph_id from graph_templates_graph where local_graph_id=" . $_GET["local_graph_id"]))) { print "<strong><font size='+1' color='FF0000'>GRAPH DOES NOT EXIST</font></strong>"; exit; } /* take graph permissions into account here, if the user does not have permission give an "access denied" message */ if (read_config_option("auth_method") != 0) { $access_denied = !(is_graph_allowed($_GET["local_graph_id"])); if ($access_denied == true) { print "<strong><font size='+1' color='FF0000'>ACCESS DENIED</font></strong>"; exit; } } $graph_title = get_graph_title($_GET["local_graph_id"]); if ($_REQUEST["view_type"] == "tree") { print "<table width='100%' style='background-color: #ffffff; border: 1px solid #ffffff;' align='center' cellpadding='3'>"; }else{ print "<br><table width='100%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center' cellpadding='3'>"; } $rras = get_associated_rras($_GET["local_graph_id"]); switch ($_REQUEST["action"]) { case 'view': ?> <tr bgcolor='#<?php print $colors["header_panel"];?>'> <td colspan='3' class='textHeaderDark'> <strong>Viewing Graph</strong> '<?php print $graph_title;?>'
function update_graph_title_cache($local_graph_id) { db_execute_prepared('UPDATE graph_templates_graph SET title_cache = ? WHERE local_graph_id = ?', array(get_graph_title($local_graph_id), $local_graph_id)); }
function host_new_graphs_save() { $selected_graphs_array = unserialize(stripslashes($_POST['selected_graphs_array'])); /* form an array that contains all of the data on the previous form */ while (list($var, $val) = each($_POST)) { if (preg_match('/^g_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['graph_template'][$matches[3]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['graph_template'][$matches[3]] = $val; } } elseif (preg_match('/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */ /* ================= input validation ================= */ input_validate_input_number($matches[3]); /* ==================================================== */ /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc_prepared('SELECT graph_template_item_id FROM graph_template_input_defs WHERE graph_template_input_id = ?', array($matches[3])); /* loop through each item affected and update column data */ if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['graph_template_item'][$item['graph_template_item_id']][$matches[4]] = $val; } } } } elseif (preg_match('/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['data_template'][$matches[3]][$matches[4]] = $val; } } elseif (preg_match('/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['custom_data'][$matches[3]][$matches[4]] = $val; } } elseif (preg_match('/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/', $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values['cg'][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val; } else { /* this is a data query field */ $values['sg'][$matches[1]][$matches[2]]['data_template_item'][$matches[4]][$matches[5]] = $val; } } } debug_log_clear('new_graphs'); while (list($form_type, $form_array) = each($selected_graphs_array)) { $current_form_type = $form_type; while (list($form_id1, $form_array2) = each($form_array)) { /* enumerate information from the arrays stored in post variables */ if ($form_type == 'cg') { $graph_template_id = $form_id1; } elseif ($form_type == 'sg') { while (list($form_id2, $form_array3) = each($form_array2)) { $snmp_index_array = $form_array3; $snmp_query_array['snmp_query_id'] = $form_id1; $snmp_query_array['snmp_index_on'] = get_best_data_query_index_type($_POST['host_id'], $form_id1); $snmp_query_array['snmp_query_graph_id'] = $form_id2; } $graph_template_id = db_fetch_cell_prepared('SELECT graph_template_id FROM snmp_query_graph WHERE id = ?', array($snmp_query_array['snmp_query_graph_id'])); } if ($current_form_type == 'cg') { $return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], '', $values['cg']); debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id'])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array['local_data_id'])) { # we expect at least one data source associated foreach ($return_array['local_data_id'] as $item) { push_out_host($_POST['host_id'], $item); } } else { debug_log_insert('new_graphs', 'ERROR: no Data Source associated. Check Template'); } } elseif ($current_form_type == 'sg') { while (list($snmp_index, $true) = each($snmp_index_array)) { $snmp_query_array['snmp_index'] = decode_data_query_index($snmp_index, $snmp_query_array['snmp_query_id'], $_POST['host_id']); $return_array = create_complete_graph_from_template($graph_template_id, $_POST['host_id'], $snmp_query_array, $values['sg'][$snmp_query_array['snmp_query_id']]); debug_log_insert('new_graphs', 'Created graph: ' . get_graph_title($return_array['local_graph_id'])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array['local_data_id'])) { # we expect at least one data source associated foreach ($return_array['local_data_id'] as $item) { push_out_host($_POST['host_id'], $item); } } else { debug_log_insert('new_graphs', 'ERROR: no Data Source associated. Check Template'); } } } } } }
if ($_REQUEST['rra_id'] == 'all') { $sql_where = ' WHERE id IS NOT NULL'; } else { $sql_where = ' WHERE id=' . $_REQUEST['rra_id']; } /* make sure the graph requested exists (sanity) */ if (!db_fetch_cell_prepared('SELECT local_graph_id FROM graph_templates_graph WHERE local_graph_id = ?', array(get_request_var_request('local_graph_id')))) { print "<strong><font class='txtErrorTextBox'>GRAPH DOES NOT EXIST</font></strong>"; exit; } /* take graph permissions into account here */ if (!is_graph_allowed($_REQUEST['local_graph_id'])) { header('Location: permission_denied.php'); exit; } $graph_title = get_graph_title($_REQUEST['local_graph_id']); if ($_REQUEST['view_type'] == 'tree') { print "<table width='100%' style='background-color: #ffffff; border: 1px solid #ffffff;' align='center' cellspacing='0' cellpadding='3'>"; } else { print "<table width='100%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center' cellspacing='0' cellpadding='3'>"; } $rras = get_associated_rras($_REQUEST['local_graph_id']); switch ($_REQUEST['action']) { case 'view': api_plugin_hook_function('page_buttons', array('lgid' => $_REQUEST['local_graph_id'], 'leafid' => '', 'mode' => 'mrtg', 'rraid' => $_REQUEST['rra_id'])); ?> <tr class='tableHeader'> <td colspan='3' class='textHeaderDark'> <strong>Viewing Graph</strong> '<?php print htmlspecialchars($graph_title); ?>
function graph_edit() { global $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item; /* ================= input validation ================= */ input_validate_input_number(get_request_var_request('id')); /* ==================================================== */ $locked = 'false'; $use_graph_template = true; if (!empty($_REQUEST['id'])) { $_SESSION['sess_graph_lock_id'] = $_REQUEST['id']; $local_graph_template_graph_id = db_fetch_cell_prepared('SELECT local_graph_template_graph_id FROM graph_templates_graph WHERE local_graph_id = ?', array($_REQUEST['id'])); if ($_REQUEST['id'] != $_SESSION['sess_graph_lock_id'] && !empty($local_graph_template_graph_id)) { $locked = 'true'; $_SESSION['sess_graph_locked'] = $locked; } elseif (empty($local_graph_template_graph_id)) { $locked = 'false'; $_SESSION['sess_graph_locked'] = $locked; } elseif (isset($_SESSION['sess_graph_locked'])) { $locked = $_SESSION['sess_graph_locked']; } else { $locked = 'true'; $_SESSION['sess_graph_locked'] = $locked; } $graphs = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE local_graph_id = ?', array($_REQUEST['id'])); $graphs_template = db_fetch_row_prepared('SELECT * FROM graph_templates_graph WHERE id = ?', array($local_graph_template_graph_id)); $host_id = db_fetch_cell_prepared('SELECT host_id FROM graph_local WHERE id = ?', array($_REQUEST['id'])); $header_label = '[edit: ' . htmlspecialchars(get_graph_title($_REQUEST['id'])) . ']'; if ($graphs['graph_template_id'] == '0') { $use_graph_template = 'false'; } } else { $header_label = '[new]'; $use_graph_template = false; } /* handle debug mode */ if (isset($_REQUEST['debug'])) { if ($_REQUEST['debug'] == '0') { kill_session_var('graph_debug_mode'); } elseif ($_REQUEST['debug'] == '1') { $_SESSION['graph_debug_mode'] = true; } } if (!empty($_REQUEST['id'])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print htmlspecialchars(get_graph_title($_REQUEST['id'])); ?> </td> <td class="textInfo" align="right" valign="top"> <span class="linkMarker">*<a class='hyperLink' href='<?php print htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_REQUEST['id']) ? $_REQUEST['id'] : '0') . '&debug=' . (isset($_SESSION['graph_debug_mode']) ? '0' : '1')); ?> '>Turn <strong><?php print isset($_SESSION['graph_debug_mode']) ? 'Off' : 'On'; ?> </strong> Graph Debug Mode.</a></span><br> <?php if (!empty($graphs['graph_template_id'])) { ?> <span class="linkMarker">*<a class='hyperLink' href='<?php print htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs['graph_template_id']) ? $graphs['graph_template_id'] : '0')); ?> '>Edit Graph Template.</a></span><br><?php } if (!empty($_REQUEST['host_id']) || !empty($host_id)) { ?> <span class="linkMarker">*<a class='hyperLink' href='<?php print htmlspecialchars('host.php?action=edit&id=' . (isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $host_id)); ?> '>Edit Device.</a></span><br><?php } if ($locked == 'true') { ?> <span class="linkMarker">* <span class='hyperLink' id='unlockid'>Unlock Graph</span></span><?php } else { ?> <span class="linkMarker">* <span class='hyperLink' id='lockid'>Lock Graph</span></span><?php } ?> </td> </tr> </table> <?php } html_start_box("<strong>Graph Template Selection</strong> {$header_label}", '100%', '', '3', 'center', ''); $form_array = array('graph_template_id' => array('method' => 'drop_sql', 'friendly_name' => 'Selected Graph Template', 'description' => 'Choose a Graph Template to apply to this Graph. Please note that Graph Data may be lost if you change the Graph Template after one is already applied.', 'value' => isset($graphs) ? $graphs['graph_template_id'] : '0', 'none_value' => 'None', 'sql' => 'SELECT graph_templates.id,graph_templates.name FROM graph_templates ORDER BY name'), 'host_id' => array('method' => 'drop_callback', 'friendly_name' => 'Device', 'description' => 'Choose the Device that this Graph belongs to.', 'sql' => "SELECT id,CONCAT_WS('',description,' (',hostname,')') as name FROM host ORDER BY description,hostname", 'action' => 'ajax_hosts_noany', 'id' => isset($_REQUEST['host_id']) ? $_REQUEST['host_id'] : $host_id, 'value' => db_fetch_cell_prepared('SELECT description AS name FROM host WHERE id = ?', isset($_REQUEST['host_id']) ? array($_REQUEST['host_id']) : array($host_id))), 'graph_template_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['id'] : '0'), 'local_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['local_graph_id'] : '0'), 'local_graph_template_graph_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['local_graph_template_graph_id'] : '0'), '_graph_template_id' => array('method' => 'hidden', 'value' => isset($graphs) ? $graphs['graph_template_id'] : '0'), '_host_id' => array('method' => 'hidden', 'value' => isset($host_id) ? $host_id : '0')); draw_edit_form(array('config' => array(), 'fields' => $form_array)); html_end_box(); /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs['graph_template_id'])) { html_start_box('<strong>Supplemental Graph Template Data</strong>', '100%', '', '3', 'center', ''); draw_nontemplated_fields_graph($graphs['graph_template_id'], $graphs, '|field|', '<strong>Graph Fields</strong>', true, true, 0); draw_nontemplated_fields_graph_item($graphs['graph_template_id'], $_REQUEST['id'], '|field|_|id|', '<strong>Graph Item Fields</strong>', true, $locked); html_end_box(); } /* graph item list goes here */ if (!empty($_REQUEST['id']) && empty($graphs['graph_template_id'])) { item(); } if (!empty($_REQUEST['id'])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="<?php print htmlspecialchars('graph_image.php?action=edit&local_graph_id=' . $_REQUEST['id'] . '&rra_id=' . read_graph_config_option('default_rra_id')); ?> " alt=""> </td> <?php if (isset($_SESSION['graph_debug_mode']) && isset($_REQUEST['id'])) { $graph_data_array['output_flag'] = RRDTOOL_OUTPUT_STDERR; $graph_data_array['print_source'] = 1; ?> <td> <span class="textInfo">RRDTool Command:</span><br> <pre><?php print @rrdtool_function_graph($_REQUEST['id'], 1, $graph_data_array); ?> </pre> <span class="textInfo">RRDTool Says:</span><br> <?php unset($graph_data_array['print_source']); ?> <pre><?php print @rrdtool_function_graph($_REQUEST['id'], 1, $graph_data_array); ?> </pre> </td> <?php } ?> </tr> </table> <br> <?php } if ((isset($_REQUEST['id']) || isset($_REQUEST['new'])) && empty($graphs['graph_template_id'])) { html_start_box('<strong>Graph Configuration</strong>', '100%', '', '3', 'center', ''); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]['value'] = isset($graphs) ? $graphs[$field_name] : ''; $form_array[$field_name]['form_id'] = isset($graphs) ? $graphs['id'] : '0'; if (!($use_graph_template == false || $graphs_template['t_' . $field_name] == 'on')) { $form_array[$field_name]['method'] = 'template_' . $form_array[$field_name]['method']; $form_array[$field_name]['description'] = ''; } } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); html_end_box(); } if (isset($_REQUEST['id']) || isset($_REQUEST['new'])) { form_hidden_box('save_component_graph', '1', ''); form_hidden_box('save_component_input', '1', ''); } else { form_hidden_box('save_component_graph_new', '1', ''); } form_hidden_box('rrdtool_version', read_config_option('rrdtool_version'), ''); form_save_button('graphs.php'); //Now we need some javascript to make it dynamic ?> <script type='text/javascript'> dynamic(); function dynamic() { if ($('#scale_log_units').is(':checked')) { $('#scale_log_units').prop('disabled', true); if ($('#auto_scale_log').is(':checked')) { $('#scale_log_units').prop('disabled', false); } } } function changeScaleLog() { if ($('#scale_log_units').is(':checked')) { $('#scale_log_units').prop('disabled', true); if ($('#auto_scale_log').is(':checked')) { $('#scale_log_units').prop('disabled', false); } } } $(function() { $('#unlockid').click(function(event) { event.preventDefault; $('body').append("<div id='modal' class='ui-widget-overlay ui-front' style='z-index: 100;'><i style='position:absolute;top:50%;left:50%;' class='fa fa-spin fa-circle-o-notch'/></div>"); $.get('graphs.php?action=unlock&header=false&id='+$('#local_graph_id').val(), function(data) { $('#modal').remove(); $('#main').html(data); applySkin(); }); }); $('#lockid').click(function(event) { event.preventDefault; $.get('graphs.php?action=lock&header=false&id='+$('#local_graph_id').val(), function(data) { $('#main').html(data); applySkin(); }); }); }); if (<?php print $locked == '' ? 'true' : $locked; ?> == true) { $('input, select').not('input[value="Cancel"]').prop('disabled', true); } </script> <?php }
function draw_dhtml_tree_level($tree_id, $parent = 0, $graphing = false) { global $config; /* Record Start Time */ list($micro, $seconds) = explode(' ', microtime()); $start = $seconds + $micro; $dhtml_tree = array(); $heirarchy = get_allowed_tree_level($tree_id, $parent); if (sizeof($heirarchy) > 0) { $dhtml_tree[] = "\t\t\t<ul>\n"; foreach ($heirarchy as $leaf) { if ($leaf['host_id'] > 0) { //It's a host $dhtml_tree[] = "\t\t\t\t<li id='tbranch:" . $leaf['id'] . "_thost:" . $leaf['host_id'] . "' data-jstree='{ \"type\" : \"device\" }'>Device: " . htmlspecialchars($leaf['hostname']) . "\n"; $dhtml_tree[] = "\t\t\t\t</li>\n"; } elseif ($leaf['local_graph_id'] > 0) { $dhtml_tree[] = "\t\t\t\t<li id='tbranch:" . $leaf['id'] . "_tgraph:" . $leaf['local_graph_id'] . "' data-jstree='{ \"type\" : \"graph\" }'>Graph: " . htmlspecialchars(get_graph_title($leaf['local_graph_id'])) . "</a>\n"; $dhtml_tree[] = "\t\t\t\t</li>\n"; } else { //It's not a host $dhtml_tree[] = "\t\t\t\t<li class='jstree-closed' id='tbranch:" . $leaf['id'] . "'>" . htmlspecialchars($leaf['title']) . "\n"; $dhtml_tree[] = "\t\t\t\t</li>\n"; } } $dhtml_tree[] = "\t\t\t</ul>\n"; } return $dhtml_tree; }
function graph_edit() { global $colors; require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php"); /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $use_graph_template = true; if (!empty($_GET["id"])) { $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . get_request_var("id")); $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . get_request_var("id")); $graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id"); $device_id = db_fetch_cell("select device_id from graph_local where id=" . get_request_var("id")); $header_label = __("[edit: ") . get_graph_title(get_request_var("id")) . "]"; if ($graphs["graph_template_id"] == "0") { $use_graph_template = false; } }else{ $graphs = array(); $graphs_template = array(); $header_label = __("[new]"); $use_graph_template = false; } /* handle debug mode */ if (isset($_GET["debug"])) { if (get_request_var("debug") == "0") { kill_session_var("graph_debug_mode"); }elseif (get_request_var("debug") == "1") { $_SESSION["graph_debug_mode"] = true; } } $tip_text = "<tr><td align=\\'right\\'><a class=\\'popup_item\\' id=\\'changeGraphState\\' onClick=\\'changeGraphState()\\' href=\\'#\\'>Unlock/Lock</a></td></tr>"; $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graphs.php?action=graph_edit&id=' . (isset($_GET["id"]) ? get_request_var("id") : 0) . "&debug=" . (isset($_SESSION["graph_debug_mode"]) ? "0" : "1")) . "\\'>" . __("Turn") . " <strong>" . (isset($_SESSION["graph_debug_mode"]) ? __("Off") : __(CHECKED)) . "</strong> " . __("Debug Mode") . "</a></td></tr>"; if (!empty($graphs["graph_template_id"])) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('graph_templates.php?action=template_edit&id=' . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) . "\\'>" . __("Edit Template") . "</a></td></tr>"; } if (!empty($_GET["device_id"]) || !empty($device_id)) { $tip_text .= "<tr><td align=\\'right\\'><a class=\\'popup_item\\' href=\\'" . htmlspecialchars('devices.php?action=edit&id=' . (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id)) . "\\'>" . __("Edit Host") . "</a></td></tr>"; } if (!empty($_GET["id"])) { ?> <script type="text/javascript"> <!-- var disabled = true; $().ready(function() { $("input").attr("disabled","disabled"); $("select").attr("disabled","disabled"); $("#cancel").removeAttr("disabled"); }); function changeGraphState() { if (disabled) { $("input").removeAttr("disabled"); $("select").removeAttr("disabled"); disabled = false; rrdtool_graph_dependencies(); // even when unlocking, disable distinct rrdtool options }else{ $("input").attr("disabled","disabled"); $("select").attr("disabled","disabled"); $("#cancel").removeAttr("disabled"); disabled = true; } } //--> </script> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print get_graph_title(get_request_var("id"));?> </td> <td style="white-space:nowrap;" align="right" width="1"><a id='tooltip' class='popup_anchor' href='#' onMouseOver="Tip('<?php print $tip_text;?>', BGCOLOR, '#EEEEEE', FIX, ['tooltip', -45, 0], STICKY, true, SHADOW, true, CLICKCLOSE, true, FADEOUT, 400, TEXTALIGN, 'right', BORDERCOLOR, '#F5F5F5')" onMouseOut="UnTip()">Graph Options</a></td> </tr> </table> <?php } print "<form method='post' action='" . basename($_SERVER["PHP_SELF"]) . "' name='graph_edit'>\n"; html_start_box("<strong>" . __("Graph Template Selection") . "</strong> $header_label", "100", $colors["header"], 0, "center", ""); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 1, true, 'template'); $form_array = array( "graph_template_id" => array( "method" => "autocomplete", "callback_function" => "./lib/ajax/get_graph_templates.php", "friendly_name" => __("Selected Graph Template"), "description" => __("Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied."), "id" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0"), "name" => db_fetch_cell("SELECT name FROM graph_templates WHERE id=" . (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0")) ), "device_id" => array( "method" => "autocomplete", "callback_function" => "./lib/ajax/get_device_detailed.php", "friendly_name" => __("Host"), "description" => __("Choose the device that this graph belongs to."), "id" => (isset($_GET["device_id"]) ? get_request_var("device_id") : $device_id), "name" => db_fetch_cell("SELECT CONCAT_WS('',description,' (',hostname,')') FROM device WHERE id=" . (isset($_GET['device_id']) ? $_GET['device_id'] : $device_id)) ), "graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["id"]) ? $graphs["id"] : "0") ), "local_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["local_graph_id"]) ? $graphs["local_graph_id"] : "0") ), "local_graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs["local_graph_template_graph_id"]) ? $graphs["local_graph_template_graph_id"] : "0") ), "_graph_template_id" => array( "method" => "hidden", "value" => (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0") ), "_device_id" => array( "method" => "hidden", "value" => (isset($device_id) ? $device_id : "0") ) ); draw_edit_form( array( "config" => array(), "fields" => $form_array ) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); # print "<form method='post' action='graphs.php'>\n"; /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs["graph_template_id"])) { html_start_box("<strong>" . __("Supplemental Graph Template Data") . "</strong>", "100", $colors["header"], "0", "center", ""); draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>" . __("Graph Fields") . "</strong>", true, true, 0); draw_nontemplated_fields_graph_item($graphs["graph_template_id"], get_request_var("id"), "|field|_|id|", "<strong>" . __("Graph Item Fields") ."</strong>", true); html_end_box(); } /* graph item list goes here */ if ((!empty($_GET["id"])) && (!array_key_exists("graph_template_id", $graphs))) { graph_template_item(); } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="<?php print htmlspecialchars("graph_image.php?action=edit&local_graph_id=" . get_request_var("id") . "&rra_id=" . read_graph_config_option("default_rra_id"));?>" alt=""> </td> <?php if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) { $graph_data_array = array(); $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; /* make rrdtool_function_graph to only print the command without executing it */ $graph_data_array["print_source"] = 1; ?> <td> <span class="textInfo"><?php print __("RRDTool Command:");?></span><br> <pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre> <span class="textInfo"><?php print __("RRDTool Says:");?></span><br> <?php /* make rrdtool_function_graph to generate AND execute the rrd command, but only for fetching the "return code" */ unset($graph_data_array["print_source"]);?> <pre><?php print rrdtool_function_graph(get_request_var("id"), read_graph_config_option("default_rra_id"), $graph_data_array);?></pre> </td> <?php } ?> </tr> </table> <?php } if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) { html_start_box("<strong>" . __("Graph Configuration") . "</strong>", "100", $colors["header"], "0", "center", ""); ############ html_start_box("<strong>" . __("Labels") . "</strong>", "100", $colors["header"], "0", "center", "", true); draw_template_edit_form('header_graph_labels', graph_labels_form_list(), $graphs, $use_graph_template); html_end_box(false); /* TODO: we should not use rrd version in the code, when going data-driven */ if ( read_config_option("rrdtool_version") != RRD_VERSION_1_0 && read_config_option("rrdtool_version") != RRD_VERSION_1_2) { html_start_box("<strong>" . __("Right Axis Settings") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_right_axis"); draw_template_edit_form('header_graph_right_axis', graph_right_axis_form_list(), $graphs, $use_graph_template); } html_end_box(false); html_start_box("<strong>" . __("Graph Template Size") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_size"); draw_template_edit_form('header_graph_size', graph_size_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Limits") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_limits"); draw_template_edit_form('header_graph_limits', graph_limits_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Grid") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_grid"); draw_template_edit_form('header_graph_grid', graph_grid_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Color") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_color"); draw_template_edit_form('header_graph_color', graph_color_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Legend") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc"); draw_template_edit_form('header_graph_legend', graph_legend_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Misc") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_misc"); draw_template_edit_form('header_graph_misc', graph_misc_form_list(), $graphs, $use_graph_template); html_end_box(false); html_start_box("<strong>" . __("Graph Template Cacti Specifics") . "</strong>", "100", $colors["header"], "0", "center", "", true, "table_graph_template_cacti"); draw_template_edit_form('header_graph_cacti', graph_cacti_form_list(), $graphs, $use_graph_template); html_end_box(false); } if ((isset($_GET["id"])) || (isset($_GET["new"]))) { form_hidden_box("save_component_graph","1",""); form_hidden_box("save_component_input","1",""); }else{ form_hidden_box("save_component_graph_new","1",""); } form_hidden_box("hidden_rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button_alt(); include_once(CACTI_BASE_PATH . "/access/js/colorpicker.js"); include_once(CACTI_BASE_PATH . "/access/js/graph_template_options.js"); ?> <script type="text/javascript"> $('#graph_item').tableDnD({ onDrop: function(table, row) { $('#AjaxResult').load("lib/ajax/jquery.tablednd/graphs_item.ajax.php?id=<?php isset($_GET["id"]) ? print get_request_var("id") : print "";?>&"+$.tableDnD.serialize()); // location.reload(); } }); </script> <?php }
/** * reports_graphs_action_execute - perform reports_graph execute action * @param string $action - action to be performed * return - * */ function reports_graphs_action_execute($action) { global $config; if ($action == "reports") { /* report */ $message = ''; /* loop through each of the graph_items selected on the previous page for skipped items */ if (isset($_POST["selected_items"])) { $selected_items = unserialize(stripslashes($_POST["selected_items"])); $reports_id = $_POST["reports_id"]; input_validate_input_number($reports_id); input_validate_input_number($_POST["timespan"]); input_validate_input_number($_POST["alignment"]); $report = db_fetch_row("SELECT * FROM reports WHERE id=" . $reports_id); if (sizeof($selected_items)) { foreach ($selected_items as $local_graph_id) { /* ================= input validation ================= */ input_validate_input_number($local_graph_id); /* ==================================================== */ /* see if the graph is already added */ $existing = db_fetch_cell("SELECT id\n\t\t\t\t\tFROM reports_items\n\t\t\t\t\tWHERE local_graph_id=" . $local_graph_id . "\n\t\t\t\t\tAND report_id=" . $reports_id . "\n\t\t\t\t\tAND timespan=" . $_POST["timespan"]); if (!$existing) { $sequence = db_fetch_cell("SELECT max(sequence)\n\t\t\t\t\t\tFROM reports_items\n\t\t\t\t\t\tWHERE report_id=" . $reports_id); $sequence++; $graph_data = db_fetch_row("SELECT *\n\t\t\t\t\t\tFROM graph_local\n\t\t\t\t\t\tWHERE id=" . $local_graph_id); if ($graph_data["host_id"]) { $host_template = db_fetch_cell("SELECT host_template_id\n\t\t\t\t\t\t\tFROM host\n\t\t\t\t\t\t\tWHERE id=" . $graph_data["host_id"]); } else { $host_template = 0; } $save["id"] = 0; $save["report_id"] = $reports_id; $save["item_type"] = REPORTS_ITEM_GRAPH; $save["tree_id"] = 0; $save["branch_id"] = 0; $save["tree_cascade"] = ''; $save["graph_name_regexp"] = ''; $save["host_template_id"] = $host_template; $save["host_id"] = $graph_data["host_id"]; $save["graph_template_id"] = $graph_data["graph_template_id"]; $save["local_graph_id"] = $local_graph_id; $save["timespan"] = $_POST["timespan"]; $save["align"] = $_POST["alignment"]; $save["item_text"] = ''; $save["font_size"] = $report["font_size"]; $save["sequence"] = $sequence; $id = sql_save($save, 'reports_items'); if ($id) { $message .= "Created Report Graph Item '<i>" . get_graph_title($local_graph_id) . "</i>'<br>"; } else { $message .= "Failed Adding Report Graph Item '<i>" . get_graph_title($local_graph_id) . "</i>' Already Exists<br>"; } } else { $message .= "Skipped Report Graph Item '<i>" . get_graph_title($local_graph_id) . "</i>' Already Exists<br>"; } } } } if (strlen($message)) { $_SESSION['reports_message'] = "{$message}"; } raise_message('reports_message'); } else { return $action; } }
function display_reports_items($report_id) { global $graph_timespans; global $item_types, $alignment; $items = db_fetch_assoc('SELECT * FROM reports_items WHERE report_id=' . $report_id . ' ORDER BY sequence'); $css = db_fetch_cell('SELECT cformat FROM reports WHERE id=' . $report_id); html_header(array('Item', 'Sequence', 'Type', 'Item Details', 'Timespan', 'Alignment', 'Font Size', 'Actions'), 2); $i = 0; if (sizeof($items) > 0) { foreach ($items as $item) { switch ($item['item_type']) { case REPORTS_ITEM_GRAPH: $item_details = get_graph_title($item['local_graph_id']); $align = $item['align'] > 0 ? $alignment[$item['align']] : ''; $size = ''; $timespan = $item['timespan'] > 0 ? $graph_timespans[$item['timespan']] : ''; break; case REPORTS_ITEM_TEXT: $item_details = $item['item_text']; $align = $item['align'] > 0 ? $alignment[$item['align']] : ''; $size = $item['font_size'] > 0 ? $item['font_size'] : ''; $timespan = ''; break; case REPORTS_ITEM_TREE: if ($item['branch_id'] > 0) { $branch_details = db_fetch_row('SELECT * FROM graph_tree_items WHERE id=' . $item['branch_id']); } else { $branch_details = array(); } $tree_name = db_fetch_cell('SELECT name FROM graph_tree WHERE id=' . $item['tree_id']); $item_details = 'Tree: ' . $tree_name; if ($item['branch_id'] > 0) { if ($branch_details['host_id'] > 0) { $item_details .= ', Host: ' . db_fetch_cell('SELECT description FROM host WHERE id=' . $branch_details['host_id']); } else { $item_details .= ', Branch: ' . $branch_details['title']; if ($item['tree_cascade'] == 'on') { $item_details .= ' (All Branches)'; } else { $item_details .= ' (Current Branch)'; } } } $align = $item['align'] > 0 ? $alignment[$item['align']] : ''; $size = $item['font_size'] > 0 ? $item['font_size'] : ''; $timespan = $item['timespan'] > 0 ? $graph_timespans[$item['timespan']] : ''; break; default: $item_details = ''; $align = ''; $size = ''; $timespan = ''; } if ($css == 'on') { $size = ''; } form_alternate_row(); $form_data = '<td><a class="linkEditMain" href="' . htmlspecialchars(get_reports_page() . '?action=item_edit&id=' . $report_id . '&item_id=' . $item['id']) . '">Item#' . $i . '</a></td>'; $i++; $form_data .= '<td>' . $item['sequence'] . '</td>'; $form_data .= '<td>' . $item_types[$item['item_type']] . '</td>'; $form_data .= '<td style="white-space:nowrap;">' . $item_details . '</td>'; $form_data .= '<td style="white-space:nowrap;">' . $timespan . '</td>'; $form_data .= '<td>' . $align . '</td>'; $form_data .= '<td>' . $size . '</td>'; $form_data .= '<td align="right" style="text-align:right;min-width:5%;white-space:nowrap;"><a href="' . htmlspecialchars(get_reports_page() . '?action=item_movedown&item_id=' . $item['id'] . '&id=' . $report_id) . '"><img src="images/move_down.gif" border="0" alt="Move Down"></a>' . '<a href="' . htmlspecialchars(get_reports_page() . '?action=item_moveup&item_id=' . $item['id'] . '&id=' . $report_id) . '"><img src="images/move_up.gif" border="0" alt="Move Up"></a>' . '</td>'; $form_data .= '<td align="right"><a href="' . htmlspecialchars(get_reports_page() . '?action=item_remove&item_id=' . $item['id'] . '&id=' . $report_id) . '"><img src="images/delete_icon.gif" border="0" width="10" height="10" alt="Delete"></a>' . '</td></tr>'; print $form_data; } } else { print "<tr><td><em>No Report Items</em></td></tr>\n"; } }
function thold_graphs_action_prepare($save) { global $config; if ($save['drp_action'] == 'plugin_thold_create') { /* get the valid thold templates * remove those hosts that do not have any valid templates */ $templates = ''; $found_list = ''; $not_found = ''; if (sizeof($save['graph_array'])) { foreach ($save['graph_array'] as $item) { $data_template_id = db_fetch_cell("SELECT dtr.data_template_id\n\t\t\t\t\t FROM data_template_rrd AS dtr\n\t\t\t\t\t LEFT JOIN graph_templates_item AS gti\n\t\t\t\t\t ON gti.task_item_id=dtr.id\n\t\t\t\t\t LEFT JOIN graph_local AS gl\n\t\t\t\t\t ON gl.id=gti.local_graph_id\n\t\t\t\t\t WHERE gl.id={$item}"); if ($data_template_id != '') { if (sizeof(db_fetch_assoc("SELECT id FROM thold_template WHERE data_template_id={$data_template_id}"))) { $found_list .= '<li>' . get_graph_title($item) . '</li>'; if (strlen($templates)) { $templates .= ", {$data_template_id}"; } else { $templates = "{$data_template_id}"; } } else { $not_found .= '<li>' . get_graph_title($item) . '</li>'; } } else { $not_found .= '<li>' . get_graph_title($item) . '</li>'; } } } if (strlen($templates)) { $sql = 'SELECT id, name FROM thold_template WHERE data_template_id IN (' . $templates . ') ORDER BY name'; } else { $sql = 'SELECT id, name FROM thold_template ORDER BY name'; } print "<tr><td colspan='2' class='textArea'>\n"; if (strlen($found_list)) { if (strlen($not_found)) { print '<p>' . __('The following Graphs have no Threshold Templates associated with them') . '</p>'; print '<ul>' . $not_found . '</ul>'; } print '<p>Are you sure you wish to create Thresholds for these Graphs?</p> <ul>' . $found_list . "</ul>\n\t\t\t\t</td>\n\t\t\t</tr>\n"; $form_array = array('general_header' => array('friendly_name' => __('Available Threshold Templates'), 'method' => 'spacer'), 'thold_template_id' => array('method' => 'drop_sql', 'friendly_name' => __('Select a Threshold Template'), 'description' => '', 'none_value' => __('None'), 'value' => __('None'), 'sql' => $sql)); draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array)); } else { if (strlen($not_found)) { print '<p>' . __('There are no Threshold Templates associated with the following Graphs') . '</p>'; print '<ul>' . $not_found . '</ul>'; } } } else { return $save; } }
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; }
function update_graph_title_cache($local_graph_id) { db_execute("update graph_templates_graph set title_cache='" . addslashes(get_graph_title($local_graph_id)) . "' where local_graph_id=$local_graph_id"); }
function thold_add_graphs_action_prepare($graph) { global $colors, $config; include $config['include_path'] . '/top_header.php'; html_start_box("<strong>Create Threshold from Template</strong>", "60%", $colors["header_panel"], "3", "center", ""); print "<form action='thold_add.php' method='POST'>\n"; /* get the valid thold templates * remove those hosts that do not have any valid templates */ $templates = ""; $found_list = ""; $not_found = ""; $data_template_id = db_fetch_cell("SELECT dtr.data_template_id\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}"); if ($data_template_id != "") { if (sizeof(db_fetch_assoc("SELECT id FROM thold_template WHERE data_template_id={$data_template_id}"))) { $found_list .= "<li>" . get_graph_title($graph) . "</li>"; if (strlen($templates)) { $templates .= ", {$data_template_id}"; } else { $templates = "{$data_template_id}"; } } else { $not_found .= "<li>" . get_graph_title($graph) . "</li>"; } } else { $not_found .= "<li>" . get_graph_title($graph) . "</li>"; } if (strlen($templates)) { $sql = "SELECT id, name FROM thold_template WHERE data_template_id IN (" . $templates . ") ORDER BY name"; } else { $sql = "SELECT id, name FROM thold_template ORDER BY name"; } print "\t<tr>\r\n\t\t\t<td colspan='2' class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>"; if (strlen($found_list)) { if (strlen($not_found)) { print "<p>The following Graph has no Threshold Templates associated with them</p>"; print "<ul>" . $not_found . "</ul>"; } print "<p>Are you sure you wish to create Thresholds for this Graph?\r\n\t\t\t\t<ul>" . $found_list . "</ul>\r\n\t\t\t\t</td>\r\n\t\t\t</tr>\n\r\n\t\t\t"; if (isset($_REQUEST["tree_id"])) { input_validate_input_number($_REQUEST["tree_id"]); } else { $_REQUEST["tree_id"] = ""; } if (isset($_REQUEST["leaf_id"])) { input_validate_input_number($_REQUEST["leaf_id"]); } else { $_REQUEST["leaf_id"] = ""; } $form_array = array('general_header' => array('friendly_name' => 'Available Threshold Templates', 'method' => 'spacer'), 'thold_template_id' => array('method' => 'drop_sql', 'friendly_name' => 'Select a Threshold Template', 'description' => '', 'none_value' => 'None', 'value' => 'None', 'sql' => $sql), 'tree_id' => array('method' => 'hidden', 'value' => $_REQUEST['tree_id']), 'action2' => array('method' => 'hidden', 'value' => $_REQUEST['action2']), 'leaf_id' => array('method' => 'hidden', 'value' => $_REQUEST['leaf_id']), 'usetemplate' => array('method' => 'hidden', 'value' => 1), 'graphid' => array('method' => 'hidden', 'value' => $graph)); draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } else { if (strlen($not_found)) { print "<p>There are no Threshold Templates associated with the following Graph</p>"; print "<ul>" . $not_found . "</ul>"; } if (isset($_REQUEST["tree_id"])) { input_validate_input_number($_REQUEST["tree_id"]); } else { $_REQUEST["tree_id"] = ""; } if (isset($_REQUEST["leaf_id"])) { input_validate_input_number($_REQUEST["leaf_id"]); } else { $_REQUEST["leaf_id"] = ""; } $form_array = array('general_header' => array('friendly_name' => 'Please select an action', 'method' => 'spacer'), 'doaction' => array('method' => 'drop_array', 'friendly_name' => '', 'description' => '', 'value' => 'None', 'array' => array(1 => 'Create a new Threshold', 2 => 'Create a Threshold Template')), 'tree_id' => array('method' => 'hidden', 'value' => $_REQUEST['tree_id']), 'action2' => array('method' => 'hidden', 'value' => $_REQUEST['action2']), 'leaf_id' => array('method' => 'hidden', 'value' => $_REQUEST['leaf_id']), 'usetemplate' => array('method' => 'hidden', 'value' => 1), 'graphid' => array('method' => 'hidden', 'value' => $graph)); draw_edit_form(array("config" => array("no_form_tag" => true), "fields" => $form_array)); } if (!strlen($not_found)) { $save_html = "<input type='submit' value='Yes'>"; print "\t<tr>\r\n\t\t\t\t<td align='right' bgcolor='#eaeaea'>\r\n\t\t\t\t\t<input type='hidden' name='action' value='actions'>\r\n\t\t\t\t\t<input type='button' onClick='javascript:history.go(-1)' value='No' title='Cancel'>\r\n\t\t\t\t\t{$save_html}\r\n\t\t\t\t</td>\r\n\t\t\t</tr>"; } else { $save_html = "<input type='submit' value='Go'>"; print "\t<tr>\r\n\t\t\t\t<td align='right' bgcolor='#eaeaea'>\r\n\t\t\t\t\t<input type='button' onClick='javascript:history.go(-1)' value='Cancel' title='Cancel'>\r\n\t\t\t\t\t{$save_html}\r\n\t\t\t\t</td>\r\n\t\t\t</tr>"; } html_end_box(); include_once "./include/bottom_footer.php"; }
function graph_edit() { global $colors, $struct_graph, $image_types, $consolidation_functions, $graph_item_types, $struct_graph_item; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ $use_graph_template = true; if (!empty($_GET["id"])) { $local_graph_template_graph_id = db_fetch_cell("select local_graph_template_graph_id from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs = db_fetch_row("select * from graph_templates_graph where local_graph_id=" . $_GET["id"]); $graphs_template = db_fetch_row("select * from graph_templates_graph where id=$local_graph_template_graph_id"); $host_id = db_fetch_cell("select host_id from graph_local where id=" . $_GET["id"]); $header_label = "[edit: " . get_graph_title($_GET["id"]) . "]"; if ($graphs["graph_template_id"] == "0") { $use_graph_template = false; } }else{ $header_label = "[new]"; $use_graph_template = false; } /* handle debug mode */ if (isset($_GET["debug"])) { if ($_GET["debug"] == "0") { kill_session_var("graph_debug_mode"); }elseif ($_GET["debug"] == "1") { $_SESSION["graph_debug_mode"] = true; } } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td class="textInfo" colspan="2" valign="top"> <?php print get_graph_title($_GET["id"]);?> </td> <td class="textInfo" align="right" valign="top"> <span style="color: #c16921;">*<a href='graphs.php?action=graph_edit&id=<?php print (isset($_GET["id"]) ? $_GET["id"] : 0);?>&debug=<?php print (isset($_SESSION["graph_debug_mode"]) ? "0" : "1");?>'>Turn <strong><?php print (isset($_SESSION["graph_debug_mode"]) ? "Off" : "On");?></strong> Graph Debug Mode.</a><br> <?php if (!empty($graphs["graph_template_id"])) { ?><span style="color: #c16921;">*<a href='graph_templates.php?action=template_edit&id=<?php print (isset($graphs["graph_template_id"]) ? $graphs["graph_template_id"] : "0");?>'>Edit Graph Template.</a><br><?php } if (!empty($_GET["host_id"]) || !empty($host_id)) { ?><span style="color: #c16921;">*<a href='host.php?action=edit&id=<?php print (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id);?>'>Edit Host.</a><br><?php } ?> </td> </tr> </table> <br> <?php } html_start_box("<strong>Graph Template Selection</strong> $header_label", "100%", $colors["header"], "3", "center", ""); $form_array = array( "graph_template_id" => array( "method" => "drop_sql", "friendly_name" => "Selected Graph Template", "description" => "Choose a graph template to apply to this graph. Please note that graph data may be lost if you change the graph template after one is already applied.", "value" => (isset($graphs) ? $graphs["graph_template_id"] : "0"), "none_value" => "None", "sql" => "select graph_templates.id,graph_templates.name from graph_templates order by name" ), "host_id" => array( "method" => "drop_sql", "friendly_name" => "Host", "description" => "Choose the host that this graph belongs to.", "value" => (isset($_GET["host_id"]) ? $_GET["host_id"] : $host_id), "none_value" => "None", "sql" => "select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname" ), "graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["id"] : "0") ), "local_graph_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["local_graph_id"] : "0") ), "local_graph_template_graph_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["local_graph_template_graph_id"] : "0") ), "_graph_template_id" => array( "method" => "hidden", "value" => (isset($graphs) ? $graphs["graph_template_id"] : "0") ), "_host_id" => array( "method" => "hidden", "value" => (isset($host_id) ? $host_id : "0") ) ); draw_edit_form( array( "config" => array(), "fields" => $form_array ) ); html_end_box(); /* only display the "inputs" area if we are using a graph template for this graph */ if (!empty($graphs["graph_template_id"])) { html_start_box("<strong>Supplemental Graph Template Data</strong>", "100%", $colors["header"], "3", "center", ""); print "<form method='post' action='graphs.php'>\n"; draw_nontemplated_fields_graph($graphs["graph_template_id"], $graphs, "|field|", "<strong>Graph Fields</strong>", true, true, 0); draw_nontemplated_fields_graph_item($graphs["graph_template_id"], $_GET["id"], "|field|_|id|", "<strong>Graph Item Fields</strong>", true); html_end_box(); } /* graph item list goes here */ if ((!empty($_GET["id"])) && (empty($graphs["graph_template_id"]))) { item(); } if (!empty($_GET["id"])) { ?> <table width="100%" align="center"> <tr> <td align="center" class="textInfo" colspan="2"> <img src="graph_image.php?action=edit&local_graph_id=<?php print $_GET["id"];?>&rra_id=<?php print read_graph_config_option("default_rra_id");?>" alt=""> </td> <?php if ((isset($_SESSION["graph_debug_mode"])) && (isset($_GET["id"]))) { $graph_data_array["output_flag"] = RRDTOOL_OUTPUT_STDERR; $graph_data_array["print_source"] = 1; ?> <td> <span class="textInfo">RRDTool Command:</span><br> <pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre> <span class="textInfo">RRDTool Says:</span><br> <?php unset($graph_data_array["print_source"]);?> <pre><?php print rrdtool_function_graph($_GET["id"], 1, $graph_data_array);?></pre> </td> <?php } ?> </tr> </table> <br> <?php } if (((isset($_GET["id"])) || (isset($_GET["new"]))) && (empty($graphs["graph_template_id"]))) { html_start_box("<strong>Graph Configuration</strong>", "100%", $colors["header"], "3", "center", ""); $form_array = array(); while (list($field_name, $field_array) = each($struct_graph)) { $form_array += array($field_name => $struct_graph[$field_name]); $form_array[$field_name]["value"] = (isset($graphs) ? $graphs[$field_name] : ""); $form_array[$field_name]["form_id"] = (isset($graphs) ? $graphs["id"] : "0"); if (!(($use_graph_template == false) || ($graphs_template{"t_" . $field_name} == "on"))) { $form_array[$field_name]["method"] = "template_" . $form_array[$field_name]["method"]; $form_array[$field_name]["description"] = ""; } } draw_edit_form( array( "config" => array( "no_form_tag" => true ), "fields" => $form_array ) ); html_end_box(); } if ((isset($_GET["id"])) || (isset($_GET["new"]))) { form_hidden_box("save_component_graph","1",""); form_hidden_box("save_component_input","1",""); }else{ form_hidden_box("save_component_graph_new","1",""); } form_hidden_box("rrdtool_version", read_config_option("rrdtool_version"), ""); form_save_button("graphs.php"); //Now we need some javascript to make it dynamic ?> <script language="JavaScript"> dynamic(); function dynamic() { //alert("RRDTool Version is '" + document.getElementById('rrdtool_version').value + "'"); //alert("Log is '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } function changeScaleLog() { //alert("Log changed to '" + document.getElementById('auto_scale_log').checked + "'"); if (document.getElementById('scale_log_units')) { document.getElementById('scale_log_units').disabled=true; if ((document.getElementById('rrdtool_version').value != 'rrd-1.0.x') && (document.getElementById('auto_scale_log').checked)) { document.getElementById('scale_log_units').disabled=false; } } } </script> <?php }
function host_new_graphs_save() { $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"])); /* form an array that contains all of the data on the previous form */ while (list($var, $val) = each($_POST)) { if (preg_match("/^g_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["graph_template"][$matches[3]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["graph_template"][$matches[3]] = $val; } } elseif (preg_match("/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: graph_template_input_id, 4:field_name */ /* ================= input validation ================= */ input_validate_input_number($matches[3]); /* ==================================================== */ /* we need to find out which graph items will be affected by saving this particular item */ $item_list = db_fetch_assoc("select\n\t\t\t\tgraph_template_item_id\n\t\t\t\tfrom graph_template_input_defs\n\t\t\t\twhere graph_template_input_id=" . $matches[3]); /* loop through each item affected and update column data */ if (sizeof($item_list) > 0) { foreach ($item_list as $item) { if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["graph_template_item"][$item["graph_template_item_id"]][$matches[4]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["graph_template_item"][$item["graph_template_item_id"]][$matches[4]] = $val; } } } } elseif (preg_match("/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["data_template"][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["data_template"][$matches[3]][$matches[4]] = $val; } } elseif (preg_match("/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:data_input_field_id */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["custom_data"][$matches[3]][$matches[4]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["custom_data"][$matches[3]][$matches[4]] = $val; } } elseif (preg_match("/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: snmp_query_id, 2: graph_template_id, 3: data_template_id, 4:local_data_template_rrd_id, 5:field_name */ if (empty($matches[1])) { /* this is a new graph from template field */ $values["cg"][$matches[2]]["data_template_item"][$matches[4]][$matches[5]] = $val; } else { /* this is a data query field */ $values["sg"][$matches[1]][$matches[2]]["data_template_item"][$matches[4]][$matches[5]] = $val; } } } debug_log_clear("new_graphs"); while (list($form_type, $form_array) = each($selected_graphs_array)) { $current_form_type = $form_type; while (list($form_id1, $form_array2) = each($form_array)) { /* enumerate information from the arrays stored in post variables */ if ($form_type == "cg") { $graph_template_id = $form_id1; } elseif ($form_type == "sg") { while (list($form_id2, $form_array3) = each($form_array2)) { $snmp_index_array = $form_array3; $snmp_query_array["snmp_query_id"] = $form_id1; $snmp_query_array["snmp_index_on"] = get_best_data_query_index_type($_POST["host_id"], $form_id1); $snmp_query_array["snmp_query_graph_id"] = $form_id2; } $graph_template_id = db_fetch_cell("select graph_template_id from snmp_query_graph where id=" . $snmp_query_array["snmp_query_graph_id"]); } if ($current_form_type == "cg") { $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], "", $values["cg"]); debug_log_insert("new_graphs", "Created graph: " . get_graph_title($return_array["local_graph_id"])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array["local_data_id"])) { # we expect at least one data source associated foreach ($return_array["local_data_id"] as $item) { push_out_host($_POST["host_id"], $item); } } else { debug_log_insert("new_graphs", "ERROR: no Data Source associated. Check Template"); } } elseif ($current_form_type == "sg") { while (list($snmp_index, $true) = each($snmp_index_array)) { $snmp_query_array["snmp_index"] = decode_data_query_index($snmp_index, $snmp_query_array["snmp_query_id"], $_POST["host_id"]); $return_array = create_complete_graph_from_template($graph_template_id, $_POST["host_id"], $snmp_query_array, $values["sg"][$snmp_query_array["snmp_query_id"]]); debug_log_insert("new_graphs", "Created graph: " . get_graph_title($return_array["local_graph_id"])); /* lastly push host-specific information to our data sources */ if (sizeof($return_array["local_data_id"])) { # we expect at least one data source associated foreach ($return_array["local_data_id"] as $item) { push_out_host($_POST["host_id"], $item); } } else { debug_log_insert("new_graphs", "ERROR: no Data Source associated. Check Template"); } } } } } }
function resolve_navigation_variables($text) { if (preg_match_all("/\|([a-zA-Z0-9_]+)\|/", $text, $matches)) { for ($i=0; $i<count($matches[1]); $i++) { switch ($matches[1][$i]) { case 'current_graph_title': $text = str_replace("|" . $matches[1][$i] . "|", get_graph_title($_GET["local_graph_id"]), $text); break; } } } return $text; }
function get_tree_leaf_items($tree_id, $leaf_id, $device_group_type, $include_parent = false) { global $current_user, $config; require(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_arrays.php"); // prototype // $items = array($tree_id, $leaf_id, $type, $id, $name); // $tree_id = 'Tree where item exists' // $leaf_id = 'Leaf where item exists' // $type = 'graph|device|site|leaf|dqn|dqi|gtn'; // $id = 'local_graph_id|device_id|site_id|leaf_id|dqn_id|dqi_id|gtn_id' // the following types are only valid if $device_group_data = true // dqn|dqi|gtn include(CACTI_BASE_PATH . "/include/global_arrays.php"); include_once(CACTI_BASE_PATH . "/lib/data_query.php"); include_once(CACTI_BASE_PATH . "/lib/tree.php"); include_once(CACTI_BASE_PATH . "/lib/html_utility.php"); /* get the trees that the user has access to */ $items = array(); if ($tree_id <= 0) { return get_trees($tree_id); }elseif (tree_authorized($tree_id)) { if ($include_parent) { return get_trees($tree_id); } $search_key = ""; if ($leaf_id > 0) { /* return leaf, site, device, graph template or data query items */ $leaf = db_fetch_row("SELECT * FROM graph_tree_items WHERE id=$leaf_id"); $leaf_type = get_tree_item_type($leaf_id); /* get the "starting leaf" if the user clicked on a specific branch */ if (!empty($leaf_id)) { $search_key = substr($leaf["order_key"], 0, (tree_tier($leaf["order_key"]) * CHARS_PER_TIER)); } }else{ $leaf_type = "header"; } $user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . $_SESSION["sess_user_id"]); if ($leaf_type == "header") { if (read_config_option("auth_method") != 0) { $tree_items = db_fetch_assoc("SELECT * FROM graph_tree_items WHERE graph_tree_id=$tree_id AND id!=$leaf_id AND order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'"); if (sizeof($tree_items)) { foreach($tree_items AS $item) { if ($item["local_graph_id"]) { if (graph_authorized($item["local_graph_id"], $user)) { $new_tree_items[] = $item; } }elseif ($item["device_id"]) { if (device_authorized($item["device_id"], $user)) { $new_tree_items[] = $item; } }else{ $new_tree_items[] = $item; } } $tree_items = $new_tree_items; } }else{ $tree_items = db_fetch_assoc("SELECT * FROM graph_tree_items WHERE graph_tree_id=$tree_id AND id!=$leaf_id AND order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'"); } if (sizeof($tree_items)) { foreach($tree_items as $item) { if ($item["local_graph_id"] > 0) { $items[] = array( "tree_id" => $tree_id, "leaf_id" => $item["id"], "type" => 'graph', "id" => $item["local_graph_id"], "name" => get_graph_title($item["local_graph_id"]) ); }elseif ($item["device_id"] > 0) { $items[] = array( "tree_id" => $tree_id, "leaf_id" => $item["id"], "type" => 'device', "id" => $item["device_id"], "name" => get_device_description($item["device_id"]) ); }else{ $items[] = array( "tree_id" => $tree_id, "leaf_id" => $item["id"], "type" => 'header', "id" => $item["id"], "name" => $item["title"] ); } } } return $items; }elseif ($leaf_type == "device") { if (read_graph_config_option("expand_devices") == CHECKED) { if ($leaf["device_grouping_type"] == TREE_DEVICE_GROUPING_GRAPH_TEMPLATE) { if ((isset($device_group_type)) && ($device_group_type[0] != 'gt')) { $items = get_device_grouping_graph_templates($leaf, $user); } }else{ if (isset($device_group_type)) { if (($device_group_type[0] != 'dqi') && ($device_group_type[0] != 'dq')) { $items = get_device_grouping_data_queries($leaf); }elseif ($device_group_type[0] != 'dqi') { $items = get_device_grouping_data_query_items($leaf, $device_group_type); } } } } return $items; }else{ return $items; } }else{ return $items; } }