Generic SNMPwalk to retrieve multiple values in one run

Templates, scripts for templates, scripts and requests for templates.

Moderators: Moderators, Developers

Author
Message
User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Generic SNMPwalk to retrieve multiple values in one run

#1 Post by gandalf » Mon Dec 08, 2008 4:22 am

Hi all,

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
Assume, you are NOT interested in each flow index but the sum, number of items and average only. Then, this is what you want to use:

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;
}

?>
This script walks the OID given. It Counts the numbers of entries, the number of non-zero entries and the total sum of all entries. From this, you may compute (total sum)/(number of items) or (total sum)/(number of non-zero items) by means of a CDEF.

Data Input Method (see Scrennshot attached). Full SNMP V3 support is provided!

A Screenshot of the graph generated:
Attachments
cacti_graph_template_snmp_-_total_all_values_of_snmpwalk.xml
The Graph Template XML (including the Data Template and Data Input Method)
(20.73 KiB) Downloaded 2366 times
ss_total_snmpwalk.php.txt
The Script. Download to ./scripts directory and remove .txt extension
(1.6 KiB) Downloaded 2014 times
Total Flows.png
The Graph Example for Total Flows of an Enterasys N7 Switch
Total Flows.png (26.17 KiB) Viewed 53621 times
Data Input Method.png
The Data Input Method
Data Input Method.png (64.09 KiB) Viewed 53621 times
Last edited by gandalf on Sat Jan 31, 2009 12:05 pm, edited 3 times in total.

ibu
Posts: 4
Joined: Thu Dec 18, 2008 4:59 am

#2 Post by ibu » Mon Jan 05, 2009 5:29 am

Well I don´t know am I dummy or something else but I got Error: XML parse error. Why? I can´t import that template.

Also what is the exact name of that php-file?

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#3 Post by gandalf » Tue Jan 06, 2009 2:55 pm

Oops, will provide the script as a download file tomorrow.
Reinhard

DukeR
Posts: 26
Joined: Fri Dec 19, 2008 3:50 am

#4 Post by DukeR » Tue Jan 20, 2009 7:33 am

Hi

Where is the download file?

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#5 Post by gandalf » Wed Jan 21, 2009 3:41 am

The file was posted inline. But for convenience, I added it now to the downloads. Please remove the .txt extension after download
Reinhard

Ellennora

RE : Generic SNMPwalk to retrieve multiple values in one run

#6 Post by Ellennora » Thu Jan 29, 2009 1:57 am

Can you provide me that downloading file?

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#7 Post by gandalf » Sat Jan 31, 2009 12:07 pm

The XML file was updated due to malformed XML
Reinhard

ambre
Cacti User
Posts: 64
Joined: Tue Jan 27, 2009 5:41 am

#8 Post by ambre » Thu Feb 12, 2009 6:16 pm

I would like to create a graph for a netapp with temperature graph.

result for snmpwalk:

SNMPv2-SMI::enterprises.789.1.21.1.2.1.1.1 = INTEGER: 0
SNMPv2-SMI::enterprises.789.1.21.1.2.1.2.1 = INTEGER: 3
SNMPv2-SMI::enterprises.789.1.21.1.2.1.3.1 = STRING: "0c.00.99"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.4.1 = STRING: "5:00c:0ff003:b5633c"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.5.1 = STRING: "DS12-ESAS"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.6.1 = STRING: "NETAPP "
SNMPv2-SMI::enterprises.789.1.21.1.2.1.7.1 = STRING: "NA-1200-SL-SAS "
SNMPv2-SMI::enterprises.789.1.21.1.2.1.8.1 = STRING: "--04"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.9.1 = STRING: "NTAPMIL-080103B563 "
SNMPv2-SMI::enterprises.789.1.21.1.2.1.10.1 = INTEGER: 12
SNMPv2-SMI::enterprises.789.1.21.1.2.1.11.1 = STRING: "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.12.1 = INTEGER: 2
SNMPv2-SMI::enterprises.789.1.21.1.2.1.13.1 = STRING: "1, 2"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.14.1 = STRING: "NTAPDNH-0801NW0676, NTAPDNH-0801NW0280"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.15.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.16.1 = INTEGER: 2
SNMPv2-SMI::enterprises.789.1.21.1.2.1.17.1 = STRING: "1, 2"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.18.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.19.1 = INTEGER: 4
SNMPv2-SMI::enterprises.789.1.21.1.2.1.20.1 = STRING: "2, 3, 4"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.21.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.22.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.23.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.24.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.25.1 = STRING: "<N/A>, 28C (82F), 25C (77F), 27C (80F)"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.26.1 = STRING: "62C (143F), 62C (143F), 62C (143F), 62C (143F)"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.27.1 = STRING: "54C (129F), 54C (129F), 55C (131F), 55C (131F)"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.28.1 = STRING: "0C (32F), 0C (32F), 0C (32F), 0C (32F)"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.29.1 = STRING: "10C (50F), 10C (50F), 10C (50F), 10C (50F)"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.30.1 = INTEGER: 2
SNMPv2-SMI::enterprises.789.1.21.1.2.1.31.1 = STRING: "2"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.32.1 = STRING: "<N/A>, <N/A>"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.33.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.34.1 = INTEGER: 6
SNMPv2-SMI::enterprises.789.1.21.1.2.1.35.1 = STRING: "1, 2, 3, 4, 5, 6"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.36.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.37.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.38.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.39.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.40.1 = STRING: "12200 mV, 5100 mV, 3540 mV, 12130 mV, 5140 mV, 3530 mV"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.41.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.42.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.43.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.44.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.45.1 = INTEGER: 4
SNMPv2-SMI::enterprises.789.1.21.1.2.1.46.1 = STRING: "1, 2, 3, 4"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.47.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.48.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.49.1 = STRING: "3480 mA, 4080 mA, 3420 mA, 3990 mA"
SNMPv2-SMI::enterprises.789.1.21.1.2.1.50.1 = ""
SNMPv2-SMI::enterprises.789.1.21.1.2.1.51.1 = ""


and I want that file is a file .xml (<path_cacti/ressource/snmp_queries/)

how do it that?

thanks

User avatar
smlick
Cacti User
Posts: 267
Joined: Tue May 20, 2008 4:09 am
Location: Italy, Rome

#9 Post by smlick » Wed Feb 18, 2009 5:28 pm

So if I understand well this is useful only if you need aggregate data and you have to select each interface to do that.
There are other use that I didn't understand?

Regards
Alessio

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#10 Post by gandalf » Fri Feb 20, 2009 3:33 pm

If you are only interested in the "total sum of all indices of an snmptable", please use the approach described here.
If you want to select which indices are aggregated, please use AGGREGATE plugin
Reinhard

swinomish
Posts: 22
Joined: Wed Oct 01, 2008 12:58 pm

#11 Post by swinomish » Wed Apr 22, 2009 11:49 pm

what about using this for Multiple CPU load averages?

C:\>snmpwalk -c public -v 1 10.0.1.156 .1.3.6.1.2.1.25.3.3.1.2
HOST-RESOURCES-MIB::hrProcessorLoad.5 = INTEGER: 6
HOST-RESOURCES-MIB::hrProcessorLoad.6 = INTEGER: 7
HOST-RESOURCES-MIB::hrProcessorLoad.7 = INTEGER: 7
HOST-RESOURCES-MIB::hrProcessorLoad.8 = INTEGER: 5
HOST-RESOURCES-MIB::hrProcessorLoad.9 = INTEGER: 3
HOST-RESOURCES-MIB::hrProcessorLoad.10 = INTEGER: 7
HOST-RESOURCES-MIB::hrProcessorLoad.11 = INTEGER: 2
HOST-RESOURCES-MIB::hrProcessorLoad.12 = INTEGER: 1


Thoughts?
Operating System: 2003 Standard Edition SP2
Webserver: Apache 2.2.6
Cacti: 0.8.7d
Plugin Architecture: cacti-plugin-0.8.7d-PA-v2.4
Installed Plugin: Aggregate-070B2
Installed Plugin: Settings - 0.6
Installed Plugin: Thold - 0.41
MySQL: 5.0.45
PHP: 5.2.4
NET-SNMP: 5.4.2.1-1.win32
RRDTool Win32: 1.2.27-1
phpMyAdmin: 2.11.1

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#12 Post by gandalf » Thu Apr 23, 2009 10:43 am

Was that a question?
It should work with this approach, but I did not test it
Reinhard

swinomish
Posts: 22
Joined: Wed Oct 01, 2008 12:58 pm

#13 Post by swinomish » Thu Apr 23, 2009 10:54 am

yes, it was a question.. It seemed at a glance it would work..

I did try and use this template, but it displays a NaN graph..

I have know clue on how to modify or create the correct CDEF to go from flows to hrProcessorLoad input..

I will study up on CDEFs, as I am having a similiar issues using the aggregate plugin not averaging the totals from my CPU data sources

I see three possible solutions for my single and Multi-CPU grahps..

the snmp-walk template ( I like the all in one graph)
the Multi-CPU template (works out of the box, but too busy/messy)
the aggragete plugin ( I like it best, multiple overlapping colors)
Operating System: 2003 Standard Edition SP2
Webserver: Apache 2.2.6
Cacti: 0.8.7d
Plugin Architecture: cacti-plugin-0.8.7d-PA-v2.4
Installed Plugin: Aggregate-070B2
Installed Plugin: Settings - 0.6
Installed Plugin: Thold - 0.41
MySQL: 5.0.45
PHP: 5.2.4
NET-SNMP: 5.4.2.1-1.win32
RRDTool Win32: 1.2.27-1
phpMyAdmin: 2.11.1

User avatar
gandalf
Developer
Posts: 22375
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

#14 Post by gandalf » Fri Apr 24, 2009 2:28 am

swinomish wrote:yes, it was a question.. It seemed at a glance it would work..

I did try and use this template, but it displays a NaN graph..

I have know clue on how to modify or create the correct CDEF to go from flows to hrProcessorLoad input..
Replace the OID when you create graphs. You will be prompted to enter the OID that should be snmpwalk'ed each time a new graph is created.
Reinhard

alibek
Posts: 33
Joined: Tue Sep 14, 2010 9:35 am

Re: Generic SNMPwalk to retrieve multiple values in one run

#15 Post by alibek » Fri Oct 22, 2010 9:05 am

How can I get multiple OIDs at a time?
At the bash I can do this:

Code: Select all

#snmpget -v 2c -c cybercom 10.1.9.100 .1.3.6.1.2.1.2.2.1.5.25 .1.3.6.1.2.1.2.2.1.10.25 .1.3.6.1.2.1.2.2.1.16.25 .1.3.6.1.2.1.16.1.1.1.5.25 .1.3.6.1.2.1.17.4.4.1.4.25
IF-MIB::ifSpeed.25 = Gauge32: 1000000000
IF-MIB::ifInOctets.25 = Counter32: 1602140694
IF-MIB::ifOutOctets.25 = Counter32: 2679750227
RMON-MIB::etherStatsPkts.25 = Counter32: 375429348 Packets
SNMPv2-SMI::mib-2.17.4.4.1.4.25 = Counter32: 301816916
and as a team to get multiple values.
However, in the server script so I can not do that. Function cacti_snmp_get function does not work with arrays. So I have several times to call this function for different OID, instead, to get their list.
This method does not work:

Code: Select all

cacti_snmp_get($hostname, $snmp_community, implode(" ", array_values($oids)), $snmp_version

Post Reply