本文整理汇总了PHP中cacti_snmp_walk函数的典型用法代码示例。如果您正苦于以下问题:PHP cacti_snmp_walk函数的具体用法?PHP cacti_snmp_walk怎么用?PHP cacti_snmp_walk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cacti_snmp_walk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ss_host_disk
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);
}
}
}
示例2: ss_host_disk
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;
}
}
}
示例3: ss_host_cpu_get_indexes
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;
}
示例4: get_indexes
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;
}
示例5: get_indexes
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;
}
示例6: ss_count_oids
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';
}
示例7: ss_host_cpu_get_indexes
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;
}
示例8: get_indexes
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;
}
示例9: ss_host_disk
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";
}
}
示例10: query_snmp_device
/**
* 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)){
//.........这里部分代码省略.........
示例11: cacti_log
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;
示例12: collectHostIndexedOid
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'];
}
//.........这里部分代码省略.........
示例13: ss_host_disk
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);
}
}
}
示例14: include
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];
示例15: reindex
$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{