function generate_complete_graph($graph_template_id, $host_id = 0, $data_query_id = 0, $data_query_index = "") { require_once(CACTI_BASE_PATH . "/lib/graph/graph_update.php"); require_once(CACTI_BASE_PATH . "/lib/data_template/data_template_push.php"); require_once(CACTI_BASE_PATH . "/lib/data_template/data_template_info.php"); /* sanity check for $graph_template_id */ if ((!is_numeric($graph_template_id)) || (empty($graph_template_id))) { return false; } /* sanity check for $host_id */ if (!is_numeric($host_id)) { return false; } $data_templates = get_data_templates_from_graph_template($graph_template_id); /* decide which data sources we will need to create */ $create_data_templates_list = array(); if (sizeof($data_templates) > 0) { foreach ($data_templates as $item) { if (($item["data_input_type"] == DATA_INPUT_TYPE_DATA_QUERY) && (isset($form_data_input_fields["data_query_id"]))) { if (db_fetch_cell("select value from data_template_field where data_template_id = " . $item["id"] . " and name = 'data_query_id'") == $form_data_input_fields["data_query_id"]) { $create_data_templates_list[] = $item["id"]; } }else{ $create_data_templates_list[] = $item["id"]; } } } /* no data templates have been marked for creation */ if (sizeof($create_data_templates_list) == 0) { return false; } $dti_to_dsi = array(); foreach ($create_data_templates_list as $data_template_id) { $data_source_id = copy_data_template_to_data_source($data_template_id, $host_id, $data_query_id, $data_query_index); if ($data_source_id === false) { log_save("Error generating data source from data template [ID#$data_template_id]", SEV_ERROR); }else{ $dti_to_dsi[$data_template_id] = $data_source_id; } } /* create the actual graph from the chosen graph template */ $graph_id = copy_graph_template_to_graph($graph_template_id, $host_id, $data_query_id, $data_query_index); if ($graph_id === false) { log_save("Error generating graph from graph template [ID#$graph_template_id]", SEV_ERROR); }else{ /* fetch a list graph template items and their associated data template items */ $data_template_items = get_data_template_items_from_graph_template($graph_template_id); if (sizeof($data_template_items) > 0) { foreach ($data_template_items as $item) { /* write out the graph->data source item mapping here. note, that we are only able to use 'sequence' * as a primary key here because the graph was just created above and therefore must be accurate */ db_update("graph_item", array( "id" => array("type" => DB_TYPE_INTEGER, "value" => db_fetch_cell("select id from graph_item where graph_id = " . sql_sanitize($graph_id) . " and graph_template_item_id = " . sql_sanitize($item["graph_template_item_id"]))), "data_source_item_id" => array("type" => DB_TYPE_INTEGER, "value" => db_fetch_cell("select id from data_source_item where data_source_name = '" . sql_sanitize($item["data_source_name"]) . "' and data_source_id = " . sql_sanitize($dti_to_dsi{$item["data_template_id"]}))) ), array("id")); } } /* make sure the graph title is up to date */ api_graph_title_cache_update($graph_id); return array("graph" => array($graph_template_id => $graph_id), "data_source" => $dti_to_dsi); } return false; }
function host_new_graphs_save() { $validation_array = array(); $selected_graphs_array = unserialize(stripslashes($_POST["selected_graphs_array"])); $map_id_to_index_array = unserialize(stripslashes($_POST["map_id_to_index_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: data_query_id, 2: graph_template_id, 3: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["graph_template"][$matches[3]] = $val; } $validation_array["graph_template"][$matches[3]][$var] = $val; } elseif (preg_match("/^gi_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: graph_template_input_id, 4: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["graph_template_item"][$matches[2]][$matches[3]] = $val; } $validation_array["graph_template_item"][$matches[4]][$var] = $val; } elseif (preg_match("/^d_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["data_template"][$matches[3]][$matches[4]] = $val; } $validation_array["data_template"][$matches[4]][$var] = $val; } elseif (preg_match("/^c_(\\d+)_(\\d+)_(\\d+)_(\\d+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_input_field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["custom_data"][$matches[3]][$matches[4]] = $val; } $validation_array["custom_data"][$matches[4]][$var] = $val; } elseif (preg_match("/^di_(\\d+)_(\\d+)_(\\d+)_(\\d+)_(\\w+)/", $var, $matches)) { /* 1: data_query_id, 2: graph_template_id, 3: data_template_id, 4: data_template_item_id, 5: field_name */ foreach ($map_id_to_index_array[empty($matches[1]) ? "gt" : "dq"][empty($matches[1]) ? $matches[2] : $matches[1]] as $uniq_id) { $selected_graphs_array[$uniq_id]["data_template_item"][$matches[3]][$matches[4]][$matches[5]] = $val; } $validation_array["data_template_item"][$matches[5]][$var] = $val; } } /* first pass: form validation */ while (list($type, $type_array) = each($validation_array)) { while (list($field_name, $field_array) = each($type_array)) { while (list($form_field_name, $value) = each($field_array)) { $_v_arr = array($field_name => $value); if ($type == "data_template") { $_sv_arr = array(); field_register_error(api_data_source_fields_validate($_v_arr, $_sv_arr, $form_field_name, "")); } else { if ($type == "custom_data") { field_register_error(api_data_source_input_fields_validate($_v_arr, $form_field_name)); } else { if ($type == "data_template_item") { $_v_arr["id"] = 0; field_register_error(api_data_source_item_fields_validate($_v_arr, $form_field_name)); } else { if ($type == "graph_template") { $_sv_arr = array(); field_register_error(api_graph_fields_validate($_v_arr, $_sv_arr, $form_field_name, "")); } else { if ($type == "graph_template_item") { field_register_error(api_graph_item_fields_validate($_v_arr, $form_field_name)); } } } } } } } } /* form validation failed: redirect back */ if (is_error_message()) { /* cache all post field values */ init_post_field_cache(); host_new_graphs($selected_graphs_array, $map_id_to_index_array); /* form validation passed: save the data on the form */ } else { debug_log_clear("new_graphs"); foreach ($selected_graphs_array as $uniq_id => $skel) { if (isset($skel["custom_data"]["all_dq"])) { $is_data_query_graph = true; $data_query_id = isset($skel["custom_data"]["all_dq"]["data_query_id"]) ? $skel["custom_data"]["all_dq"]["data_query_id"] : 0; /* decode the data query index into its literal form */ $data_query_index = decode_data_query_index(isset($skel["custom_data"]["all_dq"]["data_query_index"]) ? $skel["custom_data"]["all_dq"]["data_query_index"] : 0, get_data_query_indexes($data_query_id, $_POST["host_id"])); } else { $is_data_query_graph = false; $data_query_id = 0; $data_query_index = ""; } $create_info = generate_complete_graph($skel["graph_template_id"], $_POST["host_id"], $data_query_id, $data_query_index); /* set the appropriate 'custom_data' keys */ if ($is_data_query_graph == true) { /* pick the data query field name to index on */ $data_query_field_name = get_best_data_query_index_type($_POST["host_id"], $data_query_id); /* get a list of all data templates associated with this graph template that are of type DATA_INPUT_TYPE_DATA_QUERY */ $dq_data_templates = get_data_templates_from_graph_template($skel["graph_template_id"], DATA_INPUT_TYPE_DATA_QUERY); if (sizeof($dq_data_templates) > 0) { foreach ($dq_data_templates as $data_template) { $skel["custom_data"][$data_template["id"]]["data_query_id"] = $data_query_id; $skel["custom_data"][$data_template["id"]]["data_query_index"] = $data_query_index; $skel["custom_data"][$data_template["id"]]["data_query_field_name"] = $data_query_field_name; $skel["custom_data"][$data_template["id"]]["data_query_field_value"] = get_data_query_row_value($data_query_id, $_POST["host_id"], $data_query_field_name, $data_query_index); } } } /* update user specified data: data source-specific fields */ foreach (array_keys($create_info["data_source"]) as $data_template_id) { if (isset($skel["data_template"][$data_template_id])) { if (!api_data_source_save($create_info["data_source"][$data_template_id], $skel["data_template"][$data_template_id])) { log_save("Problems updating new data source [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } if (isset($skel["data_template_item"][$data_template_id])) { foreach ($skel["data_template_item"][$data_template_id] as $data_source_item_id => $data_template_item_array) { if (!api_data_source_item_save($data_source_item_id, $data_template_item_array)) { log_save("Problems updating new data source [item] [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } } if (isset($skel["custom_data"][$data_template_id])) { if (!api_data_source_fields_save($create_info["data_source"][$data_template_id], $skel["custom_data"][$data_template_id])) { log_save("Problems updating new data source (fields) [ID#" . $create_info["data_source"][$data_template_id] . "], data template [ID#{$data_template_id}] from user data", SEV_ERROR); } } /* update the title cache */ api_data_source_title_cache_update($create_info["data_source"][$data_template_id]); /* update poller cache */ update_poller_cache($create_info["data_source"][$data_template_id]); } /* update user specified data: graph-specific fields */ foreach (array_keys($create_info["graph"]) as $graph_template_id) { if (isset($skel["graph_template"][$graph_template_id])) { if (!api_graph_save($create_info["graph"][$graph_template_id], $skel["graph_template"][$graph_template_id])) { log_save("Problems updating new graph [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR); } } if (isset($skel["graph_template_item"][$graph_template_id])) { foreach ($skel["graph_template_item"][$graph_template_id] as $graph_template_item_input_id => $value) { if (!api_graph_template_item_input_propagate($graph_template_item_input_id, $value)) { log_save("Problems updating new graph [item] [ID#" . $create_info["graph"][$graph_template_id] . "], graph template [ID#{$graph_template_id}] from user data", SEV_ERROR); } } } /* update the title cache */ api_graph_title_cache_update($create_info["graph"][$graph_template_id]); } debug_log_insert("new_graphs", _("Created graph: ") . api_graph_title_get($create_info["graph"][$skel["graph_template_id"]])); } /* lastly push host-specific information to our data sources */ //push_out_host($_POST["host_id"], 0); } }
function duplicate_graph($_local_graph_id, $_graph_template_id, $graph_title) { global $struct_graph, $struct_graph_item; if (!empty($_local_graph_id)) { $graph_local = db_fetch_row("select * from graph_local where id=$_local_graph_id"); $graph_template_graph = db_fetch_row("select * from graph_templates_graph where local_graph_id=$_local_graph_id"); $graph_template_items = db_fetch_assoc("select * from graph_templates_item where local_graph_id=$_local_graph_id"); /* create new entry: graph_local */ $save["id"] = 0; $save["graph_template_id"] = $graph_local["graph_template_id"]; $save["host_id"] = $graph_local["host_id"]; $save["snmp_query_id"] = $graph_local["snmp_query_id"]; $save["snmp_index"] = $graph_local["snmp_index"]; $local_graph_id = sql_save($save, "graph_local"); $graph_template_graph["title"] = str_replace("<graph_title>", $graph_template_graph["title"], $graph_title); }elseif (!empty($_graph_template_id)) { $graph_template = db_fetch_row("select * from graph_templates where id=$_graph_template_id"); $graph_template_graph = db_fetch_row("select * from graph_templates_graph where graph_template_id=$_graph_template_id and local_graph_id=0"); $graph_template_items = db_fetch_assoc("select * from graph_templates_item where graph_template_id=$_graph_template_id and local_graph_id=0"); $graph_template_inputs = db_fetch_assoc("select * from graph_template_input where graph_template_id=$_graph_template_id"); /* create new entry: graph_templates */ $save["id"] = 0; $save["hash"] = get_hash_graph_template(0); $save["name"] = str_replace("<template_title>", $graph_template["name"], $graph_title); $graph_template_id = sql_save($save, "graph_templates"); } unset($save); reset($struct_graph); /* create new entry: graph_templates_graph */ $save["id"] = 0; $save["local_graph_id"] = (isset($local_graph_id) ? $local_graph_id : 0); $save["local_graph_template_graph_id"] = (isset($graph_template_graph["local_graph_template_graph_id"]) ? $graph_template_graph["local_graph_template_graph_id"] : 0); $save["graph_template_id"] = (!empty($_local_graph_id) ? $graph_template_graph["graph_template_id"] : $graph_template_id); $save["title_cache"] = $graph_template_graph["title_cache"]; reset($struct_graph); while (list($field, $array) = each($struct_graph)) { $save{$field} = $graph_template_graph{$field}; $save{"t_" . $field} = $graph_template_graph{"t_" . $field}; } $graph_templates_graph_id = sql_save($save, "graph_templates_graph"); /* create new entry(s): graph_templates_item */ if (sizeof($graph_template_items) > 0) { foreach ($graph_template_items as $graph_template_item) { unset($save); reset($struct_graph_item); $save["id"] = 0; $save["local_graph_id"] = (isset($local_graph_id) ? $local_graph_id : 0); $save["graph_template_id"] = (!empty($_local_graph_id) ? $graph_template_item["graph_template_id"] : $graph_template_id); $save["local_graph_template_item_id"] = (isset($graph_template_item["local_graph_template_item_id"]) ? $graph_template_item["local_graph_template_item_id"] : 0); while (list($field, $array) = each($struct_graph_item)) { $save{$field} = $graph_template_item{$field}; } $graph_item_mappings{$graph_template_item["id"]} = sql_save($save, "graph_templates_item"); } } if (!empty($_graph_template_id)) { /* create new entry(s): graph_template_input (graph template only) */ if (sizeof($graph_template_inputs) > 0) { foreach ($graph_template_inputs as $graph_template_input) { unset($save); $save["id"] = 0; $save["graph_template_id"] = $graph_template_id; $save["name"] = $graph_template_input["name"]; $save["description"] = $graph_template_input["description"]; $save["column_name"] = $graph_template_input["column_name"]; $graph_template_input_id = sql_save($save, "graph_template_input"); $graph_template_input_defs = db_fetch_assoc("select * from graph_template_input_defs where graph_template_input_id=" . $graph_template_input["id"]); /* create new entry(s): graph_template_input_defs (graph template only) */ if (sizeof($graph_template_input_defs) > 0) { foreach ($graph_template_input_defs as $graph_template_input_def) { db_execute("insert into graph_template_input_defs (graph_template_input_id,graph_template_item_id) values ($graph_template_input_id," . $graph_item_mappings{$graph_template_input_def["graph_template_item_id"]} . ")"); } } } } } if (!empty($_local_graph_id)) { api_graph_title_cache_update($local_graph_id); } }
function form_actions() { global $colors, $graph_actions; /* if we are to save this form, instead of display it */ if (isset($_POST["selected_items"])) { $selected_items = unserialize(stripslashes($_POST["selected_items"])); if ($_POST["drp_action"] == "1") { /* delete */ for ($i = 0; $i < count($selected_items); $i++) { if (!isset($_POST["delete_type"])) { $_POST["delete_type"] = 1; } switch ($_POST["delete_type"]) { case '2': /* delete all data sources referenced by this graph */ $data_sources = db_fetch_assoc("select distinct\n\t\t\t\t\t\t\tdata_source.id\n\t\t\t\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\t\t\t\tand " . array_to_sql_or($selected_items, "graph_item.graph_id") . "\n\t\t\t\t\t\t\torder by data_source.name_cache"); if (sizeof($data_sources) > 0) { foreach ($data_sources as $data_source) { api_data_source_remove($data_source["id"]); } } break; } api_graph_remove($selected_items[$i]); } } elseif ($_POST["drp_action"] == "2") { /* change graph template */ for ($i = 0; $i < count($selected_items); $i++) { change_graph_template($selected_items[$i], $_POST["graph_template_id"], true); } } elseif ($_POST["drp_action"] == "3") { /* duplicate */ for ($i = 0; $i < count($selected_items); $i++) { duplicate_graph($selected_items[$i], 0, $_POST["title_format"]); } } elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */ for ($i = 0; $i < count($selected_items); $i++) { graph_to_graph_template($selected_items[$i], $_POST["title_format"]); } } elseif (ereg("^tr_([0-9]+)\$", $_POST["drp_action"], $matches)) { /* place on tree */ for ($i = 0; $i < count($selected_items); $i++) { api_tree_item_save(0, $_POST["tree_id"], TREE_ITEM_TYPE_GRAPH, $_POST["tree_item_id"], "", $selected_items[$i], read_graph_config_option("default_rra_id"), 0, 0, 0, false); } } elseif ($_POST["drp_action"] == "5") { /* change host */ for ($i = 0; $i < count($selected_items); $i++) { db_execute("update graph set host_id = " . $_POST["host_id"] . " where id = " . $selected_items[$i]); api_graph_title_cache_update($selected_items[$i]); } } elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming */ for ($i = 0; $i < count($selected_items); $i++) { api_reapply_suggested_graph_title($selected_items[$i]); api_graph_title_cache_update($selected_items[$i]); } } elseif ($_POST["drp_action"] == "7") { /* resize graphs */ for ($i = 0; $i < count($selected_items); $i++) { api_graph_resize($selected_items[$i], $_POST["graph_width"], $_POST["graph_height"]); } } header("Location: graphs.php"); exit; } /* setup some variables */ $graph_list = ""; $i = 0; /* loop through each of the graphs selected on the previous page and get more info about them */ while (list($var, $val) = each($_POST)) { if (ereg("^chk_([0-9]+)\$", $var, $matches)) { $graph_list .= "<li>" . db_fetch_cell("select title_cache from graph where id = " . $matches[1]) . "<br>"; $graph_array[$i] = $matches[1]; } $i++; } require_once CACTI_BASE_PATH . "/include/top_header.php"; html_start_box("<strong>" . $graph_actions[$_POST["drp_action"]] . "</strong>", "60%", $colors["header_panel_background"], "3", "center", ""); print "<form action='graphs.php' method='post'>\n"; if ($_POST["drp_action"] == "1") { /* delete */ $graphs = array(); /* find out which (if any) data sources are being used by this graph, so we can tell the user */ if (isset($graph_array)) { $data_sources = db_fetch_assoc("select distinct\n\t\t\t\tdata_source.id,\n\t\t\t\tdata_source.name_cache\n\t\t\t\tfrom data_source_item,data_source,graph_item\n\t\t\t\twhere graph_item.data_source_item_id=data_source_item.id\n\t\t\t\tand data_source_item.data_source_id=data_source.id\n\t\t\t\tand " . array_to_sql_or($graph_array, "graph_item.graph_id") . "\n\t\t\t\torder by data_source.name_cache"); } print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Are you sure you want to delete the following graphs?") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t"; if (sizeof($data_sources) > 0) { print "<tr bgcolor='#" . $colors["form_alternate1"] . "'><td class='textArea'><p class='textArea'>" . _("The following data sources are in use by these graphs:") . "</p>\n"; foreach ($data_sources as $data_source) { print "<strong>" . $data_source["name_cache"] . "</strong><br>\n"; } print "<br>"; form_radio_button("delete_type", "1", "1", _("Leave the data sources untouched."), "1"); print "<br>"; form_radio_button("delete_type", "1", "2", _("Delete all <strong>data sources</strong> referenced by these graphs."), "1"); print "<br>"; print "</td></tr>"; } print "\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "2") { /* change graph template */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Choose a graph template and click save to change the graph template for\n\t\t\t\t\tthe following graphs. Be aware that all warnings will be suppressed during the\n\t\t\t\t\tconversion, so graph data loss is possible.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("New Graph Template:") . "</strong><br>"; form_dropdown("graph_template_id", db_fetch_assoc("select graph_templates.id,graph_templates.name from graph_templates"), "name", "id", "", "", "0"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "3") { /* duplicate */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will be duplicated. You can\n\t\t\t\t\toptionally change the title format for the new graphs.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Title Format:") . "</strong><br>"; form_text_box("title_format", "<graph_title> (1)", "", "255", "30", "text"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "4") { /* graph -> graph template */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will be converted into graph templates.\n\t\t\t\t\tYou can optionally change the title format for the new graph templates.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Title Format:") . "</strong><br>"; form_text_box("title_format", "<graph_title> " . _("Template"), "", "255", "30", "text"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "5") { /* change device */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("Choose a new host for these graphs:") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("New Device:") . "</strong><br>"; form_dropdown("host_id", db_fetch_assoc("select id,CONCAT_WS('',description,' (',hostname,')') as name from host order by description,hostname"), "name", "id", "", "", "0"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "6") { /* reapply suggested naming to host */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will have thier suggested naming convensions\n\t\t\t\t\trecalculated and applies to the graphs.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "7") { /* reapply suggested naming to host */ print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>When you click save, the following graphs will be resized per your specifications.</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>Graph Height:</strong><br>"; form_text_box("graph_height", "", "", "255", "30", "text"); print "</p>\n\t\t\t\t\t<p><strong>Graph Width:</strong><br>"; form_text_box("graph_width", "", "", "255", "30", "text"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t"; } elseif ($_POST["drp_action"] == "8") { /* place on tree */ $trees = db_fetch_assoc("select id,name from graph_tree order by name"); print "\t<tr>\n\t\t\t\t<td class='textArea' bgcolor='#" . $colors["form_alternate1"] . "'>\n\t\t\t\t\t<p>" . _("When you click save, the following graphs will be placed under the branch selected\n\t\t\t\t\tbelow.") . "</p>\n\t\t\t\t\t<p>{$graph_list}</p>\n\t\t\t\t\t<p><strong>" . _("Destination Branch:") . "</strong><br>"; html_tree_dropdown_draw($matches[1], "tree_item_id", "0"); print "</p>\n\t\t\t\t</td>\n\t\t\t</tr>\n\n\t\t\t<input type='hidden' name='tree_id' value='" . $matches[1] . "'>\n\n\t\t\t"; } if (!isset($graph_array)) { print "<tr><td bgcolor='#" . $colors["form_alternate1"] . "'><span class='textError'>" . _("You must select at least one graph.") . "</span></td></tr>\n"; $save_html = ""; } else { $save_html = "<input type='image' src='" . html_get_theme_images_path("button_yes.gif") . "' alt='" . _("Save") . "' align='absmiddle'>"; } print "\t<tr>\n\t\t\t<td align='right' bgcolor='#" . $colors["buttonbar_background"] . "'>\n\t\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t\t<input type='hidden' name='selected_items' value='" . (isset($graph_array) ? serialize($graph_array) : '') . "'>\n\t\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t\t<a href='graphs.php'><img src='" . html_get_theme_images_path("button_no.gif") . "' alt='" . _("Cancel") . "' align='absmiddle' border='0'></a>\n\t\t\t\t{$save_html}\n\t\t\t</td>\n\t\t</tr>\n\t\t"; html_end_box(); require_once CACTI_BASE_PATH . "/include/bottom_footer.php"; }
function update_graph_data_query_cache($local_graph_id) { $host_id = db_fetch_cell("select host_id from graph_local where id=$local_graph_id"); $field = data_query_field_list(db_fetch_cell("select data_template_data.id from graph_templates_item,data_template_rrd,data_template_data where graph_templates_item.task_item_id=data_template_rrd.id and data_template_rrd.local_data_id=data_template_data.local_data_id and graph_templates_item.local_graph_id=$local_graph_id limit 0,1")); if (empty($field)) { return; } $data_query_id = db_fetch_cell("select snmp_query_id from snmp_query_graph where id='" . $field["output_type"] . "'"); $index = get_data_query_row_index($data_query_id, $host_id, $field["index_type"], $field["index_value"]); if (($data_query_id != "0") && ($index != "")) { db_execute("update graph_local set snmp_query_id='$data_query_id',snmp_index='$index' where id=$local_graph_id"); /* update graph title cache */ api_graph_title_cache_update($local_graph_id); } }
function api_graph_title_cache_update_from_query($snmp_query_id, $snmp_index) { $graphs = db_fetch_assoc("select id from graph_local where snmp_query_id=$snmp_query_id and snmp_index='$snmp_index'"); if (sizeof($graphs) > 0) { foreach ($graphs as $item) { api_graph_title_cache_update($item["id"]); } } }