Discussion:
returning an integer value for extend script?
(too old to reply)
Angelo Höngens
2010-10-09 09:47:32 UTC
Permalink
Hey,

I use net-snmp extend scripts a lot in my organization to monitor all kinds of values on linux, freebsd and windows servers, and that's been working great with cacti so far. However, net-snmp seems to return only string datatypes instead of integers. It's not a problem for Cacti, since it automatically does string-to-integer conversion, but I'm starting out with nagios and other software, and it really has problems.

Example:

This extend line:
extend .1.3.6.1.4.1.2021.54.101.0 test "/bin/echo 123"

Gets me the following return value:
UCD-SNMP-MIB::ucdavis.54.101.0.4.1.2.4.116.101.115.116.1 = STRING: "123"

Is there a way I can force net-snmp to return an integer value?
--
With kind regards,


Angelo Höngens

Systems Administrator

------------------------------------------
NetMatch
tourism internet software solutions

Ringbaan Oost 2b
5013 CA Tilburg
T: +31 (0)13 5811088
F: +31 (0)13 5821239

mailto:***@netmatch.nl
http://www.netmatch.nl
------------------------------------------
Dave Shield
2010-10-09 10:22:55 UTC
Permalink
Post by Angelo Höngens
Is there a way I can force net-snmp to return an integer value?
Use the return code of the script, rather than the output
See UCD-SNMP-MIB::extResult or NET-SNMP-MIB::nsExtendResult

Dave
Angelo Höngens
2010-10-09 16:01:02 UTC
Permalink
Post by Dave Shield
Post by Angelo Höngens
Is there a way I can force net-snmp to return an integer value?
Use the return code of the script, rather than the output
See UCD-SNMP-MIB::extResult or NET-SNMP-MIB::nsExtendResult
Dave
I'm not quite sure what you mean. I only get string values back:

$ snmpwalk -v 1 -c public localhost 1.3.6.1.4.1.2021.54
UCD-SNMP-MIB::ucdavis.54.101.0.1.0 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.2.4.116.101.115.116 = STRING:
"/bin/echo 123"
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.3.4.116.101.115.116 = ""
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.4.4.116.101.115.116 = ""
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.5.4.116.101.115.116 = INTEGER: 5
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.6.4.116.101.115.116 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.7.4.116.101.115.116 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.20.4.116.101.115.116 = INTEGER: 4
UCD-SNMP-MIB::ucdavis.54.101.0.2.1.21.4.116.101.115.116 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.1.4.116.101.115.116 = STRING: "123"
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.2.4.116.101.115.116 = STRING: "123"
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.3.4.116.101.115.116 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.4.4.116.101.115.116 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.54.101.0.4.1.2.4.116.101.115.116.1 = STRING: "123"
--
With kind regards,


Angelo Höngens
systems administrator

MCSE on Windows 2003
MCSE on Windows 2000
MS Small Business Specialist
------------------------------------------
NetMatch
tourism internet software solutions

Ringbaan Oost 2b
5013 CA Tilburg
+31 (0)13 5811088
+31 (0)13 5821239

***@netmatch.nl
www.netmatch.nl
------------------------------------------
h***@gmail.com
2017-10-11 08:24:07 UTC
Permalink
By 'return code' he means exit code of a bash script.

#!/bin/sh
exit <your_value>

But the limitation is one Byte, meaning values from 0-255.

Dave Shield
2010-10-10 19:17:42 UTC
Permalink
Post by Angelo Höngens
Post by Dave Shield
Use the return code of the script, rather than the output
See  UCD-SNMP-MIB::extResult or NET-SNMP-MIB::nsExtendResult
$ snmpwalk -v 1 -c public localhost 1.3.6.1.4.1.2021.54
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.1.4.116.101.115.116 = STRING: "123"
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.2.4.116.101.115.116 = STRING: "123"
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.3.4.116.101.115.116 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.54.101.0.3.1.4.4.116.101.115.116 = INTEGER: 0
No - you get two string values ("123" and "123"), and two integer
values (1 and 0)

If you define the same extension command rooted at the default location
(NET-SNMP-EXTEND-MIB::nsExtendObjects), the results would be shown
as follows:


NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."test" = STRING: "123"
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."test" = STRING: "123"
NET-SNMP-EXTEND-MIB::nsExtendOutputNumLines."test" = INTEGER: 1
NET-SNMP-EXTEND-MIB::nsExtendResult."test" = INTEGER: 0


Try with
extend .1.3.6.1.4.1.2021.54.101.0 test "exit 123"
or
extend test "exit 123"

Dave
Angelo Höngens
2010-10-11 17:30:24 UTC
Permalink
Post by Dave Shield
No - you get two string values ("123" and "123"), and two integer
values (1 and 0)
If you define the same extension command rooted at the default location
(NET-SNMP-EXTEND-MIB::nsExtendObjects), the results would be shown
NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."test" = STRING: "123"
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."test" = STRING: "123"
NET-SNMP-EXTEND-MIB::nsExtendOutputNumLines."test" = INTEGER: 1
NET-SNMP-EXTEND-MIB::nsExtendResult."test" = INTEGER: 0
Try with
extend .1.3.6.1.4.1.2021.54.101.0 test "exit 123"
or
extend test "exit 123"
Dave
Thanks, it's an excellent workaround, and works like a charm!
--
With kind regards,


Angelo Höngens
systems administrator

MCSE on Windows 2003
MCSE on Windows 2000
MS Small Business Specialist
------------------------------------------
NetMatch
tourism internet software solutions

Ringbaan Oost 2b
5013 CA Tilburg
+31 (0)13 5811088
+31 (0)13 5821239

***@netmatch.nl
www.netmatch.nl
------------------------------------------
Loading...