function ss_host_disk($hostname, $host_id, $snmp_auth, $cmd, $arg1 = "", $arg2 = "") { $snmp = explode(":", $snmp_auth); $snmp_version = $snmp[0]; $snmp_port = $snmp[1]; $snmp_timeout = $snmp[2]; $ping_retries = $snmp[3]; $max_oids = $snmp[4]; $snmp_auth_username = ""; $snmp_auth_password = ""; $snmp_auth_protocol = ""; $snmp_priv_passphrase = ""; $snmp_priv_protocol = ""; $snmp_context = ""; $snmp_community = ""; if ($snmp_version == 3) { $snmp_auth_username = $snmp[6]; $snmp_auth_password = $snmp[7]; $snmp_auth_protocol = $snmp[8]; $snmp_priv_passphrase = $snmp[9]; $snmp_priv_protocol = $snmp[10]; $snmp_context = $snmp[11]; } else { $snmp_community = $snmp[5]; } $oids = array("total" => ".1.3.6.1.2.1.25.2.3.1.5", "used" => ".1.3.6.1.2.1.25.2.3.1.6", "failures" => ".1.3.6.1.2.1.25.2.3.1.7", "index" => ".1.3.6.1.2.1.25.2.3.1.1", "description" => ".1.3.6.1.2.1.25.2.3.1.3", "sau" => ".1.3.6.1.2.1.25.2.3.1.4"); if ($cmd == "index") { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i = 0; $i < sizeof($return_arr); $i++) { print $return_arr[$i] . "\n"; } } elseif ($cmd == "num_indexes") { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); print sizeof($return_arr); } elseif ($cmd == "query") { $arg = $arg1; $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i = 0; $i < sizeof($arr_index); $i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } } elseif ($cmd == "get") { $arg = $arg1; $index = $arg2; if ($arg == "total" || $arg == "used") { $sau = preg_replace("/[^0-9]/i", "", db_fetch_cell("select field_value from host_snmp_cache where host_id={$host_id} and field_name='hrStorageAllocationUnits' and snmp_index='{$index}'")); $snmp_data = cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); if ($snmp_data < 0) { return ($snmp_data + 4294967296) * $sau; } else { return $snmp_data * $sau; } } else { return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); } } }
function ss_host_disk($hostname, $host_id, $snmp_auth, $cmd, $arg1 = "", $arg2 = "") { $snmp = explode(":", $snmp_auth); $snmp_version = $snmp[0]; $snmp_port = $snmp[1]; $snmp_timeout = $snmp[2]; $snmp_auth_username = ""; $snmp_auth_password = ""; $snmp_auth_protocol = ""; $snmp_priv_passphrase = ""; $snmp_priv_protocol = ""; $snmp_context = ""; $snmp_community = ""; if ($snmp_version == 3) { $snmp_auth_username = $snmp[4]; $snmp_auth_password = $snmp[5]; $snmp_auth_protocol = $snmp[6]; $snmp_priv_passphrase = $snmp[7]; $snmp_priv_protocol = $snmp[8]; $snmp_context = $snmp[9]; } else { $snmp_community = $snmp[3]; } $oids = array("total" => ".1.3.6.1.2.1.25.2.3.1.5", "totalin" => ".1.3.6.1.2.1.25.2.3.1.5", "used" => ".1.3.6.1.2.1.25.2.3.1.6", "failures" => ".1.3.6.1.2.1.25.2.3.1.7", "index" => ".1.3.6.1.2.1.25.2.3.1.1", "description" => ".1.3.6.1.2.1.25.2.3.1.3", "sau" => ".1.3.6.1.2.1.25.2.3.1.4"); if ($cmd == "index") { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); for ($i = 0; $i < sizeof($return_arr); $i++) { print $return_arr[$i] . "\n"; } } elseif ($cmd == "query") { $arg = $arg1; $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); for ($i = 0; $i < sizeof($arr_index); $i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } } elseif ($cmd == "get") { $arg = $arg1; $index = $arg2; $value = api_plugin_hook_function('hmib_get_disk', array("host_id" => $host_id, "arg" => $arg, "index" => $index)); if (is_array($value)) { if ($arg == "total" || $arg == "used") { $sau = eregi_replace("[^0-9]", "", db_fetch_cell("select field_value from host_snmp_cache where host_id={$host_id} and field_name='hrStorageAllocationUnits' and snmp_index='{$index}'")); return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER) * $sau; } else { return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER); } } else { return $value; } } }
function ss_host_cpu_get_indexes($hostname, $snmp_community, $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, $snmp_port, $snmp_timeout) { $arr = ss_host_cpu_reindex(cacti_snmp_walk($hostname, $snmp_community, ".1.3.6.1.2.1.25.3.3.1", $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmp_port, $snmp_timeout, read_config_option("snmp_retries"), SNMP_POLLER)); $return_arr = array(); $j = 0; for ($i = 0; $i < sizeof($arr); $i++) { if (is_numeric($arr[$i])) { $return_arr[$j] = $j; $j++; } } return $return_arr; }
function get_indexes($hostname, $snmp_community, $snmp_version) { $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, ".1.3.6.1.2.1.25.3.3.1", $snmp_version, "", "", 161, 1000)); $return_arr = array(); $j = 0; for ($i = 0; $i < sizeof($arr); $i++) { if (ereg("^[0-9]+\$", $arr[$i])) { $return_arr[$j] = $j; $j++; } } return $return_arr; }
function get_indexes($hostname, $snmp_community, $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids) { $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, ".1.3.6.1.2.1.25.3.3.1", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); $return_arr = array(); $j = 0; for ($i = 0; $i < sizeof($arr); $i++) { if (ereg("^[0-9]+\$", $arr[$i])) { $return_arr[$j] = $j; $j++; } } return $return_arr; }
function ss_count_oids($hostid = '', $oid = '') { global $config; include_once $config['base_path'] . '/lib/snmp.php'; if ($hostid > 0) { $host = db_fetch_row("SELECT hostname, snmp_community, snmp_version, snmp_username, snmp_password, \n\t\t\tsnmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, \n\t\t\tsnmp_port, snmp_timeout, max_oids \n\t\t\tFROM host \n\t\t\tWHERE id={$hostid}"); if (sizeof($host)) { $walk = cacti_snmp_walk($host['hostname'], $host['snmp_community'], $oid, $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'), $host['max_oids'], SNMP_WEBUI); if (sizeof($walk)) { return sizeof($walk); } } } return '0'; }
function ss_host_cpu_get_indexes($hostname, $snmp_community, $snmp_version, $snmp_port, $snmp_timeout) { $arr = ss_host_cpu_reindex(cacti_snmp_walk($hostname, $snmp_community, ".1.3.6.1.2.1.25.3.3.1", $snmp_version, "", "", $snmp_port, $snmp_timeout, SNMP_POLLER)); $return_arr = array(); $j = 0; for ($i=0;($i<sizeof($arr));$i++) { if (ereg("^[0-9]+$", $arr[$i])) { $return_arr[$j] = $j; $j++; } } return $return_arr; }
function get_indexes($hostname, $snmp_community, $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol) { $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, ".1.3.6.1.2.1.25.3.3.1", $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, 161, 1000)); $return_arr = array(); $j = 0; for ($i=0;($i<sizeof($arr));$i++) { if (is_numeric($arr[$i])) { $return_arr[$j] = $j; $j++; } } return $return_arr; }
function ss_host_disk($hostname, $snmp_community, $snmp_version, $host_id, $cmd, $arg1 = "", $arg2 = "", $snmp_port = 161, $snmp_timeout = 500) { $oids = array( "total" => ".1.3.6.1.2.1.25.2.3.1.5", "used" => ".1.3.6.1.2.1.25.2.3.1.6", "failures" => ".1.3.6.1.2.1.25.2.3.1.7", "index" => ".1.3.6.1.2.1.25.2.3.1.1", "description" => ".1.3.6.1.2.1.25.2.3.1.3", "sau" => ".1.3.6.1.2.1.25.2.3.1.4" ); if ((func_num_args() == "9") || (func_num_args() == "7") || (func_num_args() == "6") || (func_num_args() == "5")) { if ($cmd == "index") { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, "", "", $snmp_port, $snmp_timeout, SNMP_POLLER)); for ($i=0;($i<sizeof($return_arr));$i++) { print $return_arr[$i] . "\n"; } }elseif ($cmd == "query") { $arg = $arg1; $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, "", "", $snmp_port, $snmp_timeout, SNMP_POLLER)); $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, "", "", $snmp_port, $snmp_timeout, SNMP_POLLER)); for ($i=0;($i<sizeof($arr_index));$i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } }elseif ($cmd == "get") { $arg = $arg1; $index = $arg2; if (($arg == "total") || ($arg == "used")) { /* get hrStorageAllocationUnits from the snmp cache since it is faster */ $sau = eregi_replace("[^0-9]", "", db_fetch_cell("select field_value from host_snmp_cache where host_id=$host_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'")); return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, "", "", $snmp_port, $snmp_timeout, SNMP_POLLER) * $sau; }else{ return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, "", "", $snmp_port, $snmp_timeout, SNMP_POLLER); } } } else { return "ERROR: Invalid Parameters\n"; } }
/** * execute an SNMP query for a given device * @param int $device_id * @param int $snmp_query_id */ function query_snmp_device($device_id, $snmp_query_id) { global $config; include_once(CACTI_BASE_PATH . "/lib/snmp.php"); $device = db_fetch_row("SELECT hostname, snmp_community, snmp_version, snmp_username, snmp_password, snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, snmp_port, snmp_timeout, ping_retries, max_oids FROM device WHERE id='$device_id'"); $snmp_queries = get_data_query_array($snmp_query_id); if ($device["hostname"] == "") { debug_log_insert("data_query", __("Invalid device_id:") . " $device_id"); return false; } /* invalid xml check */ if ((!is_array($snmp_queries)) || (sizeof($snmp_queries) == 0)) { debug_log_insert("data_query", __("Error parsing XML file into an array.")); return false; } debug_log_insert("data_query", __("XML file parsed ok.")); /* fetch specified index at specified OID */ $snmp_indexes = cacti_snmp_walk($device["hostname"], $device["snmp_community"], $snmp_queries["oid_index"], $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["ping_retries"], $device["max_oids"], SNMP_WEBUI); debug_log_insert("data_query", __("Executing SNMP walk for list of indexes @ '%s'", $snmp_queries["oid_index"])); /* no data found; get out */ if (!$snmp_indexes) { debug_log_insert("data_query", __("No SNMP data returned")); return false; } else { /* show list of indices found */ for ($i=0; $i<sizeof($snmp_indexes); $i++) { debug_log_insert("data_query", __("Index found at OID: '%s' value: '%s'", $snmp_indexes[$i]["oid"], $snmp_indexes[$i]["value"])); } } /* the last octet of the oid is the index by default */ $index_parse_regexp = '/.*\.([0-9]+)$/'; /* parse the index if required */ if (isset($snmp_queries["oid_index_parse"])) { $index_parse_regexp = str_replace("OID/REGEXP:", "", $snmp_queries["oid_index_parse"]); for ($i=0; $i<sizeof($snmp_indexes); $i++) { $snmp_indexes[$i]["value"] = preg_replace($index_parse_regexp, "\\1", $snmp_indexes[$i]["oid"]); debug_log_insert("data_query", __("index_parse at OID: '%s' results: '%s'", $snmp_indexes[$i]["oid"], $snmp_indexes[$i]["value"])); } } /* set an array to host all updates */ $output_array = array(); $fields_processed = array(); rewrite_snmp_enum_value(NULL); while (list($field_name, $field_array) = each($snmp_queries["fields"])) { if ($field_array["direction"] == "input" && $field_array["method"] != "get" && (isset($field_array["rewrite_index"]) || isset($field_array["oid_suffix"]) )){ #$field_array["method"] = "get"; # do NOT change method, only create error message debug_log_insert("data_query", __("FIXME: wrong 'method' defined for '%s' while using 'rewrite_index' or 'oid_suffix'. Please change XML to use 'get' instead.", $field_name)); } $values = array(); if ((!isset($field_array["oid"])) && ($field_array["source"] == "index")) { for ($i=0; $i<sizeof($snmp_indexes); $i++) { debug_log_insert("data_query", __("Inserting index data for field '%s' [value='%s']", $field_name, $snmp_indexes[$i]["value"])); $values[] = array( "value" => $snmp_indexes[$i]["value"], "index" => $snmp_indexes[$i]["value"], "oid" => $oid); } }elseif (($field_array["method"] == "get") && ($field_array["direction"] == "input")) { debug_log_insert("data_query", __("Located input field '%s' [get]", $field_name)); $rewritten_indexes = array(); if (isset($field_array["rewrite_index"])) { $rewritten_indexes = data_query_rewrite_indexes($errmsg, $device_id, $snmp_query_id, $field_array["rewrite_index"], $snmp_indexes, $fields_processed); if(sizeof($errmsg)){ foreach($errmsg as $message){ debug_log_insert("data_query", "Field '$field_name'" . $message); } } } for ($i=0; $i<sizeof($snmp_indexes); $i++) { $oid = $field_array["oid"]; if (isset($field_array["rewrite_index"])) { if (isset($rewritten_indexes[$snmp_indexes[$i]["value"]])) { $oid_suffix = $rewritten_indexes[$snmp_indexes[$i]["value"]]; }else{ // we failed to build rewritten index. warnings are sent already, just skip this index silently continue; } $oid .= "." . $oid_suffix; } else { $oid .= "." . $snmp_indexes[$i]["value"]; } $oid .= isset($field_array["oid_suffix"]) ? ("." . $field_array["oid_suffix"]) : ""; $value = NULL; if (substr($field_array["source"], 0, 13) == "VALUE/REGEXP:" || $field_array["source"] == "value") { $value = cacti_snmp_get($device["hostname"], $device["snmp_community"], $oid, $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], SNMP_WEBUI); if (substr($field_array["source"], 0, 13) == "VALUE/REGEXP:") { $value = preg_replace("/" . str_replace("VALUE/REGEXP:", "", $field_array["source"]) . "/", "\\1", $value); } } else if(substr($field_array["source"], 0, 11) == "OID/REGEXP:") { $value = preg_replace("/" . str_replace("OID/REGEXP:", "", $field_array["source"]) . "/", "\\1", $oid); } debug_log_insert("data_query", __("Executing SNMP get for data") . " @ '$oid' [value='$value']"); $values[] = array( "value" => $value, "index" => $snmp_indexes[$i]["value"], "oid" => $oid); } } elseif (($field_array["method"] == "walk") && ($field_array["direction"] == "input")) { debug_log_insert("data_query", __("Located input field '%s' [walk]", $field_name)); $snmp_data = array(); $snmp_data = cacti_snmp_walk($device["hostname"], $device["snmp_community"], $field_array["oid"], $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["ping_retries"], $device["max_oids"], SNMP_WEBUI); debug_log_insert("data_query", __("Executing SNMP walk for data @ '%s'", $field_array["oid"])); if ($field_array["source"] == "value") { for ($i=0; $i<sizeof($snmp_data); $i++) { # Is this preg_replace functional? - JPP $snmp_index = preg_replace(isset($field_array["oid_index_parse"]) ? $field_array["oid_index_parse"] : $index_parse_regexp, "\\1", $snmp_data[$i]["oid"]); $oid = $field_array["oid"] . ".$snmp_index"; # deprecated in favour of "<rewrite_value>", bug#0001225 #if ($field_name == "ifOperStatus") { # if ((substr_count(strtolower($snmp_data[$i]["value"]), "down")) || # ($snmp_data[$i]["value"] == "2")) { # $snmp_data[$i]["value"] = __("Down"); # }else if ((substr_count(strtolower($snmp_data[$i]["value"]), "up")) || # ($snmp_data[$i]["value"] == "1")) { # $snmp_data[$i]["value"] = __("Up"); # }else if ((substr_count(strtolower($snmp_data[$i]["value"]), "notpresent")) || # ($snmp_data[$i]["value"] == "6")) { # $snmp_data[$i]["value"] = __("notPresent"); # }else{ # $snmp_data[$i]["value"] = __("Testing"); # } #} debug_log_insert("data_query", __("Found item [$field_name='%s'] index: %s [from value]", $snmp_data[$i]["value"], $snmp_index)); $values[] = array( "value" => $snmp_data[$i]["value"], "index" => $snmp_index, "oid" => $oid); } } elseif (substr($field_array["source"], 0, 11) == "OID/REGEXP:") { for ($i=0; $i<sizeof($snmp_data); $i++) { $value = preg_replace("/" . str_replace("OID/REGEXP:", "", $field_array["source"]) . "/", "\\1", $snmp_data[$i]["oid"]); if (isset($snmp_queries["oid_index_parse"])) { $snmp_index = preg_replace("/" . $index_parse_regexp . "/", "\\1", $snmp_data[$i]["oid"]); }else if ((isset($snmp_data[$i]["value"])) && ($snmp_data[$i]["value"] != "")) { $snmp_index = $snmp_data[$i]["value"]; } $oid = $field_array["oid"] . "." . $value; debug_log_insert("data_query", __("Found item [%s='%s'] index: %s [from regexp oid parse]", $field_name, $value, $snmp_index)); $values[] = array( "value" => $value, "index" => $snmp_index, "oid" => $oid); } }elseif (substr($field_array["source"], 0, 13) == "VALUE/REGEXP:") { for ($i=0; $i<sizeof($snmp_data); $i++) { $value = preg_replace("/" . str_replace("VALUE/REGEXP:", "", $field_array["source"]) . "/", "\\1", $snmp_data[$i]["value"]); $snmp_index = preg_replace("/" . $index_parse_regexp . "/", "\\1", $snmp_data[$i]["oid"]); $oid = $field_array["oid"] . "." . $value; debug_log_insert("data_query", __("Found item [%s='%s'] index: %s [from regexp value parse]", $field_name, $value, $snmp_index)); $values[] = array( "value" => $value, "index" => $snmp_index, "oid" => $oid); } } } if (sizeof($values)) { foreach($values as $item){ if(isset($field_array["rewrite_value"])) { $item["value"] = rewrite_snmp_enum_value($field_name, $item["value"], $field_array["rewrite_value"]); } $output_array[] = data_query_format_record($device_id, $snmp_query_id, $field_name, $item["value"], $item["index"], $item["oid"]); } $fields_processed[] = $field_name; } } if (sizeof($output_array)) { data_query_update_device_cache_from_buffer($device_id, $snmp_query_id, $output_array); } return true; }
if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM) { cacti_log("Device[{$host_id}] RECACHE DQ[" . $index_item['data_query_id'] . '] Script Server: ' . $index_item['arg1'] . ", output: {$output}", $print_data_to_stdout); } } else { if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM) { cacti_log("Device[{$host_id}] DS[{$data_source}] *SKIPPING* Script Server: " . $item['arg1'] . ' (PHP < 4.3)', $print_data_to_stdout); } $output = 'U'; } break; case POLLER_ACTION_SNMP_COUNT: /* snmp; count items */ if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_DEBUG) { cacti_log("Device[{$host_id}] RECACHE DQ[" . $index_item['data_query_id'] . '] OID Count: ' . $index_item['arg1'], $print_data_to_stdout); } $output = sizeof(cacti_snmp_walk($item['hostname'], $item['snmp_community'], $index_item['arg1'], $item['snmp_version'], $item['snmp_username'], $item['snmp_password'], $item['snmp_auth_protocol'], $item['snmp_priv_passphrase'], $item['snmp_priv_protocol'], $item['snmp_context'], $item['snmp_port'], $item['snmp_timeout'], read_config_option('snmp_retries'), SNMP_CMDPHP)); if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM) { cacti_log("Device[{$host_id}] RECACHE DQ[" . $index_item['data_query_id'] . '] OID Count: ' . $index_item['arg1'] . ', output: ' . $output, $print_data_to_stdout); } break; case POLLER_ACTION_SCRIPT_COUNT: /* script (popen); count items */ if (read_config_option('log_verbosity') >= POLLER_VERBOSITY_DEBUG) { cacti_log("Device[{$host_id}] RECACHE DQ[" . $index_item['data_query_id'] . '] Script Count: ' . $index_item['arg1'], $print_data_to_stdout); } /* count items found */ $script_index_array = exec_into_array($index_item['arg1']); $output = sizeof($script_index_array); if (!validate_result($output)) { if (strlen($output) > 20) { $strout = 20;
function collectHostIndexedOid(&$host, $tree, $table, $name, $preserve = false, $depth = 1) { static $types; debug("Beginning Processing for '" . $host['description'] . '[' . $host['hostname'] . "]', Table '{$name}'"); if (sizeof($host)) { /* mark for deletion */ if ($name == 'users') { db_execute("UPDATE {$table} SET present=0 WHERE host_id=" . $host['id'] . ' AND userType=0'); } else { db_execute("UPDATE {$table} SET present=0 WHERE host_id=" . $host['id']); } debug("Polling {$name} from '" . $host['description'] . '[' . $host['hostname'] . "]'"); $treeMib = array(); $goodVals = array(); foreach ($tree as $mname => $oid) { if ($name == 'processor') { $retrieval = SNMP_VALUE_PLAIN; } elseif ($mname == 'mac') { $retrieval = SNMP_VALUE_LIBRARY; } elseif ($mname == 'apBSSID') { $retrieval = SNMP_VALUE_LIBRARY; } elseif ($mname == 'date') { $retrieval = SNMP_VALUE_LIBRARY; } elseif ($mname != 'baseOID') { $retrieval = SNMP_VALUE_PLAIN; } else { continue; } $walk = cacti_snmp_walk($host['hostname'], $host['snmp_community'], $oid, $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'), $host['max_oids'], $retrieval, SNMP_WEBUI); if (sizeof($walk)) { $goodVals[$mname] = true; } else { $goodVals[$mname] = false; } if (($mname == 'index' || $mname == 'name' || $mname == 'apSSID' || $mname == 'Strength') && !sizeof($walk)) { debug('No Index Information for OID: ' . $oid . ' on ' . $host['description'] . ' returning'); return; } if ($goodVals[$mname]) { $treeMib = array_merge($treeMib, $walk); } debug('Polled: ' . $host['description'] . ', OID: ' . $oid . ', Size: ' . sizeof($walk)); } $set_string = ''; $values = ''; $sql_suffix = ''; $sql_prefix = "INSERT INTO {$table}"; if (sizeof($tree)) { foreach ($tree as $mname => $oid) { if ($mname != 'baseOID' && $mname != 'index') { if ($goodVals[$mname] == true) { $values .= (strlen($values) ? '`, `' : '`') . $mname; $sql_suffix .= (!strlen($sql_suffix) ? ' ON DUPLICATE KEY UPDATE `index`=VALUES(`index`), `' : ', `') . $mname . '`=VALUES(`' . $mname . '`)'; } } } } $sql_prefix .= ' (`host_id`, `index`, ' . ($preserve ? '`last_seen`, ' : '') . $values . '`) VALUES '; $sql_suffix .= ', present=1' . ($preserve ? ', last_seen=NOW()' : ''); // Locate the values names $prevIndex = ''; $new_array = array(); if (sizeof($treeMib)) { foreach ($treeMib as $mib) { /* do some cleanup */ if (substr($mib['oid'], 0, 1) != '.') { $mib['oid'] = '.' . $mib['oid']; } if (substr($mib['value'], 0, 4) == 'OID:') { $mib['value'] = trim(str_replace('OID:', '', $mib['value'])); } $splitIndex = mikrotik_splitBaseIndex($mib['oid'], $depth); if (sizeof($splitIndex)) { if ($name == 'wireless_registrations') { $parts = explode('.', $splitIndex[1]); $index = ''; for ($i = 0; $i < 6; $i++) { $index .= ($i > 0 ? ':' : '') . strtoupper(substr('0' . dechex($parts[$i]), -2)); } } else { $index = $splitIndex[1]; } $oid = $splitIndex[0]; $key = array_search($oid, $tree); if (!empty($key) && $goodVals[$key] == true) { if ($key == 'type') { if ($mib['value'] == '.1.3.6.1.2.1.25.2.1.1') { $new_array[$index][$key] = 11; } elseif ($mib['value'] == '.1.3.6.1.2.1.25.2.1.4') { $new_array[$index][$key] = 14; } } elseif ($key == 'name') { $new_array[$index][$key] = str_replace('<', '', str_replace('>', '', strtoupper($mib['value']))); } elseif ($key == 'date') { $new_array[$index][$key] = mikrotik_dateParse($mib['value']); } elseif ($key == 'mac') { $new_array[$index][$key] = mikrotik_macParse($mib['value']); } elseif ($key != 'index') { $new_array[$index][$key] = $mib['value']; } if (!empty($key) && $key != 'index') { debug("Key:'" . $key . "', Orig:'" . $mib['oid'] . "', Val:'" . (isset($new_array[$index]) ? $new_array[$index][$key] : '(Index not defined)') . "', Index:'" . $index . "', Base:'" . $oid . "'"); } } } else { echo "WARNING: Error parsing OID value\n"; } } } /* dump the output to the database */ $sql_insert = ''; $count = 0; if (sizeof($new_array)) { foreach ($new_array as $index => $item) { $sql_insert .= (strlen($sql_insert) ? '), (' : '(') . $host['id'] . ", '" . $index . "', " . ($preserve ? 'NOW(), ' : ''); $i = 0; foreach ($tree as $mname => $oid) { if ($mname != 'baseOID' && $mname != 'index') { if ($goodVals[$mname] == true) { $sql_insert .= ($i > 0 ? ', ' : '') . (isset($item[$mname]) && strlen(strlen($item[$mname])) ? db_qstr($item[$mname]) : "''"); $i++; } } } } $sql_insert .= ')'; $count++; if ($count % 200 == 0) { db_execute($sql_prefix . $sql_insert . $sql_suffix); $sql_insert = ''; } } //print $sql_prefix . $sql_insert . $sql_suffix . "\n"; if (strlen($sql_insert)) { db_execute($sql_prefix . $sql_insert . $sql_suffix); } } }
function ss_host_disk($hostname, $host_id, $snmp_auth, $cmd, $arg1 = "", $arg2 = "") { $snmp = explode(":", $snmp_auth); $snmp_version = $snmp[0]; $snmp_port = $snmp[1]; $snmp_timeout = $snmp[2]; $snmpv3_auth_username = ""; $snmpv3_auth_password = ""; $snmpv3_auth_protocol = ""; $snmpv3_priv_passphrase = ""; $snmpv3_priv_protocol = ""; $snmp_community = ""; if ($snmp_version == 3) { $snmpv3_auth_username = $snmp[4]; $snmpv3_auth_password = $snmp[5]; $snmpv3_auth_protocol = $snmp[6]; $snmpv3_priv_passphrase = $snmp[7]; $snmpv3_priv_protocol = $snmp[8]; }else{ $snmp_community = $snmp[3]; } $oids = array( "total" => ".1.3.6.1.2.1.25.2.3.1.5", "used" => ".1.3.6.1.2.1.25.2.3.1.6", "failures" => ".1.3.6.1.2.1.25.2.3.1.7", "index" => ".1.3.6.1.2.1.25.2.3.1.1", "description" => ".1.3.6.1.2.1.25.2.3.1.3", "sau" => ".1.3.6.1.2.1.25.2.3.1.4" ); if ($cmd == "index") { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmp_port, $snmp_timeout, SNMP_POLLER)); for ($i=0;($i<sizeof($return_arr));$i++) { print $return_arr[$i] . "\n"; } }elseif ($cmd == "query") { $arg = $arg1; $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmp_port, $snmp_timeout, SNMP_POLLER)); $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmp_port, $snmp_timeout, SNMP_POLLER)); for ($i=0;($i<sizeof($arr_index));$i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } }elseif ($cmd == "get") { $arg = $arg1; $index = $arg2; if (($arg == "total") || ($arg == "used")) { /* get hrStorageAllocationUnits from the snmp cache since it is faster */ $sau = eregi_replace("[^0-9]", "", db_fetch_cell("select field_value from host_snmp_cache where host_id=$host_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'")); return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmp_port, $snmp_timeout, SNMP_POLLER) * $sau; }else{ return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmp_port, $snmp_timeout, SNMP_POLLER); } } }
if (file_exists(dirname(__FILE__) . "/../include/global.php")) { include(dirname(__FILE__) . "/../include/global.php"); } include(dirname(__FILE__) . "/../include/config.php"); include(dirname(__FILE__) . "/../lib/snmp.php"); $hostname = $_SERVER["argv"][1]; $snmp_community = $_SERVER["argv"][2]; $snmp_version = $_SERVER["argv"][3]; $bsnMobileProtocol = ".1.3.6.1.4.1.14179.2.1.4.1.25"; $stationprotocol = reindex(cacti_snmp_walk($hostname, $snmp_community, $bsnMobileProtocol, $snmp_version, "", "", 161, 1000)); $findStationProtocolType= array_count_values($stationprotocol); $stationdot11a=0; $stationdot11b=0; $stationdot11g=0; $stationunknownprotocol=0; $stationmobile=0; if (array_key_exists('1', $findStationProtocolType)) { $stationdot11a=$findStationProtocolType[1]; } if (array_key_exists('2', $findStationProtocolType)) { $stationdot11b=$findStationProtocolType[2];
$hostname = $_SERVER["argv"][1]; $snmp_community = $_SERVER["argv"][2]; $snmp_version = $_SERVER["argv"][3]; $cmd = $_SERVER["argv"][4]; if ($cmd == "index") { $return_arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, "", "", "", 161, 1000)); for ($i=0;($i<sizeof($return_arr));$i++) { print $return_arr[$i] . "\n"; } }elseif ($cmd == "query") { $arg = $_SERVER["argv"][5]; $arr_index = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, "", "", "", 161, 1000)); $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, "", "", "", 161, 1000)); for ($i=0;($i<sizeof($arr_index));$i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } }elseif ($cmd == "get") { $arg = $_SERVER["argv"][5]; $index = $_SERVER["argv"][6]; if (($arg == "total") || ($arg == "used")) { /* get hrStorageAllocationUnits from the snmp cache since it is faster */ $host_id = db_fetch_cell("select id from host where hostname='$hostname' and snmp_community='$snmp_community'"); $sau = db_fetch_cell("select field_value from host_snmp_cache where host_id=$host_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'"); print (cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, "", "", "", 161, 1000) * $sau); }else{
function xform_enterasys_N7_vlan_associations(&$device, $snmp_readstring = "") { /* get raw index data */ if ($snmp_readstring == "") { $snmp_readstring = $device["snmp_readstring"]; } /* initialize the output array */ $output_array = array(); /* obtain vlan associations: dot1qTpFdbStatus from dot1qTpFdbTable */ $xformArray = cacti_snmp_walk($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.7.1.2.2.1.2", $device["snmp_version"], "", "", "", "", "", "", $device["snmp_port"], $device["snmp_timeout"]); $i = 0; foreach ($xformArray as $xformItem) { //print_r($xformItem); /* peel off the beginning of the OID */ $key = $xformItem["oid"]; //print ("========= key=[$key]"); $key = str_replace("iso", "1", $key); $key = str_replace("1.3.6.1.2.1.17.7.1.2.2.1.2.", "", $key); //print ("========= key=[$key]\n"); /* now grab the VLAN Id */ $perPos = strpos($key, ".", 1); //print ("========= perPos=[$perPos]\n"); $output_array[$i]["vlan_id"] = substr($key, 1, $perPos - 1); //print ("========= i=[$i] [" . $output_array[$i]["vlan_id"] . "]\n"); /* save the key=MAC Address for association with the dot1d table */ $output_array[$i]["key"] = substr($key, $perPos); /* get VLAN name, if any: dot1qVlanStaticName from dot1qVlanStaticTable */ $vlan_name = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.7.1.4.3.1.1." . $output_array[$i]["vlan_id"], $device["snmp_version"], "", "", "", "", "", "", $device["snmp_port"], $device["snmp_timeout"]); $output_array[$i]["vlan_name"] = $vlan_name; //print ("========= i=[$i] [" . $output_array[$i]["vlan_id"] . "] name=[" . $output_array[$i]["vlan_name"] . "]\n"); $i++; } return array_rekey($output_array, "key", "vlan_id"); #return $output_array; }
$snmpv3_auth_protocol = $_SERVER["argv"][6]; $snmpv3_priv_passphrase = $_SERVER["argv"][7]; $snmpv3_priv_protocol = $_SERVER["argv"][8]; $cmd = $_SERVER["argv"][9]; if ($cmd == "index") { $return_arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, 161, 1000)); for ($i=0;($i<sizeof($return_arr));$i++) { print $return_arr[$i] . "\n"; } }elseif ($cmd == "query") { $arg = $_SERVER["argv"][10]; $arr_index = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, 161, 1000)); $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, 161, 1000)); for ($i=0;($i<sizeof($arr_index));$i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } }elseif ($cmd == "get") { $arg = $_SERVER["argv"][10]; $index = $_SERVER["argv"][11]; if (($arg == "total") || ($arg == "used")) { /* get hrStorageAllocationUnits from the snmp cache since it is faster */ $host_id = db_fetch_cell("select id from host where hostname='$hostname' and snmp_community='$snmp_community'"); $sau = db_fetch_cell("select field_value from host_data_query_cache where host_id=$host_id and field_name='hrStorageAllocationUnits' and index_value='$index'"); print (cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmpv3_auth_username, $snmpv3_auth_password, $snmpv3_auth_protocol, $snmpv3_priv_passphrase, $snmpv3_priv_protocol, 161, 1000) * $sau); }else{
function collectHostIndexedOid(&$host, $tree, $table, $name, $preserve = false) { global $cnn_id; static $types; debug("Beginning Processing for '" . $host["description"] . "[" . $host["hostname"] . "]', Table '{$name}'"); if (sizeof($host)) { /* mark for deletion */ db_execute("UPDATE {$table} SET present=0 WHERE host_id=" . $host["id"]); debug("Polling {$name} from '" . $host["description"] . "[" . $host["hostname"] . "]'"); $hostMib = array(); foreach ($tree as $mname => $oid) { if ($name == "processor") { $retrieval = SNMP_VALUE_PLAIN; } elseif ($mname == "mac") { $retrieval = SNMP_VALUE_LIBRARY; } elseif ($mname == "date") { $retrieval = SNMP_VALUE_LIBRARY; } elseif ($mname != "baseOID") { $retrieval = SNMP_VALUE_PLAIN; } else { continue; } $walk = cacti_snmp_walk($host["hostname"], $host["snmp_community"], $oid, $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"), $host["max_oids"], $retrieval, SNMP_WEBUI); $hostMib = array_merge($hostMib, $walk); } $set_string = ""; $values = ""; $sql_suffix = ""; $sql_prefix = "INSERT INTO {$table}"; if (sizeof($tree)) { foreach ($tree as $bname => $oid) { if ($bname != "baseOID" && $bname != "index") { $values .= (strlen($values) ? "`, `" : "`") . $bname; $sql_suffix .= (!strlen($sql_suffix) ? " ON DUPLICATE KEY UPDATE `index`=VALUES(`index`), `" : ", `") . $bname . "`=VALUES(`" . $bname . "`)"; } } } $sql_prefix .= " (`host_id`, `index`, " . ($preserve ? "`last_seen`, " : "") . $values . "`) VALUES "; $sql_suffix .= ", present=1" . ($preserve ? ", last_seen=NOW()" : ""); // Locate the values names $prevIndex = ""; $new_array = array(); if (sizeof($hostMib)) { foreach ($hostMib as $mib) { /* do some cleanup */ if (substr($mib["oid"], 0, 1) != ".") { $mib["oid"] = "." . $mib["oid"]; } if (substr($mib["value"], 0, 4) == "OID:") { $mib["value"] = trim(str_replace("OID:", "", $mib["value"])); } $splitIndex = mikrotik_splitBaseIndex($mib["oid"]); if (sizeof($splitIndex)) { $index = $splitIndex[1]; $oid = $splitIndex[0]; $key = array_search($oid, $tree); if (!empty($key)) { if ($key == "type") { if ($mib["value"] == ".1.3.6.1.2.1.25.2.1.1") { $new_array[$index][$key] = 11; } elseif ($mib["value"] == ".1.3.6.1.2.1.25.2.1.4") { $new_array[$index][$key] = 14; } } elseif ($key == "name") { $new_array[$index][$key] = strtoupper($mib["value"]); } elseif ($key == "date") { $new_array[$index][$key] = mikrotik_dateParse($mib["value"]); } elseif ($key != "index") { $new_array[$index][$key] = $mib["value"]; } } if (!empty($key) && $key != "index") { debug("Key:'" . $key . "', Orig:'" . $mib["oid"] . "', Val:'" . $new_array[$index][$key] . "', Index:'" . $index . "', Base:'" . $oid . "'"); } } else { echo "WARNING: Error parsing OID value\n"; } } } /* dump the output to the database */ $sql_insert = ""; $count = 0; if (sizeof($new_array)) { foreach ($new_array as $index => $item) { $sql_insert .= (strlen($sql_insert) ? "), (" : "(") . $host["id"] . ", " . $index . ", " . ($preserve ? "NOW(), " : ""); $i = 0; foreach ($tree as $mname => $oid) { if ($mname != "baseOID" && $mname != "index") { $sql_insert .= ($i > 0 ? ", " : "") . (isset($item[$mname]) && strlen(strlen($item[$mname])) ? $cnn_id->qstr($item[$mname]) : "''"); $i++; } } } $sql_insert .= ")"; $count++; if ($count % 200 == 0) { db_execute($sql_prefix . $sql_insert . $sql_suffix); $sql_insert = ""; } } //print $sql_prefix . $sql_insert . $sql_suffix . "\n"; if (strlen($sql_insert)) { db_execute($sql_prefix . $sql_insert . $sql_suffix); } } }
function xform_dlink_vlan_associations(&$device, $snmp_readstring = "") { /* get raw index data */ if ($snmp_readstring == "") { $snmp_readstring = $device["snmp_readstring"]; } /* initialize the output array */ $output_array = array(); /* obtain vlan associations */ $xformArray = cacti_snmp_walk($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.7.1.2.2.1.2", $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"], $device["max_oids"]); $i = 0; foreach ($xformArray as $xformItem) { /* peel off the beginning of the OID */ $key = $xformItem["oid"]; $key = str_replace("iso", "1", $key); $key = str_replace("1.3.6.1.2.1.17.7.1.2.2.1.2.", "", $key); //print ("========= key=[$key]\n"); /* now grab the VLAN */ $perPos = strpos($key, ".", 1); //print ("========= perPos=[$perPos]\n"); $output_array[$i]["vlan_id"] = substr($key, 1, $perPos - 1); //print ("========= i=[$i] [" . $output_array[$i]["vlan_id"] . "]\n"); /* save the key for association with the dot1d table */ $output_array[$i]["key"] = substr($key, $perPos + 1); $vlan_name = @cacti_snmp_get($device["hostname"], $snmp_readstring, ".1.3.6.1.2.1.17.7.1.4.3.1.1." . $output_array[$i]["vlan_id"], $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"]); $output_array[$i]["vlan_name"] = $vlan_name; //print ("========= i=[$i] [" . $output_array[$i]["vlan_id"] . "] name=[" . $output_array[$i]["vlan_name"] . "]\n"); $i++; } //return array_rekey($output_array, "key", "vlan_name"); return $output_array; }
$no_http_headers = true; if (file_exists(dirname(__FILE__) . "/../include/global.php")) { include(dirname(__FILE__) . "/../include/global.php"); } include(dirname(__FILE__) . "/../include/config.php"); include(dirname(__FILE__) . "/../lib/snmp.php"); $hostname = $_SERVER["argv"][1]; $snmp_community = $_SERVER["argv"][2]; $snmp_version = $_SERVER["argv"][3]; $bsnMobileStationStatus = ".1.3.6.1.4.1.14179.2.1.4.1.9"; $stationstatus = reindex(cacti_snmp_walk($hostname, $snmp_community, $bsnMobileStationStatus, $snmp_version, "", "", 161, 1000)); $findStationStatusType= array_count_values($stationstatus); $stationidle=0; $stationpending=0; $stationauthenticated=0; $stationassociated=0; $stationpowersave=0; $stationdisassociated=0; $stationtobedeleted=0; $stationprobing=0; $stationblacklisted=0; if (array_key_exists('0', $findStationStatusType)) {
function xform_indexed_data($xformOID, &$device, $xformLevel = 1) { /* get raw index data */ $xformArray = cacti_snmp_walk($device["hostname"], $device["snmp_readstring"], $xformOID, $device["snmp_version"], $device["snmp_username"], $device["snmp_password"], $device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"], $device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], $device["snmp_retries"], $device["max_oids"]); $i = 0; $output_array = array(); if (sizeof($xformArray)) { foreach ($xformArray as $xformItem) { /* break down key */ $OID = $xformItem["oid"]; for ($j = 0; $j < $xformLevel; $j++) { $perPos = strrpos($OID, "."); $xformItem_piece[$j] = substr($OID, $perPos + 1); $OID = substr($OID, 0, $perPos); } /* reassemble key */ $key = ""; for ($j = $xformLevel - 1; $j >= 0; $j--) { $key .= $xformItem_piece[$j]; if ($j > 0) { $key .= "."; } } $output_array[$i]["key"] = $key; $output_array[$i]["value"] = $xformItem["value"]; $i++; } } return array_rekey($output_array, "key", "value"); }
function ss_host_disk($hostname, $device_id, $snmp_auth, $cmd, $arg1 = "", $arg2 = "") { $snmp = explode(":", $snmp_auth); $snmp_version = $snmp[0]; $snmp_port = $snmp[1]; $snmp_timeout = $snmp[2]; $ping_retries = $snmp[3]; $max_oids = $snmp[4]; $snmp_auth_username = ""; $snmp_auth_password = ""; $snmp_auth_protocol = ""; $snmp_priv_passphrase = ""; $snmp_priv_protocol = ""; $snmp_context = ""; $snmp_community = ""; if ($snmp_version == 3) { $snmp_auth_username = $snmp[6]; $snmp_auth_password = $snmp[7]; $snmp_auth_protocol = $snmp[8]; $snmp_priv_passphrase = $snmp[9]; $snmp_priv_protocol = $snmp[10]; $snmp_context = $snmp[11]; }else{ $snmp_community = $snmp[5]; } $oids = array( "total" => ".1.3.6.1.2.1.25.2.3.1.5", "used" => ".1.3.6.1.2.1.25.2.3.1.6", "failures" => ".1.3.6.1.2.1.25.2.3.1.7", "index" => ".1.3.6.1.2.1.25.2.3.1.1", "description" => ".1.3.6.1.2.1.25.2.3.1.3", "sau" => ".1.3.6.1.2.1.25.2.3.1.4" ); if ($cmd == "index") { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i=0;($i<sizeof($return_arr));$i++) { print $return_arr[$i] . "\n"; } }elseif ($cmd == "query") { $arg = $arg1; $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i=0;($i<sizeof($arr_index));$i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } }elseif ($cmd == "get") { $arg = $arg1; $index = $arg2; if (!array_key_exists($arg, $oids)) { return "ERROR: Invalid get parameter"; } if (($arg == "total") || ($arg == "used")) { $sau = preg_replace("/[^0-9]/i", "", db_fetch_cell("select field_value from device_snmp_cache where device_id=$device_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'")); $value = cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol,$snmp_priv_passphrase,$snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); return (strlen($value) > 0) ? $value * $sau : "U"; }else{ return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".$index", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol,$snmp_priv_passphrase,$snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); } } }
function query_snmp_host($host_id, $snmp_query_id) { global $config; include_once $config["library_path"] . "/snmp.php"; $host = db_fetch_row("SELECT\n\t\thostname,\n\t\tsnmp_community,\n\t\tsnmp_version,\n\t\tsnmp_username,\n\t\tsnmp_password,\n\t\tsnmp_auth_protocol,\n\t\tsnmp_priv_passphrase,\n\t\tsnmp_priv_protocol,\n\t\tsnmp_context,\n\t\tsnmp_port,\n\t\tsnmp_timeout,\n\t\tping_retries,\n\t\tmax_oids\n\t\tFROM host\n\t\tWHERE id='{$host_id}'"); $snmp_queries = get_data_query_array($snmp_query_id); if ($host["hostname"] == "") { debug_log_insert("data_query", "Invalid host_id: {$host_id}"); return false; } /* invalid xml check */ if (!is_array($snmp_queries) || sizeof($snmp_queries) == 0) { debug_log_insert("data_query", "Error parsing XML file into an array."); return false; } debug_log_insert("data_query", "XML file parsed ok."); if (!verify_index_order($snmp_queries)) { debug_log_insert("data_query", "Invalid field <index_order>" . $snmp_queries["index_order"] . "</index_order>"); debug_log_insert("data_query", "Must contain <direction>input</direction> fields only"); return false; } /* provide data for oid_num_indexes, if given */ if (isset($snmp_queries["oid_num_indexes"])) { $snmp_num_indexes = cacti_snmp_get($host["hostname"], $host["snmp_community"], $snmp_queries["oid_num_indexes"], $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"], $host["ping_retries"], $host["max_oids"], SNMP_WEBUI); debug_log_insert("data_query", "Executing SNMP get for num of indexes @ '" . $snmp_queries["oid_num_indexes"] . "' Index Count: " . $snmp_num_indexes); } else { debug_log_insert("data_query", "<oid_num_indexes> missing in XML file, 'Index Count Changed' emulated by counting oid_index entries"); } /* fetch specified index at specified OID */ $snmp_indexes = cacti_snmp_walk($host["hostname"], $host["snmp_community"], $snmp_queries["oid_index"], $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"], $host["ping_retries"], $host["max_oids"], SNMP_WEBUI); debug_log_insert("data_query", "Executing SNMP walk for list of indexes @ '" . $snmp_queries["oid_index"] . "' Index Count: " . sizeof($snmp_indexes)); /* no data found; get out */ if (!sizeof($snmp_indexes)) { debug_log_insert("data_query", "No SNMP data returned"); return false; } else { /* show list of indices found */ for ($i = 0; $i < sizeof($snmp_indexes); $i++) { debug_log_insert("data_query", "Index found at OID: '" . $snmp_indexes[$i]["oid"] . "' value: '" . $snmp_indexes[$i]["value"] . "'"); } } /* the last octet of the oid is the index by default */ $index_parse_regexp = '.*\\.([0-9]+)$'; /* parse the index if required */ if (isset($snmp_queries["oid_index_parse"])) { $index_parse_regexp = str_replace("OID/REGEXP:", "", $snmp_queries["oid_index_parse"]); for ($i = 0; $i < sizeof($snmp_indexes); $i++) { $snmp_indexes[$i]["value"] = preg_replace('/' . $index_parse_regexp . '/', "\\1", $snmp_indexes[$i]["oid"]); debug_log_insert("data_query", "index_parse at OID: '" . $snmp_indexes[$i]["oid"] . "' results: '" . $snmp_indexes[$i]["value"] . "'"); } } /* set an array to host all updates */ $output_array = array(); while (list($field_name, $field_array) = each($snmp_queries["fields"])) { if (!isset($field_array["oid"]) && $field_array["source"] == "index") { for ($i = 0; $i < sizeof($snmp_indexes); $i++) { debug_log_insert("data_query", "Inserting index data for field '" . $field_name . "' [value='" . $snmp_indexes[$i]["value"] . "']"); $output_array[] = data_query_format_record($host_id, $snmp_query_id, $field_name, $snmp_indexes[$i]["value"], $snmp_indexes[$i]["value"], ''); } } else { if ($field_array["method"] == "get" && $field_array["direction"] == "input") { debug_log_insert("data_query", "Located input field '{$field_name}' [get]"); if ($field_array["source"] == "value") { for ($i = 0; $i < sizeof($snmp_indexes); $i++) { $oid = $field_array["oid"] . "." . $snmp_indexes[$i]["value"]; $oid .= isset($field_array["oid_suffix"]) ? "." . $field_array["oid_suffix"] : ""; $value = cacti_snmp_get($host["hostname"], $host["snmp_community"], $oid, $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"], SNMP_WEBUI); debug_log_insert("data_query", "Executing SNMP get for data @ '{$oid}' [value='{$value}']"); $output_array[] = data_query_format_record($host_id, $snmp_query_id, $field_name, $value, $snmp_indexes[$i]["value"], $oid); } } } else { if ($field_array["method"] == "walk" && $field_array["direction"] == "input") { debug_log_insert("data_query", "Located input field '{$field_name}' [walk]"); $snmp_data = array(); $snmp_data = cacti_snmp_walk($host["hostname"], $host["snmp_community"], $field_array["oid"], $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"], $host["ping_retries"], $host["max_oids"], SNMP_WEBUI); debug_log_insert("data_query", "Executing SNMP walk for data @ '" . $field_array["oid"] . "'"); if ($field_array["source"] == "value") { for ($i = 0; $i < sizeof($snmp_data); $i++) { $snmp_index = preg_replace('/' . (isset($field_array["oid_index_parse"]) ? $field_array["oid_index_parse"] : $index_parse_regexp) . '/', "\\1", $snmp_data[$i]["oid"]); $oid = $field_array["oid"] . ".{$snmp_index}"; if ($field_name == "ifOperStatus") { if (substr_count(strtolower($snmp_data[$i]["value"]), "down") || $snmp_data[$i]["value"] == "2") { $snmp_data[$i]["value"] = "Down"; } else { if (substr_count(strtolower($snmp_data[$i]["value"]), "up") || $snmp_data[$i]["value"] == "1") { $snmp_data[$i]["value"] = "Up"; } else { if (substr_count(strtolower($snmp_data[$i]["value"]), "notpresent") || $snmp_data[$i]["value"] == "6") { $snmp_data[$i]["value"] = "notPresent"; } else { $snmp_data[$i]["value"] = "Testing"; } } } } debug_log_insert("data_query", "Found item [{$field_name}='" . $snmp_data[$i]["value"] . "'] index: {$snmp_index} [from value]"); $output_array[] = data_query_format_record($host_id, $snmp_query_id, $field_name, $snmp_data[$i]["value"], $snmp_index, $oid); } } elseif (substr($field_array["source"], 0, 11) == "OID/REGEXP:") { for ($i = 0; $i < sizeof($snmp_data); $i++) { $value = preg_replace('/' . str_replace("OID/REGEXP:", "", $field_array["source"]) . '/', "\\1", $snmp_data[$i]["oid"]); if (isset($snmp_queries["oid_index_parse"])) { $snmp_index = preg_replace('/' . $index_parse_regexp . '/', "\\1", $snmp_data[$i]["oid"]); } else { if (isset($snmp_data[$i]["value"]) && $snmp_data[$i]["value"] != "") { $snmp_index = $snmp_data[$i]["value"]; } } /* correct bogus index value */ /* found in some devices such as an EMC Cellera */ if ($snmp_index == 0) { $snmp_index = 1; } $oid = $field_array["oid"] . "." . $value; debug_log_insert("data_query", "Found item [{$field_name}='{$value}'] index: {$snmp_index} [from regexp oid parse]"); $output_array[] = data_query_format_record($host_id, $snmp_query_id, $field_name, $value, $snmp_index, $oid); } } elseif (substr($field_array["source"], 0, 13) == "VALUE/REGEXP:") { for ($i = 0; $i < sizeof($snmp_data); $i++) { $value = preg_replace('/' . str_replace("VALUE/REGEXP:", "", $field_array["source"]) . '/', "\\1", $snmp_data[$i]["value"]); $snmp_index = preg_replace('/' . (isset($field_array["oid_index_parse"]) ? $field_array["oid_index_parse"] : $index_parse_regexp) . '/', "\\1", $snmp_data[$i]["oid"]); $oid = $field_array["oid"] . "." . $snmp_index; debug_log_insert("data_query", "Found item [{$field_name}='{$value}'] index: {$snmp_index} [from regexp value parse]"); $output_array[] = "('{$host_id}', '{$snmp_query_id}', '{$field_name}', '{$value}', '{$snmp_index}', '{$oid}', '1')"; } } } } } } data_query_update_host_cache_from_buffer($host_id, $snmp_query_id, $output_array); return true; }
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; }
*/ if ($cmd == "index") { $return_arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i=0;($i<sizeof($return_arr));$i++) { print $return_arr[$i] . "\n"; } /* * process QUERY requests */ }elseif ($cmd == "query") { $arg = $_SERVER["argv"][5]; $arr_index = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids["index"], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); $arr = reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i=0;($i<sizeof($arr_index));$i++) { print $arr_index[$i] . "!" . $arr[$i] . "\n"; } /* * process GET requests */ }elseif ($cmd == "get") { $arg = $_SERVER["argv"][5]; $index = $_SERVER["argv"][6]; if (($arg == "total") || ($arg == "used")) { /* get hrStorageAllocationUnits from the snmp cache since it is faster */ $sau = db_fetch_cell("select field_value from device_snmp_cache where device_id=$device_id and field_name='hrStorageAllocationUnits' and snmp_index='$index'");
$no_http_headers = true; if (file_exists(dirname(__FILE__) . "/../include/global.php")) { include(dirname(__FILE__) . "/../include/global.php"); } include(dirname(__FILE__) . "/../include/config.php"); include(dirname(__FILE__) . "/../lib/snmp.php"); $hostname = $_SERVER["argv"][1]; $snmp_community = $_SERVER["argv"][2]; $snmp_version = $_SERVER["argv"][3]; $bsnMobileEncryptionCipher = ".1.3.6.1.4.1.14179.2.1.4.1.31"; $stationcipher = reindex(cacti_snmp_walk($hostname, $snmp_community, $bsnMobileEncryptionCipher, $snmp_version, "", "", 161, 1000)); $findStationCipherType= array_count_values($stationcipher); $stationccmpaes=0; $stationtkipmic=0; $stationwep40=0; $stationwep104=0; $stationwep128=0; $stationciphernone=0; $stationciphernotavailable=0; $stationcipherunknown=0; if (array_key_exists('0', $findStationCipherType)) { $stationccmpaes=$findStationCipherType[0];
function ss_host_disk($hostname, $host_id, $snmp_auth, $cmd, $arg1 = '', $arg2 = '') { global $environ; $snmp = explode(':', $snmp_auth); $snmp_version = $snmp[0]; $snmp_port = $snmp[1]; $snmp_timeout = $snmp[2]; $ping_retries = $snmp[3]; $max_oids = $snmp[4]; $snmp_auth_username = ''; $snmp_auth_password = ''; $snmp_auth_protocol = ''; $snmp_priv_passphrase = ''; $snmp_priv_protocol = ''; $snmp_context = ''; $snmp_community = ''; if ($snmp_version == 3) { $snmp_auth_username = $snmp[6]; $snmp_auth_password = $snmp[7]; $snmp_auth_protocol = $snmp[8]; $snmp_priv_passphrase = $snmp[9]; $snmp_priv_protocol = $snmp[10]; $snmp_context = $snmp[11]; } else { $snmp_community = $snmp[5]; } $oids = array('total' => '.1.3.6.1.2.1.25.2.3.1.5', 'totalin' => '.1.3.6.1.2.1.25.2.3.1.5', 'used' => '.1.3.6.1.2.1.25.2.3.1.6', 'failures' => '.1.3.6.1.2.1.25.2.3.1.7', 'index' => '.1.3.6.1.2.1.25.2.3.1.1', 'description' => '.1.3.6.1.2.1.25.2.3.1.3', 'sau' => '.1.3.6.1.2.1.25.2.3.1.4'); if ($cmd == 'index') { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i = 0; $i < sizeof($return_arr); $i++) { print $return_arr[$i] . "\n"; } } elseif ($cmd == 'num_indexes') { $return_arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); print sizeof($return_arr) . "\n"; } elseif ($cmd == 'query') { $arg = $arg1; $arr_index = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids['index'], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); $arr = ss_host_disk_reindex(cacti_snmp_walk($hostname, $snmp_community, $oids[$arg], $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, $max_oids, SNMP_POLLER)); for ($i = 0; $i < sizeof($arr_index); $i++) { print $arr_index[$i] . '!' . $arr[$i] . "\n"; } } elseif ($cmd == 'get') { $arg = $arg1; $index = $arg2; if ($environ != 'realtime') { $value = api_plugin_hook_function('hmib_get_disk', array('host_id' => $host_id, 'arg' => $arg, 'index' => $index)); } else { $value = array(); } if (is_array($value)) { if ($arg == 'total' || $arg == 'used') { $sau = preg_replace('/[^0-9]/i', '', db_fetch_cell("select field_value from host_snmp_cache where host_id={$host_id} and field_name='hrStorageAllocationUnits' and snmp_index='{$index}'")); $snmp_data = cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); if ($snmp_data < 0) { return (abs($snmp_data) + 2147483647) * $sau; } else { return $snmp_data * $sau; } } else { return cacti_snmp_get($hostname, $snmp_community, $oids[$arg] . ".{$index}", $snmp_version, $snmp_auth_username, $snmp_auth_password, $snmp_auth_protocol, $snmp_priv_passphrase, $snmp_priv_protocol, $snmp_context, $snmp_port, $snmp_timeout, $ping_retries, SNMP_POLLER); } } else { return $value; } } }
function collectHostIndexedOid(&$host, $tree, $table, $name) { global $cnn_id; static $types; debug("Beginning Processing for '" . $host["description"] . "[" . $host["hostname"] . "]', Table '{$name}'"); if (!sizeof($types)) { $types = array_rekey(db_fetch_assoc("SELECT id, oid, description FROM plugin_hmib_types"), "oid", array("id", "description")); } if (sizeof($host)) { /* mark for deletion */ db_execute("UPDATE {$table} SET present=0 WHERE host_id=" . $host["id"]); debug("Polling {$name} from '" . $host["description"] . "[" . $host["hostname"] . "]'"); $hostMib = array(); foreach ($tree as $mname => $oid) { if ($name == "hrProcessor") { $retrieval = SNMP_VALUE_PLAIN; } elseif ($mname == "date") { $retrieval = SNMP_VALUE_LIBRARY; } elseif ($mname != "baseOID") { $retrieval = SNMP_VALUE_PLAIN; } else { continue; } $walk = cacti_snmp_walk($host["hostname"], $host["snmp_community"], $oid, $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"), $host["max_oids"], $retrieval, SNMP_WEBUI); $hostMib = array_merge($hostMib, $walk); } $set_string = ""; $values = ""; $sql_suffix = ""; $sql_prefix = "INSERT INTO {$table}"; if (sizeof($tree)) { foreach ($tree as $bname => $oid) { if ($bname != "baseOID" && $bname != "index") { $values .= (strlen($values) ? "`, `" : "`") . $bname; $sql_suffix .= (!strlen($sql_suffix) ? " ON DUPLICATE KEY UPDATE `index`=VALUES(`index`), `" : ", `") . $bname . "`=VALUES(`" . $bname . "`)"; } } } $sql_prefix .= " (`host_id`, `index`, " . $values . "`) VALUES "; $sql_suffix .= ", present=1"; // Locate the values names $prevIndex = ""; $new_array = array(); $wonky = false; $hrProcValid = false; $effective = 0; if (sizeof($hostMib)) { foreach ($hostMib as $mib) { /* do some cleanup */ if (substr($mib["oid"], 0, 1) != ".") { $mib["oid"] = "." . $mib["oid"]; } if (substr($mib["value"], 0, 4) == "OID:") { $mib["value"] = trim(str_replace("OID:", "", $mib["value"])); } $splitIndex = hmib_splitBaseIndex($mib["oid"]); if (sizeof($splitIndex)) { $index = $splitIndex[1]; $oid = $splitIndex[0]; $key = array_search($oid, $tree); /* issue workaround for snmp issues */ if ($name == "hrProcessor" && $mib["value"] == ".0.0") { if ($wonky) { $key = "load"; $mib["value"] = $effective; } elseif (!$hrProcValid) { if (db_fetch_cell("SELECT count(*) FROM plugin_hmib_hrSystem WHERE sysDescr LIKE '%Linux%' AND host_id=" . $host["id"])) { /* look for the hrProcessorLoad value */ $temp_mib = $hostMib; foreach ($temp_mib as $kk => $vv) { if (substr_count($kk, ".1.3.6.1.2.1.25.3.3.1.2")) { $hrProcValid = true; } } if (!$hrProcValid) { $user = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.4.1.2021.11.9.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"), $host["max_oids"], SNMP_VALUE_LIBRARY, SNMP_WEBUI); $system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.4.1.2021.11.10.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"), $host["max_oids"], SNMP_VALUE_LIBRARY, SNMP_WEBUI); $effective = ($user + $system) * 2 / sizeof($mib); $key = "load"; $mib["value"] = $effective; $wonky = true; } } else { $effective = 0; } } } if (!empty($key)) { if ($key == "type") { $value = explode("(", $mib["value"]); if (sizeof($value) > 1) { $value = trim($value[1], " \n\r)"); if ($table != "plugin_hmib_hrSWInstalled" && $table != "plugin_hmib_hrSWRun") { $new_array[$index][$key] = isset($types[$value]) ? $types[$value]["id"] : 0; } else { $new_array[$index][$key] = $value; } } else { if ($table != "plugin_hmib_hrSWInstalled" && $table != "plugin_hmib_hrSWRun") { $new_array[$index][$key] = isset($types[$value[0]]) ? $types[$value[0]]["id"] : 0; } else { $new_array[$index][$key] = $value[0]; } } } elseif ($key == "date") { $new_array[$index][$key] = hmib_dateParse($mib["value"]); } elseif ($key != "index") { $new_array[$index][$key] = $mib["value"]; } } if (!empty($key) && $key != "index") { debug("Key:'" . $key . "', Orig:'" . $mib["oid"] . "', Val:'" . $new_array[$index][$key] . "', Index:'" . $index . "', Base:'" . $oid . "'"); } } else { echo "WARNING: Error parsing OID value\n"; } } } /* dump the output to the database */ $sql_insert = ""; $count = 0; if (sizeof($new_array)) { foreach ($new_array as $index => $item) { $sql_insert .= (strlen($sql_insert) ? "), (" : "(") . $host["id"] . ", " . $index . ", "; $i = 0; foreach ($tree as $mname => $oid) { if ($mname != "baseOID" && $mname != "index") { $sql_insert .= ($i > 0 ? ", " : "") . (isset($item[$mname]) && strlen(strlen($item[$mname])) ? $cnn_id->qstr($item[$mname]) : "''"); $i++; } } } $sql_insert .= ")"; $count++; if ($count % 200 == 0) { db_execute($sql_prefix . $sql_insert . $sql_suffix); $sql_insert = ""; } } if ($sql_insert != '') { db_execute($sql_prefix . $sql_insert . $sql_suffix); } /* remove old records */ db_execute("DELETE FROM {$table} WHERE present=0 AND host_id=" . $host["id"]); } }
function query_snmp_host($host_id, $snmp_query_id) { global $config; include_once($config["library_path"] . "/snmp.php"); $host = db_fetch_row("SELECT hostname, snmp_community, snmp_version, snmp_username, snmp_password, snmp_auth_protocol, snmp_priv_passphrase, snmp_priv_protocol, snmp_context, snmp_port, snmp_timeout FROM host WHERE id='$host_id'"); $snmp_queries = get_data_query_array($snmp_query_id); if ($host["hostname"] == "") { debug_log_insert("data_query", "Invalid host_id: $host_id"); return false; } /* invalid xml check */ if ((!is_array($snmp_queries)) || (sizeof($snmp_queries) == 0)) { debug_log_insert("data_query", "Error parsing XML file into an array."); return false; } debug_log_insert("data_query", "XML file parsed ok."); /* fetch specified index at specified OID */ $snmp_index = cacti_snmp_walk($host["hostname"], $host["snmp_community"], $snmp_queries["oid_index"], $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); debug_log_insert("data_query", "Executing SNMP walk for list of indexes @ '" . $snmp_queries["oid_index"] . "'"); /* no data found; get out */ if (!$snmp_index) { debug_log_insert("data_query", "No SNMP data returned"); return false; } /* the last octet of the oid is the index by default */ $index_parse_regexp = '.*\.([0-9]+)$'; /* parse the index if required */ if (isset($snmp_queries["oid_index_parse"])) { $index_parse_regexp = str_replace("OID/REGEXP:", "", $snmp_queries["oid_index_parse"]); for ($i=0; $i<sizeof($snmp_index); $i++) { $snmp_index[$i]["value"] = ereg_replace($index_parse_regexp, "\\1", $snmp_index[$i]["oid"]); } } db_execute("delete from host_snmp_cache where host_id='$host_id' and snmp_query_id='$snmp_query_id'"); while (list($field_name, $field_array) = each($snmp_queries["fields"])) { if ((!isset($field_array["oid"])) && ($field_array["source"] == "index")) { for ($i=0; $i<sizeof($snmp_index); $i++) { debug_log_insert("data_query", "Inserting index data [value='" . $snmp_index[$i]["value"] . "']"); db_execute("replace into host_snmp_cache (host_id, snmp_query_id, field_name, field_value, snmp_index, oid) values ('$host_id','$snmp_query_id','$field_name','" . $snmp_index[$i]["value"] . "','" . $snmp_index[$i]["value"] . "','')"); } }else if (($field_array["method"] == "get") && ($field_array["direction"] == "input")) { debug_log_insert("data_query", "Located input field '$field_name' [get]"); if ($field_array["source"] == "value") { for ($i=0; $i<sizeof($snmp_index); $i++) { $oid = $field_array["oid"] . "." . $snmp_index[$i]["value"]; $value = cacti_snmp_get($host["hostname"], $host["snmp_community"], $oid, $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"], SNMP_WEBUI); debug_log_insert("data_query", "Executing SNMP get for data @ '$oid' [value='$value']"); db_execute("replace into host_snmp_cache (host_id,snmp_query_id,field_name,field_value,snmp_index,oid) values ('$host_id','$snmp_query_id','$field_name','$value','" . $snmp_index[$i]["value"] . "','$oid')"); } } }else if (($field_array["method"] == "walk") && ($field_array["direction"] == "input")) { debug_log_insert("data_query", "Located input field '$field_name' [walk]"); $snmp_data = array(); $snmp_data = cacti_snmp_walk($host["hostname"], $host["snmp_community"], $field_array["oid"], $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); debug_log_insert("data_query", "Executing SNMP walk for data @ '" . $field_array["oid"] . "'"); if ($field_array["source"] == "value") { for ($i=0; $i<sizeof($snmp_data); $i++) { $snmp_index = ereg_replace($index_parse_regexp, "\\1", $snmp_data[$i]["oid"]); $oid = $field_array["oid"] . ".$snmp_index"; if ($field_name == "ifOperStatus") { if ((substr_count(strtolower($snmp_data[$i]["value"]), "down")) || ($snmp_data[$i]["value"] == "2")) { $snmp_data[$i]["value"] = "Down"; }else if ((substr_count(strtolower($snmp_data[$i]["value"]), "up")) || ($snmp_data[$i]["value"] == "1")) { $snmp_data[$i]["value"] = "Up"; }else{ $snmp_data[$i]["value"] = "Testing"; } } debug_log_insert("data_query", "Found item [$field_name='" . $snmp_data[$i]["value"] . "'] index: $snmp_index [from value]"); db_execute("replace into host_snmp_cache (host_id,snmp_query_id,field_name,field_value,snmp_index,oid) values ('$host_id','$snmp_query_id','$field_name','" . $snmp_data[$i]["value"] . "','$snmp_index','$oid')"); } }elseif (substr($field_array["source"], 0, 11) == "OID/REGEXP:") { for ($i=0; $i<sizeof($snmp_data); $i++) { $value = ereg_replace(str_replace("OID/REGEXP:", "", $field_array["source"]), "\\1", $snmp_data[$i]["oid"]); if (isset($snmp_queries["oid_index_parse"])) { $snmp_index = ereg_replace($index_parse_regexp, "\\1", $snmp_data[$i]["oid"]); }else if ((isset($snmp_data[$i]["value"])) && ($snmp_data[$i]["value"] != "")) { $snmp_index = $snmp_data[$i]["value"]; } /* correct bogus index value */ /* found in some devices such as an EMC Cellera */ if ($snmp_index == 0) { $snmp_index = 1; } $oid = $field_array["oid"] . "." . $value; debug_log_insert("data_query", "Found item [$field_name='$value'] index: $snmp_index [from regexp oid parse]"); db_execute("replace into host_snmp_cache (host_id,snmp_query_id,field_name,field_value,snmp_index,oid) values ('$host_id','$snmp_query_id','$field_name','$value','$snmp_index','$oid')"); } }elseif (substr($field_array["source"], 0, 13) == "VALUE/REGEXP:") { for ($i=0; $i<sizeof($snmp_data); $i++) { $value = ereg_replace(str_replace("VALUE/REGEXP:", "", $field_array["source"]), "\\1", $snmp_data[$i]["value"]); $snmp_index = ereg_replace($index_parse_regexp, "\\1", $snmp_data[$i]["oid"]); $oid = $field_array["oid"] . "." . $value; debug_log_insert("data_query", "Found item [$field_name='$value'] index: $snmp_index [from regexp value parse]"); db_execute("replace into host_snmp_cache (host_id,snmp_query_id,field_name,field_value,snmp_index,oid) values ('$host_id','$snmp_query_id','$field_name','$value','$snmp_index','$oid')"); } } } } return true; }
$no_http_headers = true; if (file_exists(dirname(__FILE__) . "/../include/global.php")) { include(dirname(__FILE__) . "/../include/global.php"); } include(dirname(__FILE__) . "/../include/config.php"); include(dirname(__FILE__) . "/../lib/snmp.php"); $hostname = $_SERVER["argv"][1]; $snmp_community = $_SERVER["argv"][2]; $snmp_version = $_SERVER["argv"][3]; $bsnRogueAPEntry = ".1.3.6.1.4.1.14179.2.1.7.1.24"; $rogues = reindex(cacti_snmp_walk($hostname, $snmp_community, $bsnRogueAPEntry, $snmp_version, "", "", 161, 1000)); $sorted = array_count_values($rogues); for ($i = 0; $i <= 10; $i++) { if (array_key_exists($i, $sorted)) { } else { $sorted[$i] = 0;} } print "reta:" . $sorted[0] . " retb:" . $sorted[1] . " retc:" . $sorted[2] . " retd:" . $sorted[3] . " rete:" . $sorted[4] . " retf:" . $sorted[5] . " retg:" . $sorted[6] . " reth:" . $sorted[7] . " reti:" . $sorted[8] . " retj:" . $sorted[9] . " retk:" . $sorted[10]; function reindex($arr) {