function host_edit() { $_device_id = get_get_var_number("id"); if (empty($_device_id)) { $header_label = "[new]"; } else { $device = api_device_get($_device_id); /* get a list of each package that is associated with this device */ $packages = api_device_package_list($_device_id); $header_label = "[edit: " . $device["description"] . "]"; } if (!empty($device["id"])) { echo "<div>\n"; echo $device["description"] . " (" . $device["hostname"] . ")<br />\n"; echo _("SNMP Information") . "\n"; if ($device["snmp_community"] == "" && $device["snmpv3_auth_username"] == "") { echo "<span style='color: #ab3f1e; font-weight: bold;'>" . _("SNMP not in use") . "</span>\n"; } else { $snmp_system = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.1.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); if ($snmp_system == "") { echo "<span style='color: #ff0000; font-weight: bold;'>" . _("SNMP error") . "</span>\n"; } else { $snmp_uptime = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.3.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); $snmp_hostname = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.5.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); $snmp_location = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.6.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); $snmp_contact = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.4.0", $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); echo "<strong>System:</strong> {$snmp_system}<br>\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)); echo "<strong>" . _("Uptime:") . "</strong> {$snmp_uptime}"; echo " ({$days} days, {$hours} hours, {$minutes} minutes)<br>\n"; echo "<strong>" . _("Hostname:") . "</strong> {$snmp_hostname}<br>\n"; echo "<strong>" . _("Location:") . "</strong> {$snmp_location}<br>\n"; echo "<strong>" . _("Contact:") . "</strong> {$snmp_contact}<br>\n"; } } ?> </span> </div> <div> <span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php print $host["id"]; ?> "><?php echo _("Create Graphs for this Host"); ?> </a> </div> <br /> <?php } form_start("devices.php", "form_device"); html_start_box("<strong>" . _("Devices") . "</strong> {$header_label}"); _device_field__description("description", isset($device["description"]) ? $device["description"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__hostname("hostname", isset($device["hostname"]) ? $device["hostname"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__host_template_id("host_template_id", isset($device["host_template_id"]) ? $device["host_template_id"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__poller_id("poller_id", isset($device["poller_id"]) ? $device["poller_id"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__disabled("disabled", isset($device["disabled"]) ? $device["disabled"] : "", isset($device["id"]) ? $device["id"] : "0"); echo ui_html_box_heading_make("SNMP Options"); _device_field__snmp_version("snmp_version", isset($device["snmp_version"]) ? $device["snmp_version"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmp_community("snmp_community", isset($device["snmp_community"]) ? $device["snmp_community"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmp_port("snmp_port", isset($device["snmp_port"]) ? $device["snmp_port"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmp_timeout("snmp_timeout", isset($device["snmp_timeout"]) ? $device["snmp_timeout"] : "", isset($device["id"]) ? $device["id"] : "0"); echo ui_html_box_heading_make("SNMPv3 Authentication"); _device_field__snmpv3_auth_username("snmpv3_auth_username", isset($device["snmpv3_auth_username"]) ? $device["snmpv3_auth_username"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_auth_password("snmpv3_auth_password", isset($device["snmpv3_auth_password"]) ? $device["snmpv3_auth_password"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_auth_protocol("snmpv3_auth_protocol", isset($device["snmpv3_auth_protocol"]) ? $device["snmpv3_auth_protocol"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_priv_passphrase("snmpv3_priv_passphrase", isset($device["snmpv3_priv_passphrase"]) ? $device["snmpv3_priv_passphrase"] : "", isset($device["id"]) ? $device["id"] : "0"); _device_field__snmpv3_priv_protocol("snmpv3_priv_protocol", isset($device["snmpv3_priv_protocol"]) ? $device["snmpv3_priv_protocol"] : "", isset($device["id"]) ? $device["id"] : "0"); html_end_box(); if (isset($_GET["display_dq_details"]) && isset($_SESSION["debug_log"]["data_query"])) { html_start_box("<strong>" . _("Data Query Debug Information") . "</strong>"); echo "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>"; html_end_box(); } if (!empty($_device_id)) { html_start_box("<strong>" . _("Assigned Packages") . "</strong>"); html_header(array(_("Package Name")), 2); if (sizeof($packages) > 0) { foreach ($packages as $package) { ?> <tr class="item"> <td style="padding: 4px;"> <?php echo $package["name"]; ?> </td> <td align="right" style="padding: 4px;"> <a href="devices.php?action=remove_package&id=<?php echo $_device_id; ?> &package_id=<?php echo $package["id"]; ?> "><img src="<?php echo html_get_theme_images_path("delete_icon_large.gif"); ?> " alt="<?php echo _("Delete Package Assignment"); ?> " border="0" align="absmiddle"></a> </td> </tr> <?php } } else { ?> <tr class="empty"> <td colspan="2"> No packages have been assigned to this device. </td> </tr> <?php } ?> <tr> <td style="border-top: 1px solid #b5b5b5; padding: 1px;" colspan="2"> <table width="100%" cellpadding="2" cellspacing="0"> <tr> <td> Add package: <?php form_dropdown("assoc_package_id", api_package_list(), "name", "id", "", "", ""); ?> </td> <td align="right"> <input type="image" src="<?php echo html_get_theme_images_path('button_add.gif'); ?> " alt="<?php echo _('Add'); ?> " name="assoc_package_add" align="absmiddle"> </td> </tr> </table> </td> </tr> <?php html_end_box(); } form_hidden_box("id", $_device_id); form_hidden_box("action_post", "device_edit"); form_save_button("devices.php", "save_device"); }
function api_data_query_snmp_execute_field($host_id, $data_query_field_id) { require_once(CACTI_BASE_PATH . "/include/data_query/data_query_constants.php"); require_once(CACTI_BASE_PATH . "/lib/sys/snmp.php"); require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php"); require_once(CACTI_BASE_PATH . "/lib/device/device_info.php"); /* fetch information about the data query field */ $data_query_field = api_data_query_field_get($data_query_field_id); /* fetch information about the associated device */ $device = api_device_get($host_id); debug_log_insert("data_query", "Walking OID '" . $data_query_field["source"] . "'"); /* walk the base snmp oid to get a raw list of values */ $snmp_output = cacti_snmp_walk( $device["hostname"], $device["snmp_community"], $data_query_field["source"], $device["snmp_version"], $device["snmpv3_auth_username"], $device["snmpv3_auth_password"], $device["snmpv3_auth_protocol"], $device["snmpv3_priv_passphrase"], $device["snmpv3_priv_protocol"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); /* make sure some data has been returned */ if (!$snmp_output) { debug_log_insert("data_query", _("No SNMP data returned when walking OID '" . $data_query_field["source"] . "'")); return false; } debug_log_insert("data_query", _("Parsing output using method type '" . $data_query_field["method_type"] . "'")); $values_array = array(); switch ($data_query_field["method_type"]) { /* use the values returned from the snmpwalk without modification */ case DATA_QUERY_FIELD_METHOD_VALUE: foreach ($snmp_output as $row) { $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $row["value"]); } break; /* apply a regular expression to the values returned from the snmpwalk */ case DATA_QUERY_FIELD_METHOD_VALUE_PARSE: foreach ($snmp_output as $row) { /* a match was found; grab the first hit */ if (ereg($data_query_field["method_value"], $row["value"], $matches)) { $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $matches[1]); /* no match was found. use an empty string */ }else{ $values_array{$row["oid"]} = array("value" => "", "value_parsed" => ""); } } break; /* use the last N octets of the oid for each value */ case DATA_QUERY_FIELD_METHOD_OID_OCTET: foreach ($snmp_output as $row) { $octets = explode(".", $row["oid"]); $_new_oid = ""; /* start at the sizeof(array)-Nth item, and move forward */ for ($i=$data_query_field["method_value"]; $i>0; $i--) { $_new_oid .= $octets{sizeof($octets)-$i} . ($i > 1 ? "." : ""); } $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $_new_oid); } break; /* apply a regular expression to the oid's returned from the snmpwalk */ case DATA_QUERY_FIELD_METHOD_OID_PARSE: foreach ($snmp_output as $row) { /* a match was found; grab the first hit */ if (ereg($data_query_field["method_value"], $row["oid"], $matches)) { $values_array{$row["oid"]} = array("value" => $row["value"], "value_parsed" => $matches[1]); /* no match was found. use an empty string */ }else{ $values_array{$row["oid"]} = array("value" => "", "value_parsed" => ""); } } break; } return $values_array; }
function update_reindex_cache($host_id, $data_query_id) { require_once(CACTI_BASE_PATH . "/lib/sys/snmp.php"); require_once(CACTI_BASE_PATH . "/include/data_query/data_query_constants.php"); require_once(CACTI_BASE_PATH . "/lib/device/device_info.php"); require_once(CACTI_BASE_PATH . "/lib/data_query/data_query_info.php"); /* will be used to keep track of sql statements to execute later on */ $recache_stack = array(); /* get information about the host */ $host = api_device_get($host_id); /* get information about the host->data query assignment */ $host_data_query = api_device_data_query_get($host_id, $data_query_id); /* get information about the data query */ $data_query = api_data_query_get($data_query_id); switch ($host_data_query["reindex_method"]) { case DATA_QUERY_AUTOINDEX_NONE: break; case DATA_QUERY_AUTOINDEX_BACKWARDS_UPTIME: /* the uptime backwards method requires snmp, so make sure snmp is actually enabled * on this device first */ if ($host["snmp_community"] != "") { $assert_value = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmpv3_auth_username"], $host["snmpv3_auth_password"], $host["snmpv3_auth_protocol"], $host["snmpv3_priv_passphrase"], $host["snmpv3_priv_protocol"], $host["snmp_port"], $host["snmp_timeout"], SNMP_POLLER); array_push($recache_stack, "insert into poller_reindex (host_id,data_query_id,action,op,assert_value,arg1) values (" . sql_sanitize($host_id) . "," . sql_sanitize($data_query_id) . ",0,'<','" . sql_sanitize($assert_value) . "','.1.3.6.1.2.1.1.3.0')"); } break; case DATA_QUERY_AUTOINDEX_INDEX_NUM_CHANGE: /* this method requires that some command/oid can be used to determine the * current number of indexes in the data query */ $assert_value = api_data_query_cache_num_rows_get($data_query_id, $host_id); if ($data_query_type == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) { if ($data_query["snmp_oid_num_rows"] != "") { array_push($recache_stack, "insert into poller_reindex (host_id,data_query_id,action,op,assert_value,arg1) values (" . sql_sanitize($host_id) . "," . sql_sanitize($data_query_id) . ",0,'=','" . sql_sanitize($assert_value) . "','" . sql_sanitize($data_query["snmp_oid_num_rows"]) . "')"); } }else if ($data_query_type == DATA_QUERY_INPUT_TYPE_SCRIPT_QUERY) { array_push($recache_stack, "insert into poller_reindex (host_id,data_query_id,action,op,assert_value,arg1) values (" . sql_sanitize($host_id) . "," . sql_sanitize($data_query_id) . ",1,'=','" . sql_sanitize($assert_value) . "','" . sql_sanitize(api_data_query_script_path_format($data_query_xml["script_path"]) . DATA_QUERY_SCRIPT_ARG_NUM_INDEXES) . "')"); } break; case DATA_QUERY_AUTOINDEX_FIELD_VERIFICATION: $primary_indexes = api_data_query_cache_field_get($data_query_id, $host_id, $data_query["sort_field"]); if (sizeof($primary_indexes) > 0) { foreach ($primary_indexes as $index) { $assert_value = $index["field_value"]; if ($data_query_type == DATA_QUERY_INPUT_TYPE_SNMP_QUERY) { array_push($recache_stack, "insert into poller_reindex (host_id,data_query_id,action,op,assert_value,arg1) values (" . sql_sanitize($host_id) . "," . sql_sanitize($data_query_id) . ",0,'=','" . sql_sanitize($assert_value) . "','" . sql_sanitize($index["oid"]) . "')"); }else if ($data_query_type == DATA_QUERY_INPUT_TYPE_SCRIPT_QUERY) { array_push($recache_stack, "insert into poller_reindex (host_id,data_query_id,action,op,assert_value,arg1) values (" . sql_sanitize($host_id) . "," . sql_sanitize($data_query_id) . ",1,'=','" . sql_sanitize($assert_value) . "','" . sql_sanitize(api_data_query_script_path_format($data_query_xml["script_path"]) . DATA_QUERY_SCRIPT_ARG_GET . " " . $data_query_xml["fields"]{$data_query["sort_field"]}["query_name"] . " " . $index["snmp_index"]) . "')"); } } } break; } /* save the delete for last since we need to reference this table in the code above */ db_execute("delete from poller_reindex where host_id=$host_id and data_query_id=$data_query_id"); for ($i=0; $i<count($recache_stack); $i++) { db_execute($recache_stack[$i]); } }