check_snmp return STRING value

This forum is intended for the discussion of Nagios plugin development. Feature requests, patches, bug fixes, and all types of development-related discussions are welcome!

NOTE: The SourceForge.net nagiosplug-devel mailing list has been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

check_snmp return STRING value

Postby scagno83 » Mon Jun 26, 2017 1:15 am

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,
scagno83
 
Posts: 5
Joined: Thu Jan 30, 2014 9:49 am

Re: check_snmp return STRING value

Postby tmcdonald » Mon Jun 26, 2017 10:45 am

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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tmcdonald
Support Manager
 
Posts: 8544
Joined: Mon Sep 23, 2013 8:40 am

Re: check_snmp return STRING value

Postby scagno83 » Tue Jun 27, 2017 7:07 am

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?
scagno83
 
Posts: 5
Joined: Thu Jan 30, 2014 9:49 am

Re: check_snmp return STRING value

Postby tgriep » Tue Jun 27, 2017 2:54 pm

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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 5634
Joined: Thu Oct 30, 2014 9:02 am

Re: check_snmp return STRING value

Postby scagno83 » Fri Jun 30, 2017 9:42 am

Thank you for your reply tgriep.

Are there some best practices to follow in order to write a wrapper of Nagios plugin?
scagno83
 
Posts: 5
Joined: Thu Jan 30, 2014 9:49 am

Re: check_snmp return STRING value

Postby tgriep » Fri Jun 30, 2017 11:40 am

You may want to look at the plugin development guide at the link below for formatting specifications.
https://nagios-plugins.org/doc/guidelines.html
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
tgriep
Madmin
 
Posts: 5634
Joined: Thu Oct 30, 2014 9:02 am


Return to Nagios Plugin Development

Who is online

Users browsing this forum: No registered users and 1 guest