SNMP output (move decimal place?)

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
devildog31415
Posts: 48
Joined: Thu Jun 12, 2014 10:55 am

SNMP output (move decimal place?)

Post by devildog31415 »

My temp sensor, and humidity sensor comes out as an integer that requires me to recognize that the decimal has to be moved.
Example.. if the temp is 65.75 F then the SNMP sends me 6575

Here is an example:
./check_snmp -H 172.24.52.130 -p 161 -o .1.3.6.1.4.1.20916.1.9.1.1.1.2.0 -C public -P 1 -l "Temperature" -u "F" -m ROOMALERT3E -w 7100 -c 7500
SNMP OK - Temperature 6575 F | Temperature=6575F;7100;7500;

I don't want my alerts to be something that the actual info has to be extrapolated. What can I do to either:
1) get the reply down to just first 2 digits OR
2) get the decimal place moved so it's correct for
a) notifications/emails
b) graphing

Thank you
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: SNMP output (move decimal place?)

Post by sreinhardt »

Unfortunately, man I'm using that a lot today.., check_snmp will only report the values that the device it is querying responds with, reason being that we(N-P devs and plugins) should never assume what the actual value your device is intended to be, but instead need to respect what it replies with.

You are welcome to take a look at the code and modify it to something that will work better for you, but I would honestly suggest a wrapper script that finds any 3+ digit numbers and inserts a period after the first two, this is presuming that you won't hit 100+. You could also work it the opposite way if you know that it will always return two points of precision after the whole number, and instead place the period before the last two numbers, this would have the advantage of being more flexible if heat becomes a real issue. The only other thing you would need to do is relay the exit code from the original plugin, and output the modified string.

You might also try working with check_snmp or snmpget to correctly pull in your mib, and that might redefine it for both binaries and tell them to interpret it as a float.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
devildog31415
Posts: 48
Joined: Thu Jun 12, 2014 10:55 am

Re: SNMP output (move decimal place?)

Post by devildog31415 »

That makes sense.
If I make a wrapper script.. that means I will have to learn how to make sure the new check passes info to be graphed as well, is that correct?
If so, can you help me understand what I'm getting into?
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: SNMP output (move decimal place?)

Post by Box293 »

devildog31415 wrote:If I make a wrapper script.. that means I will have to learn how to make sure the new check passes info to be graphed as well, is that correct?
Yes you are right.

You'll be receiving something like:

Code: Select all

SNMP OK - Temperature 6575 F | Temperature=6575F;7100;7500;
You need to fix the values in the string.
After "Temperate" followed by a space.
After "Temperate" followed by an equals sign (make sure you keep the F.
Values between two semi columns ;;

So you'll end up with:

Code: Select all

SNMP OK - Temperature 65.75 F | Temperature=65.75F;71.00;75.00;
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: SNMP output (move decimal place?)

Post by tmcdonald »

To expand on what Box said:

You see the pipe character "|" in there? Everything before that pipe is what you would see in the Status Information field. It's just plain text that a human can read. Everything after the pipe is the performance data that gets graphed. In this case, the first number is the actual temp, the number after the semi-colon is the warning threshold, and the number after the second semi-colon is the critical. All of this will be output as plain text if you run the check from the command line.

Now what you don't see is the exit code, which is what tells Nagios what the status is - OK, Warning, or Critical. I believe we dealt with this in a remote session and the concept is the same. The exit code is never displayed on the screen in normal usage, but your wrapper script (assuming it is a bash shell script) can easily get the value just as it did in your other script by using the `backticks` around the command and assigning that to a variable.

So status info, perfdata, and exit code are the only things you need to worry about.
Former Nagios employee
Locked