Chapter V: Extending the Net-SNMP agent
A great functionnality of Net-SNMP is that you can "extend" it.
Let's run the /tmp/foo.sh script :
| Code: |
$ /tmp/foo.sh -arg1 123 |
Now put this in snmpd.conf :
| Code: |
exec foo /bin/sh /tmp/foo.sh -arg1 |
The result of your script will be accessible under the ucdavis.extTable.extEntry tree :
- output of the script : ucdavis.extTable.extEntry.extOutput
- exit status : ucdavis.extTable.extEntry.extResult
- command : ucdavis.extTable.extEntry.extCommand
You can check the result with this SNMP query :
| Code: |
$ snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.8.1 UCD-SNMP-MIB::extIndex.1 = INTEGER: 1 UCD-SNMP-MIB::extNames.1 = STRING: foo UCD-SNMP-MIB::extCommand.1 = STRING: /bin/sh /tmp/foo.sh -arg1 UCD-SNMP-MIB::extResult.1 = INTEGER: 0 UCD-SNMP-MIB::extOutput.1 = STRING: 123 UCD-SNMP-MIB::extErrFix.1 = INTEGER: 0 UCD-SNMP-MIB::extErrFixCmd.1 = STRING: |
extOutput translates to .1.3.6.1.4.1.2021.8.1.101
As "foo" is our first exec directive, add ".1" at the end of the OID.
In Cacti, use the "SNMP - Generic OID Template" like this :

Voila ! Result of the /tmp/foo.sh script is now graphed in Cacti.
Now let's run this second script, which returns more than one result :
| Code: |
$ /tmp/bar.sh 456 789 |
It returns two values, one per line (this is important).
Another way to call scripts from snmpd.conf is by specifying an OID, like this :
| Code: |
exec .1.3.6.1.4.1.2021.555 /bin/sh /tmp/bar.sh |
Run this query :
| Code: |
$ snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.555 UCD-SNMP-MIB::ucdavis.555.1.1 = INTEGER: 1 UCD-SNMP-MIB::ucdavis.555.2.1 = STRING: "/bin/sh" UCD-SNMP-MIB::ucdavis.555.3.1 = STRING: "/tmp/bar.sh" UCD-SNMP-MIB::ucdavis.555.100.1 = INTEGER: 0 UCD-SNMP-MIB::ucdavis.555.101.1 = STRING: "456" UCD-SNMP-MIB::ucdavis.555.101.2 = STRING: "789" UCD-SNMP-MIB::ucdavis.555.102.1 = INTEGER: 0 UCD-SNMP-MIB::ucdavis.555.103.1 = "" |
First line returned by the script will be available at .1.3.6.1.4.1.2021.555.2, and so on.
You can then use the "SNMP - Generic OID Template" in Cacti (one Data Source per OID).
Let's say you want to count the number of entries in a log file.
Add this to snmpd.conf :
| Code: |
logmatch cactistats /home/cactiuser/cacti/log/cacti.log 120 SYSTEM STATS |
- the global count of matches will be available under the .1.3.6.1.4.1.2021.16.2.1.5.1 OID
- the "Regex match counter" (which is reset with each file rotation) will be available under the .1.3.6.1.4.1.2021.16.2.1.7.1 OID
To list all the available variables, use this query :
| Code: |
$ snmpwalk -v 1 -c public localhost logMatch UCD-SNMP-MIB::logMatchMaxEntries.0 = INTEGER: 50 UCD-SNMP-MIB::logMatchIndex.1 = INTEGER: 1 UCD-SNMP-MIB::logMatchName.1 = STRING: cactistats UCD-SNMP-MIB::logMatchFilename.1 = STRING: /home/cactiuser/cacti/log/cacti.log UCD-SNMP-MIB::logMatchRegEx.1 = STRING: SYSTEM STATS UCD-SNMP-MIB::logMatchGlobalCounter.1 = Counter32: 301634 UCD-SNMP-MIB::logMatchGlobalCount.1 = INTEGER: 301634 UCD-SNMP-MIB::logMatchCurrentCounter.1 = Counter32: 6692 UCD-SNMP-MIB::logMatchCurrentCount.1 = INTEGER: 6692 UCD-SNMP-MIB::logMatchCounter.1 = Counter32: 1 UCD-SNMP-MIB::logMatchCount.1 = INTEGER: 0 UCD-SNMP-MIB::logMatchCycle.1 = INTEGER: 120 UCD-SNMP-MIB::logMatchErrorFlag.1 = INTEGER: 0 UCD-SNMP-MIB::logMatchRegExCompilation.1 = STRING: Success |
We'll then use another interesting directive, the "proxy" one.
Let's take for example the Squid proxy : when enabled, its SNMP agent listen to UDP 3401 port.
If you want to have system graphs and Squid graphs without declaring 2 devices in Cacti, add this in snmpd.conf :
| Code: |
proxy -v 1 -c public localhost:3401 .1.3.6.1.4.1.3495.1 |
The Squid SNMP tree will be available under the .1.3.6.1.4.1.3495.1 branch.
Let's query this host :
| Code: |
$ snmpwalk -v 1 -c public 10.151.33.3 sysdescr SNMPv2-MIB::sysDescr.0 = STRING: Linux srv1.foo.com 2.6.8.1-12mdk #1 Fri Oct 1 12:53:41 CEST 2004 i686 |
And here's the Squid part (this specific OID returns the Squid version) :
| Code: |
$ snmpwalk -v 1 -c public 10.151.33.3 .1.3.6.1.4.1.3495.1.2.3.0 SNMPv2-SMI::enterprises.3495.1.2.3.0 = STRING: "2.5.STABLE6" |
You'll find how to enable the Squid SNMP agent here.





