Page 1 of 1

check_snmp return STRING value

Posted: Mon Jun 26, 2017 1:15 am
by scagno83
Hi All,

I would like to know if exists some option for check_snmp plugin in order to convert the STRING return value to float/decimal value.
Below an example with the check_snmp v1.4.15 belonging to the nagios-plugins 1.4.15 pkg.

Code: Select all

[nagios@nagios nagios]$ /usr/lib64/nagios/plugins/check_snmp -H A.B.C.D. -o .1.3.6.1.4.1.4466.1.2.10.1.1.1.2.1.9.1392508928
SNMP OK - "+18.30" |
and if I perform the snmpget

Code: Select all

[nagios@nagios sklmed]$ snmpget -v 2c -c public 172.16.198.95 .1.3.6.1.4.1.4466.1.2.10.1.1.1.2.1.9.1392508928
SNMPv2-SMI::enterprises.4466.1.2.10.1.1.1.2.1.9.1392508928 = STRING: "+18.30"
Thank you in advance for any suggestion.

Best regards,

Re: check_snmp return STRING value

Posted: Mon Jun 26, 2017 10:45 am
by tmcdonald
Well technically speaking any output that comes from a Nagios plugin is going to be a string. What is your use case here? If you are looking to modify the plugin source code you can find it here: https://github.com/nagios-plugins/nagio ... eck_snmp.c

Otherwise it could be pretty trivial to write a wrapper script in Python or something to parse that string into an integer.

Re: check_snmp return STRING value

Posted: Tue Jun 27, 2017 7:07 am
by scagno83
Hi tmcdonald

thank you for your feedback.
I am tring to explain better my case.
If I ask to a dated device the result of a parameter (via the nagios plugin check_snmp) I get a STRING

Code: Select all

/usr/lib64/nagios/plugins/check_snmp -H A.B.C.D -o .1.3.6.1.4.1.4466.1.2.10.1.1.1.2.1.9.1392508928
SNMP OK - "+18.30" |
equivalent snmpget is

Code: Select all

snmpget -v2c -c public A.B.C.D .1.3.6.1.4.1.4466.1.2.10.1.1.1.2.1.9.1392508928
SNMPv2-SMI::enterprises.4466.1.2.10.1.1.1.2.1.9.1392508928 = STRING: "+18.30"
If I ask to updated device (same brand) the result of the same parameter I get a INTEGER

Code: Select all

[nagios@nagios ~]$ /usr/lib64/nagios/plugins/check_snmp -H A.B.C.D -o .1.3.6.1.4.1.1563.4466.1.1.1.3.1.1.1.1.1.1.1.1.1.9.289406977
SNMP OK - 1540 | iso.3.6.1.4.1.1563.4466.1.1.1.3.1.1.1.1.1.1.1.1.1.9.289406977=1540
equivalent snmpget is

Code: Select all

[nagios@nagios ~]$ snmpget -v2c -c public 172.21.181.31 .1.3.6.1.4.1.1563.4466.1.1.1.3.1.1.1.1.1.1.1.1.1.9.289406977
SNMPv2-SMI::enterprises.1563.4466.1.1.1.3.1.1.1.1.1.1.1.1.1.9.289406977 = INTEGER: 1525
I understand that the best solution is to write a wrapper. Do you confirm this?

Re: check_snmp return STRING value

Posted: Tue Jun 27, 2017 2:54 pm
by tgriep
When you run the snmpget command, the output(STRING or INTEGER) is telling you that the OID you are polling is a String or an Integer but of you want to change the output of the plugin to a different value, you would have to write a wrapper.

Re: check_snmp return STRING value

Posted: Fri Jun 30, 2017 9:42 am
by scagno83
Thank you for your reply tgriep.

Are there some best practices to follow in order to write a wrapper of Nagios plugin?

Re: check_snmp return STRING value

Posted: Fri Jun 30, 2017 11:40 am
by tgriep
You may want to look at the plugin development guide at the link below for formatting specifications.
https://nagios-plugins.org/doc/guidelines.html