check_snmp return STRING value

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
scagno83
Posts: 5
Joined: Thu Jan 30, 2014 9:49 am

check_snmp return STRING value

Post 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,
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: check_snmp return STRING value

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

Re: check_snmp return STRING value

Post 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?
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: check_snmp return STRING value

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
scagno83
Posts: 5
Joined: Thu Jan 30, 2014 9:49 am

Re: check_snmp return STRING value

Post by scagno83 »

Thank you for your reply tgriep.

Are there some best practices to follow in order to write a wrapper of Nagios plugin?
User avatar
tgriep
Madmin
Posts: 9177
Joined: Thu Oct 30, 2014 9:02 am

Re: check_snmp return STRING value

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked