Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Fri Apr 28, 2017 8:47 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Generic SNMPwalk to retrieve multiple values in one run
PostPosted: Mon Dec 08, 2008 4:22 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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:
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:
<?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:
File comment: The Graph Template XML (including the Data Template and Data Input Method)
cacti_graph_template_snmp_-_total_all_values_of_snmpwalk.xml [20.73 KiB]
Downloaded 2035 times
File comment: The Script. Download to ./scripts directory and remove .txt extension
ss_total_snmpwalk.php.txt [1.6 KiB]
Downloaded 1776 times
File comment: The Data Input Method
Data Input Method.png
Data Input Method.png [ 64.09 KiB | Viewed 46997 times ]
File comment: The Graph Example for Total Flows of an Enterasys N7 Switch
Total Flows.png
Total Flows.png [ 26.17 KiB | Viewed 46997 times ]

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Last edited by gandalf on Sat Jan 31, 2009 12:05 pm, edited 3 times in total.
Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2009 5:29 am 
Offline

Joined: Thu Dec 18, 2008 4:59 am
Posts: 4
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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 2:55 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
Oops, will provide the script as a download file tomorrow.
Reinhard

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2009 7:33 am 
Offline

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

Where is the download file?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2009 3:41 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
The file was posted inline. But for convenience, I added it now to the downloads. Please remove the .txt extension after download
Reinhard

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: RE : Generic SNMPwalk to retrieve multiple values in one run
PostPosted: Thu Jan 29, 2009 1:57 am 
Can you provide me that downloading file?


Top
  
 
 Post subject:
PostPosted: Sat Jan 31, 2009 12:07 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
The XML file was updated due to malformed XML
Reinhard

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2009 6:16 pm 
Offline
Cacti User

Joined: Tue Jan 27, 2009 5:41 am
Posts: 64
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 5:28 pm 
Offline
Cacti User
User avatar

Joined: Tue May 20, 2008 4:09 am
Posts: 266
Location: Italy, Rome
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2009 3:33 pm 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 22, 2009 11:49 pm 
Offline

Joined: Wed Oct 01, 2008 12:58 pm
Posts: 22
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 23, 2009 10:43 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
Was that a question?
It should work with this approach, but I did not test it
Reinhard

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 23, 2009 10:54 am 
Offline

Joined: Wed Oct 01, 2008 12:58 pm
Posts: 22
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 24, 2009 2:28 am 
Offline
Developer
User avatar

Joined: Thu Dec 02, 2004 2:46 am
Posts: 22461
Location: Muenster, Germany
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

_________________
Official Cacti Documentation
Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
 Post subject: Re: Generic SNMPwalk to retrieve multiple values in one run
PostPosted: Fri Oct 22, 2010 9:05 am 
Offline

Joined: Tue Sep 14, 2010 9:35 am
Posts: 33
How can I get multiple OIDs at a time?
At the bash I can do this:
Code:
#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:
cacti_snmp_get($hostname, $snmp_community, implode(" ", array_values($oids)), $snmp_version


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group