"Delete", 2 => "Enable", 3 => "Disable", 4 => "Change SNMP Options", 5 => "Clear Statistics", 6 => "Change Availability Options" ); /* set default action */ if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; } switch ($_REQUEST["action"]) { case 'save': form_save(); break; case 'actions': form_actions(); break; case 'gt_remove': host_remove_gt(); header("Location: host.php?action=edit&id=" . $_GET["host_id"]); break; case 'query_remove': host_remove_query(); header("Location: host.php?action=edit&id=" . $_GET["host_id"]); break; case 'query_reload': host_reload_query(); header("Location: host.php?action=edit&id=" . $_GET["host_id"]); break; case 'query_verbose': host_reload_query(); header("Location: host.php?action=edit&id=" . $_GET["host_id"] . "&display_dq_details=true"); break; case 'edit': include_once("./include/top_header.php"); host_edit(); include_once("./include/bottom_footer.php"); break; default: include_once("./include/top_header.php"); host(); include_once("./include/bottom_footer.php"); break; } /* -------------------------- Global Form Functions -------------------------- */ function add_tree_names_to_actions_array() { global $device_actions; /* add a list of tree names to the actions dropdown */ $trees = db_fetch_assoc("select id,name from graph_tree order by name"); if (sizeof($trees) > 0) { foreach ($trees as $tree) { $device_actions{"tr_" . $tree["id"]} = "Place on a Tree (" . $tree["name"] . ")"; } } } /* -------------------------- The Save Function -------------------------- */ function form_save() { if ((!empty($_POST["add_dq_x"])) && (!empty($_POST["snmp_query_id"]))) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("id")); input_validate_input_number(get_request_var_post("snmp_query_id")); input_validate_input_number(get_request_var_post("reindex_method")); /* ==================================================== */ db_execute("replace into host_snmp_query (host_id,snmp_query_id,reindex_method) values (" . $_POST["id"] . "," . $_POST["snmp_query_id"] . "," . $_POST["reindex_method"] . ")"); /* recache snmp data */ run_data_query($_POST["id"], $_POST["snmp_query_id"]); header("Location: host.php?action=edit&id=" . $_POST["id"]); exit; } if ((!empty($_POST["add_gt_x"])) && (!empty($_POST["graph_template_id"]))) { /* ================= input validation ================= */ input_validate_input_number(get_request_var_post("id")); input_validate_input_number(get_request_var_post("graph_template_id")); /* ==================================================== */ db_execute("replace into host_graph (host_id,graph_template_id) values (" . $_POST["id"] . "," . $_POST["graph_template_id"] . ")"); header("Location: host.php?action=edit&id=" . $_POST["id"]); exit; } if ((isset($_POST["save_component_host"])) && (empty($_POST["add_dq_x"]))) { if ($_POST["snmp_version"] == 3 && ($_POST["snmp_password"] != $_POST["snmp_password_confirm"])) { raise_message(4); }else{ $host_id = api_device_save($_POST["id"], $_POST["host_template_id"], $_POST["description"], trim($_POST["hostname"]), $_POST["snmp_community"], $_POST["snmp_version"], $_POST["snmp_username"], $_POST["snmp_password"], $_POST["snmp_port"], $_POST["snmp_timeout"], (isset($_POST["disabled"]) ? $_POST["disabled"] : ""), $_POST["availability_method"], $_POST["ping_method"], $_POST["ping_port"], $_POST["ping_timeout"], $_POST["ping_retries"], $_POST["notes"], $_POST["snmp_auth_protocol"], $_POST["snmp_priv_passphrase"], $_POST["snmp_priv_protocol"], $_POST["snmp_context"], $_POST["max_oids"]); } header("Location: host.php?action=edit&id=" . (empty($host_id) ? $_POST["id"] : $host_id)); } } /* ------------------------ The "actions" function ------------------------ */ function form_actions() { global $colors, $device_actions, $fields_host_edit; /* 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"] == "2") { /* Enable Selected Devices */ for ($i=0;($i 0) { foreach ($data_sources as $data_source) { update_poller_cache($data_source["id"], false); } } } }elseif ($_POST["drp_action"] == "3") { /* Disable Selected Devices */ for ($i=0;($i 0) { foreach ($data_sources as $data_source) { $data_sources_to_act_on[] = $data_source["local_data_id"]; } } if ($_POST["delete_type"] == 2) { $graphs = db_fetch_assoc("select graph_local.id as local_graph_id from graph_local where " . array_to_sql_or($selected_items, "graph_local.host_id")); if (sizeof($graphs) > 0) { foreach ($graphs as $graph) { $graphs_to_act_on[] = $graph["local_graph_id"]; } } } $devices_to_act_on[] = $selected_items[$i]; } switch ($_POST["delete_type"]) { case '1': /* leave graphs and data_sources in place, but disable the data sources */ api_data_source_disable_multi($data_sources_to_act_on); break; case '2': /* delete graphs/data sources tied to this device */ api_data_source_remove_multi($data_sources_to_act_on); api_graph_remove_multi($graphs_to_act_on); break; } api_device_remove_multi($devices_to_act_on); }elseif (ereg("^tr_([0-9]+)$", $_POST["drp_action"], $matches)) { /* place on tree */ for ($i=0;($i"; $host_array[$i] = $matches[1]; $i++; } } include_once("./include/top_header.php"); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); html_start_box("" . $device_actions{$_POST["drp_action"]} . "", "60%", $colors["header_panel"], "3", "center", ""); print "
\n"; if (isset($host_array) && sizeof($host_array)) { if ($_POST["drp_action"] == "2") { /* Enable Devices */ print "

To enable the following Device(s), click \"Continue\".

    " . $host_list . "

"; $save_html = " "; }elseif ($_POST["drp_action"] == "3") { /* Disable Devices */ print "

To disable the following Device(s), click \"Continue\".

    " . $host_list . "

"; $save_html = " "; }elseif ($_POST["drp_action"] == "4") { /* change snmp options */ print "

To change SNMP parameters for the following Device(s), check the box next to the fields you want to update, fill in the new value, and click \"Continue\".

    " . $host_list . "

"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if ((ereg("^snmp_", $field_name)) || ($field_name == "max_oids")) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array( "name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "" ); } } draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => $form_array ) ); $save_html = " "; }elseif ($_POST["drp_action"] == "6") { /* change availability options */ print "

To change Availability parameters for the following Device(s), check the box next to the fields you want to update, fill in the new value, and click \"Continue\".

    " . $host_list . "

"; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("(availability_method|ping_method|ping_port)", $field_name)) { $form_array += array($field_name => $fields_host_edit[$field_name]); $form_array[$field_name]["value"] = ""; $form_array[$field_name]["description"] = ""; $form_array[$field_name]["form_id"] = 0; $form_array[$field_name]["sub_checkbox"] = array( "name" => "t_" . $field_name, "friendly_name" => "Update this Field", "value" => "" ); } } draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => $form_array ) ); $save_html = " "; }elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ print "

To clear the counters for the following Device(s), press the \"Continue\" button below.

    " . $host_list . "

"; $save_html = " "; }elseif ($_POST["drp_action"] == "1") { /* delete */ print "

When you click \"Continue\" the following Device(s) will be deleted.

    " . $host_list . "

"; form_radio_button("delete_type", "2", "1", "Leave all Graph(s) and Data Source(s) untouched. Data Source(s) will be disabled however.", "1"); print "
"; form_radio_button("delete_type", "2", "2", "Delete all associated Graph(s) and Data Source(s).", "1"); print "
"; print " \n "; $save_html = " "; }elseif (ereg("^tr_([0-9]+)$", $_POST["drp_action"], $matches)) { /* place on tree */ print "

When you click \"Continue\", the following Device(s) will be placed under the branch selected below.

    " . $host_list . "

Destination Branch:
"; grow_dropdown_tree($matches[1], "tree_item_id", "0"); print "

\n \n "; $save_html = " "; } }else{ print "You must select at least one device.\n"; $save_html = ""; } print " $save_html "; html_end_box(); include_once("./include/bottom_footer.php"); } /* ------------------- Data Query Functions ------------------- */ function host_reload_query() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("host_id")); /* ==================================================== */ run_data_query($_GET["host_id"], $_GET["id"]); } function host_remove_query() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("host_id")); /* ==================================================== */ api_device_dq_remove($_GET["host_id"], $_GET["id"]); } function host_remove_gt() { /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); input_validate_input_number(get_request_var("host_id")); /* ==================================================== */ api_device_gt_remove($_GET["host_id"], $_GET["id"]); } /* --------------------- Host Functions --------------------- */ function host_remove() { global $config; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if ((read_config_option("deletion_verification") == "on") && (!isset($_GET["confirm"]))) { include("./include/top_header.php"); form_confirm("Are You Sure?", "Are you sure you want to delete the host '" . htmlspecialchars(db_fetch_cell("select description from host where id=" . $_GET["id"])) . "'?", htmlspecialchars("host.php"), htmlspecialchars("host.php?action=remove&id=" . $_GET["id"])); include("./include/bottom_footer.php"); exit; } if ((read_config_option("deletion_verification") == "") || (isset($_GET["confirm"]))) { api_device_remove($_GET["id"]); } } function host_edit() { global $colors, $fields_host_edit, $reindex_types; /* ================= input validation ================= */ input_validate_input_number(get_request_var("id")); /* ==================================================== */ if (!empty($_GET["id"])) { $host = db_fetch_row("select * from host where id=" . $_GET["id"]); $header_label = "[edit: " . htmlspecialchars($host["description"]) . "]"; }else{ $header_label = "[new]"; } if (!empty($host["id"])) { ?>
()
SNMP Information
SNMP not in use\n"; }else{ $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"),SNMP_WEBUI); /* modify for some system descriptions */ /* 0000937: System output in host.php poor for Alcatel */ if (substr_count($snmp_system, "00:")) { $snmp_system = str_replace("00:", "", $snmp_system); $snmp_system = str_replace(":", " ", $snmp_system); } if ($snmp_system == "") { print "SNMP error\n"; }else{ $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); $snmp_contact = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI); print "System:" . html_split_string($snmp_system) . "
\n"; $days = intval($snmp_uptime / (60*60*24*100)); $remainder = $snmp_uptime % (60*60*24*100); $hours = intval($remainder / (60*60*100)); $remainder = $remainder % (60*60*100); $minutes = intval($remainder / (60*100)); print "Uptime: $snmp_uptime"; print " ($days days, $hours hours, $minutes minutes)
\n"; print "Hostname: $snmp_hostname
\n"; print "Location: $snmp_location
\n"; print "Contact: $snmp_contact
\n"; } } ?> host = $host; $ping->port = $host["ping_port"]; /* perform the appropriate ping check of the host */ if ($ping->ping($host["availability_method"], $host["ping_method"], $host["ping_timeout"], $host["ping_retries"])) { $host_down = false; $color = "#000000"; }else{ $host_down = true; $color = "#ff0000"; } ?>
Ping Results
ping_response; ?> No Availability Check In Use
*">Create Graphs for this Host
*">Data Source List
*">Graph List
Devices $header_label", "100%", $colors["header"], "3", "center", ""); /* preserve the host template id if passed in via a GET variable */ if (!empty($_GET["host_template_id"])) { $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"]; } draw_edit_form(array( "config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, (isset($host) ? $host : array())) )); /* we have to hide this button to make a form change in the main form trigger the correct * submit action */ echo "
"; html_end_box(); ?> Data Query Debug Information", "100%", $colors["header"], "3", "center", ""); print "" . debug_log_return("data_query") . ""; html_end_box(); } if (!empty($host["id"])) { html_start_box("Associated Graph Templates", "100%", $colors["header"], "3", "center", ""); html_header(array("Graph Template Name", "Status"), 2); $selected_graph_templates = db_fetch_assoc("select graph_templates.id, graph_templates.name from (graph_templates,host_graph) where graph_templates.id=host_graph.graph_template_id and host_graph.host_id=" . $_GET["id"] . " order by graph_templates.name"); $available_graph_templates = db_fetch_assoc("SELECT graph_templates.id, graph_templates.name FROM snmp_query_graph RIGHT JOIN graph_templates ON (snmp_query_graph.graph_template_id = graph_templates.id) WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name"); $i = 0; if (sizeof($selected_graph_templates) > 0) { foreach ($selected_graph_templates as $item) { $i++; /* get status information for this graph template */ $is_being_graphed = (sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0) ? true : false; ?> ) Is Being Graphed (Edit)" : "Not Being Graphed");?> Delete Graph Template Association No associated graph templates."; } ?> ">
Add Graph Template:   
Associated Data Queries", "100%", $colors["header"], "3", "center", ""); html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2); $selected_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name, host_snmp_query.reindex_method from (snmp_query,host_snmp_query) where snmp_query.id=host_snmp_query.snmp_query_id and host_snmp_query.host_id=" . $_GET["id"] . " order by snmp_query.name"); $available_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name from snmp_query order by snmp_query.name"); $keeper = array(); foreach ($available_data_queries as $item) { if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] ."))")) > 0) { /* do nothing */ } else { array_push($keeper, $item); } } $available_data_queries = $keeper; $i = 0; if (sizeof($selected_data_queries) > 0) { foreach ($selected_data_queries as $item) { $i++; /* get status information for this data query */ $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"])); $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index")); $status = "success"; ?> ) (">Verbose Query) Success" : "Fail");?> [ Item, Row] Reload Data Query  Delete Data Query Association No associated data queries."; } ?> ">
Add Data Query:  Re-Index Method:   
Devices", "100%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status")); ?> ">
Type:   Status:   Search:  ">  Rows per Page:   
\n"; html_start_box("", "100%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("select COUNT(host.id) from host $sql_where"); $sortby = get_request_var_request("sort_column"); if ($sortby=="hostname") { $sortby = "INET_ATON(hostname)"; } $host_graphs = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as graphs FROM graph_local GROUP BY host_id"), "host_id", "graphs"); $host_data_sources = array_rekey(db_fetch_assoc("SELECT host_id, count(*) as data_sources FROM data_local GROUP BY host_id"), "host_id", "data_sources"); $sql_query = "SELECT * FROM host $sql_where ORDER BY " . $sortby . " " . get_request_var_request("sort_direction") . " LIMIT " . (get_request_var_request("host_rows")*(get_request_var_request("page")-1)) . "," . get_request_var_request("host_rows"); $hosts = db_fetch_assoc($sql_query); /* generate page list */ $url_page_select = get_page_list(get_request_var_request("page"), MAX_DISPLAY_PAGES, get_request_var_request("host_rows"), $total_rows, "host.php?filter=" . get_request_var_request("filter") . "&host_template_id=" . get_request_var_request("host_template_id") . "&host_status=" . get_request_var_request("host_status")); $nav = " \n \n \n
<< "; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= "Previous"; if (get_request_var_request("page") > 1) { $nav .= ""; } $nav .= " Showing Rows " . ((get_request_var_request("host_rows")*(get_request_var_request("page")-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (get_request_var_request("host_rows")*get_request_var_request("page")))) ? $total_rows : (get_request_var_request("host_rows")*get_request_var_request("page"))) . " of $total_rows [$url_page_select] "; if ((get_request_var_request("page") * get_request_var_request("host_rows")) < $total_rows) { $nav .= ""; } $nav .= "Next"; if ((get_request_var_request("page") * get_request_var_request("host_rows")) < $total_rows) { $nav .= ""; } $nav .= " >>
\n"; print $nav; $display_text = array( "description" => array("Description", "ASC"), "id" => array("ID", "ASC"), "nosort1" => array("Graphs", "ASC"), "nosort2" => array("Data Sources", "ASC"), "status" => array("Status", "ASC"), "status_event_count" => array("Event Count", "ASC"), "hostname" => array("Hostname", "ASC"), "cur_time" => array("Current (ms)", "DESC"), "avg_time" => array("Average (ms)", "DESC"), "availability" => array("Availability", "ASC")); html_header_sort_checkbox($display_text, get_request_var_request("sort_column"), get_request_var_request("sort_direction"), false); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { form_alternate_row_color($colors["alternate"], $colors["light"], $i, 'line' . $host["id"]); $i++; form_selectable_cell("" . (strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "\\1", htmlspecialchars($host["description"])) : htmlspecialchars($host["description"])) . "", $host["id"], 250); form_selectable_cell(round(($host["id"]), 2), $host["id"]); form_selectable_cell((isset($host_graphs[$host["id"]]) ? $host_graphs[$host["id"]] : 0), $host["id"]); form_selectable_cell((isset($host_data_sources[$host["id"]]) ? $host_data_sources[$host["id"]] : 0), $host["id"]); form_selectable_cell(get_colored_device_status(($host["disabled"] == "on" ? true : false), $host["status"]), $host["id"]); form_selectable_cell(round(($host["status_event_count"]), 2), $host["id"]); form_selectable_cell((strlen(get_request_var_request("filter")) ? eregi_replace("(" . preg_quote(get_request_var_request("filter")) . ")", "\\1", htmlspecialchars($host["hostname"])) : htmlspecialchars($host["hostname"])), $host["id"]); form_selectable_cell(round(($host["cur_time"]), 2), $host["id"]); form_selectable_cell(round(($host["avg_time"]), 2), $host["id"]); form_selectable_cell(round($host["availability"], 2), $host["id"]); form_checkbox_cell($host["description"], $host["id"]); form_end_row(); } /* put the nav bar on the bottom as well */ print $nav; }else{ print "No Hosts"; } html_end_box(false); /* add a list of tree names to the actions dropdown */ add_tree_names_to_actions_array(); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); print "\n"; } ?>