"Delete", 2 => "Enable", 3 => "Disable", 4 => "Change SNMP Options", 5 => "Clear Statistics" ); /* 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; } /* -------------------------- The Save Function -------------------------- */ function form_save() { if ((!empty($_POST["add_dq_y"])) && (!empty($_POST["snmp_query_id"]))) { db_execute("replace into host_snmp_query (host_id,snmp_query_id) values (" . $_POST["id"] . "," . $_POST["snmp_query_id"] . ")"); /* 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_y"])) && (!empty($_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_y"]))) { $host_id = api_device_save($_POST["id"], $_POST["host_template_id"], $_POST["description"], $_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"] : "")); if ((is_error_message()) || ($_POST["host_template_id"] != $_POST["_host_template_id"])) { header("Location: host.php?action=edit&id=" . (empty($host_id) ? $_POST["id"] : $host_id)); }else{ header("Location: host.php"); } } } /* ------------------------ 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) { api_data_source_remove($data_source["local_data_id"]); } } $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) { api_graph_remove($graph["local_graph_id"]); } } break; } api_device_remove($selected_items[$i]); } } header("Location: host.php"); exit; } /* setup some variables */ $host_list = ""; $i = 0; /* loop through each of the host templates selected on the previous page and get more info about them */ while (list($var,$val) = each($_POST)) { if (ereg("^chk_([0-9]+)$", $var, $matches)) { $host_list .= "
  • " . db_fetch_cell("select description from host where id=" . $matches[1]) . "
    "; $host_array[$i] = $matches[1]; } $i++; } include_once("./include/top_header.php"); html_start_box("" . $device_actions{$_POST["drp_action"]} . "", "60%", $colors["header_panel"], "3", "center", ""); print "
    \n"; if ($_POST["drp_action"] == "2") { /* Enable Devices */ print "

    To enable the following devices, press the \"yes\" button below.

    $host_list

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

    To disable the following devices, press the \"yes\" button below.

    $host_list

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

    To change SNMP parameters for the following devices, check the box next to the fields you want to update, fill in the new value, and click Save.

    $host_list

    "; $form_array = array(); while (list($field_name, $field_array) = each($fields_host_edit)) { if (ereg("^snmp_", $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 ) ); }elseif ($_POST["drp_action"] == "5") { /* Clear Statisitics for Selected Devices */ print "

    To clear the counters for the following devices, press the \"yes\" button below.

    $host_list

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

    Are you sure you want to delete the following devices?

    $host_list

    "; form_radio_button("delete_type", "2", "1", "Leave all graphs and data sources untouched.", "1"); print "
    "; form_radio_button("delete_type", "2", "2", "Delete all associated graphs and data sources.", "1"); print "
    "; print " \n "; } if (!isset($host_array)) { print "You must select at least one device.\n"; $save_html = ""; }else{ $save_html = ""; } print " Cancel $save_html "; html_end_box(); include_once("./include/bottom_footer.php"); } /* ------------------- Data Query Functions ------------------- */ function host_reload_query() { run_data_query($_GET["host_id"], $_GET["id"]); } function host_remove_query() { api_device_dq_remove($_GET["host_id"], $_GET["id"]); } function host_remove_gt() { api_device_gt_remove($_GET["host_id"], $_GET["id"]); } /* --------------------- Host Functions --------------------- */ function host_remove() { global $config; if ((read_config_option("remove_verification") == "on") && (!isset($_GET["confirm"]))) { include("./include/top_header.php"); form_confirm("Are You Sure?", "Are you sure you want to delete the host '" . db_fetch_cell("select description from host where id=" . $_GET["id"]) . "'?", "host.php", "host.php?action=remove&id=" . $_GET["id"]); include("./include/bottom_footer.php"); exit; } if ((read_config_option("remove_verification") == "") || (isset($_GET["confirm"]))) { api_device_remove($_GET["id"]); } } function host_edit() { global $colors, $fields_host_edit; display_output_messages(); if (!empty($_GET["id"])) { $host = db_fetch_row("select * from host where id=" . $_GET["id"]); $header_label = "[edit: " . $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_port"], $host["snmp_timeout"]); 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_port"], $host["snmp_timeout"]); $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_port"], $host["snmp_timeout"]); print "System: $snmp_system
    \n"; print "Uptime: $snmp_uptime
    \n"; print "Hostname: $snmp_hostname
    \n"; } } ?>
    *">Create Graphs for this Host

    Devices $header_label", "98%", $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())) )); html_end_box(); if ((isset($_GET["display_dq_details"])) && (isset($_SESSION["debug_log"]["data_query"]))) { html_start_box("Data Query Debug Information", "98%", $colors["header"], "3", "center", ""); print "" . debug_log_return("data_query") . ""; html_end_box(); } if (!empty($host["id"])) { html_start_box("Associated Data Queries", "98%", $colors["header"], "3", "center", ""); html_header(array("Data Query Name", "Debugging", "Status"), 2); $selected_data_queries = db_fetch_assoc("select snmp_query.id, snmp_query.name 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"); $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"; ?> ) (&host_id=">Verbose Query) Success" : "Fail");?> [ Item, Row] Reload Data Query  Delete Data Query Association No associated data queries."; } ?> ">
    Add Data Query:   
    Associated Graph Templates", "98%", $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"); $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:   
    Devices", "98%", $colors["header"], "3", "center", "host.php?action=edit&host_template_id=" . $_REQUEST["host_template_id"]); include("./include/html/inc_device_filter_table.php"); html_end_box(); /* form the 'where' clause for our main sql query */ $sql_where = "where host.description like '%%" . $_REQUEST["filter"] . "%%'"; if ($_REQUEST["host_template_id"] == "-1") { /* Show all items */ }elseif ($_REQUEST["host_template_id"] == "0") { $sql_where .= " and host.host_template_id=0"; }elseif (!empty($_REQUEST["host_template_id"])) { $sql_where .= " and host.host_template_id=" . $_REQUEST["host_template_id"]; } html_start_box("", "98%", $colors["header"], "3", "center", ""); $total_rows = db_fetch_cell("select COUNT(host.id) from host $sql_where"); $hosts = db_fetch_assoc("select host.id, host.disabled, host.status, host.hostname, host.description, host.min_time, host.max_time, host.cur_time, host.avg_time, host.availability from host $sql_where order by host.description limit " . (read_config_option("num_rows_device")*($_REQUEST["page"]-1)) . "," . read_config_option("num_rows_device")); /* sometimes its a pain to browse throug a long list page by page... so make a list of each page #, so the user can jump straight to it */ $page_number = 0; $url_page_select = ""; for ($i=0; ($i<$total_rows); $i += read_config_option("num_rows_device")) { $page_number++; if ($_REQUEST["page"] == $page_number) { $url_page_select .= "$page_number"; }else{ $url_page_select .= "$page_number"; } if (($i+read_config_option("num_rows_device")) < $total_rows) { $url_page_select .= ","; } } $nav = " \n \n \n
    << "; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= "Previous"; if ($_REQUEST["page"] > 1) { $nav .= ""; } $nav .= " Showing Rows " . ((read_config_option("num_rows_device")*($_REQUEST["page"]-1))+1) . " to " . ((($total_rows < read_config_option("num_rows_device")) || ($total_rows < (read_config_option("num_rows_device")*$_REQUEST["page"]))) ? $total_rows : (read_config_option("num_rows_device")*$_REQUEST["page"])) . " of $total_rows [$url_page_select] "; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= "Next"; if (($_REQUEST["page"] * read_config_option("num_rows_device")) < $total_rows) { $nav .= ""; } $nav .= " >>
    \n"; print $nav; html_header_checkbox(array("Description", "Status", "Hostname", "Min (ms)", "Max (ms)", "Current (ms)", "Average (ms)", "Availability")); $i = 0; if (sizeof($hosts) > 0) { foreach ($hosts as $host) { form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++; ?> ">\\1", $host["description"]);?> % "> No Hosts"; } html_end_box(false); /* draw the dropdown containing a list of available actions for this form */ draw_actions_dropdown($device_actions); } ?>