I promised lately to publish my latest script; so here we go!
Use case:
Assume an SNMPtable filled with one to many indices. In my example, it was the number of flows through an Enterasys N7 switch (OID: .1.3.6.1.4.1.5624.1.2.43.1.3.1.1.6). The snmpwalk would look like
Code: Select all
snmpwalk -c .... -v ... <hostname> .1.3.6.1.4.1.5624.1.2.43.1.3.1.1.6
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12001 = Gauge32: 1
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12002 = Gauge32: 631
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12003 = Gauge32: 649
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12004 = Gauge32: 631
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12005 = Gauge32: 197
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12006 = Gauge32: 169
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12007 = Gauge32: 1424
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12008 = Gauge32: 752
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12009 = Gauge32: 317
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12010 = Gauge32: 409
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12011 = Gauge32: 2
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.12012 = Gauge32: 289
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22001 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22002 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22003 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22004 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22005 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22006 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22007 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22008 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22009 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22010 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22011 = Gauge32: 0
SNMPv2-SMI::enterprises.5624.1.2.43.1.3.1.1.6.22012 = Gauge32: 0
Script (PHP Script Server Script). Place it into ./scripts
Code: Select all
<?php
/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
die("<br><strong>This script is only meant to run at the command line.</strong>");
}
$no_http_headers = true;
/* display No errors */
error_reporting(E_ERROR);
include_once(dirname(__FILE__) . "/../lib/snmp.php");
if (!isset($called_by_script_server)) {
if (file_exists(dirname(__FILE__) . "/../include/global.php")) {
include_once(dirname(__FILE__) . "/../include/global.php");
} else {
include_once(dirname(__FILE__) . "/../include/config.php");
}
array_shift($_SERVER["argv"]);
print call_user_func_array("ss_total_snmpwalk", $_SERVER["argv"]);
}
function ss_total_snmpwalk($hostname, $oid, $snmp_community, $snmp_version, $snmp_port, $snmp_timeout, $snmp_auth_username="", $snmp_auth_password="", $snmp_auth_protocol="", $snmp_priv_passphrase="", $snmp_priv_protocol="", $snmp_context="") {
$result = 0;
$arr = cacti_snmp_walk($hostname, $snmp_community, $oid, $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);
$nonzero_count = 0;
for ($i=0;($i<sizeof($arr));$i++) {
if (is_numeric($arr[$i]["value"])) {
$result += $arr[$i]["value"];
if ( $arr[$i]["value"] > 0 ) {
$nonzero_count++;
}
}
}
$cacti_result = "items:" . trim($i) . " nonzero:" . $nonzero_count . " total:" . trim($result);
return $cacti_result;
}
?>
Data Input Method (see Scrennshot attached). Full SNMP V3 support is provided!
A Screenshot of the graph generated: