SNMP Divide...

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.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

SNMP Divide...

Post by spyder13337 »

Hello Everybody

i need to monitor a APC switched i already config the ip and snmp community on the powerstrip AP7830 and AP7932 so i config snmp to monitor and i already it monitoring but the issue is i need to divide by 100 the output result since it is coming from snmp is there a way to divide the result by 100 or is this a plugin that works because i could not find one that seem to work

this is my service

define service{
use generic-service,srv-pnp
service_description Total Load
check_command check_snmp!1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1
max_check_attempts 3
check_interval 5
retry_interval 1
check_period workhours
hostgroup APC
notification_interval 60
notification_period workhours
contacts nagiosadmin


my command


# 'check_snmp' command definition
define command{
command_name check_snmp
command_line $USER1$/check_snmp -H $HOSTADDRESS$ -C XXXXXX -o $ARG1$


i get out result like this

./check_snmp -H x.x.x.x -C XXXXX -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1
SNMP OK - 94 | iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=94

now the result need to be divided by 100 i.e 9.4 which is the most idea scenario

any feedback or help will be appreciated
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: SNMP Divide...

Post by Box293 »

You know I keep thinking that the check_snmp plugin needs a divide or multiple argument.

Anyway, today I learned how to use awk which can do what you want (my head hurts now :lol:)

I'm not sure if this will affect the exit codes from Nagios if you introduced warning and critical thresholds.

This:

Code: Select all

./check_snmp -H x.x.x.x -C XXXXX -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
Should produce:

Code: Select all

SNMP OK - 9.4 | iso.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1=9.4 
94 divide 10 = 9.4

Just change the /10 values if you want the decimal place shifted.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: SNMP Divide...

Post by spyder13337 »

i got the our put of this

External command error with no output (return code: 3)- 0|=0
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: SNMP Divide...

Post by spyder13337 »

nevermind it works you are the best i dont care what anybody said... it was my falut snmp config correct
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: SNMP Divide...

Post by spyder13337 »

let me rephrase it work just like that but i need to see of nagios con take the command and display it as it should
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: SNMP Divide...

Post by rkennedy »

You'll want to create a wrapper script, and have it run the check_snmp script. That way, it'll appear as you're looking for in the interface. For example -

check_snmp_apc_custom.sh -

Code: Select all

#!/bin/bash
./check_snmp -H x.x.x.x -C XXXXX -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
Then, assign a command to Nagios so that it uses the above, and then assign that command to the specific service. You may need to write out a few different bash scripts (or integrate dynamic variables) for the different APC's.

Is that what you were looking for?
Former Nagios Employee
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: SNMP Divide...

Post by spyder13337 »

basically what i was looming for a more of a number that display like 9.4 amps instead of 94 which either way i can make adjustment but i prefer to use 9.4... but it seem you are telling me that you want me to create a wrapper script called "check_snmp_apc_custom.sh" which runs command "./check_snmp -H x.x.x.x -C XXXXX -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'"


then assign a command to it thru command.cfg and a service.cfg can i get a quick examples pf these i think i understand but would like some clarification on them. Once i understadn the process i can create i couple more

thank you for all your help everybody
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: SNMP Divide...

Post by Box293 »

Command:

Code: Select all

define command{
command_name check_snmp_apc_custom
command_line $USER1$/check_snmp_apc_custom.sh
}
In your service you would have:

Code: Select all

check_command check_snmp_apc_custom
Basically the wrapper script means that you would need a separate script per device, as your script has hard coded in the address for the device.

You could submit $HOSTADDRESS$ as well, however then you would need to code the script to get the address provided to it.

Code: Select all

define command{
command_name check_snmp_apc_custom
command_line $USER1$/check_snmp_apc_custom.sh $HOSTADDRESS$
}

Code: Select all

#!/bin/bash
hostaddress=$1
./check_snmp -H $hostaddress -C XXXXX -o .1.3.6.1.4.1.318.1.1.12.2.3.1.1.2.1 | awk -F'|' '{split($1,array_left,"-");} {split($2,array_right,"=");} {print array_left[1]"- "array_left[2]/10"|"array_right[1]"="array_right[2]/10;}'
Something like that.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
spyder13337
Posts: 68
Joined: Tue Oct 06, 2015 9:50 pm

Re: SNMP Divide...

Post by spyder13337 »

thank that worked perfectly you guys are the best
User avatar
tgriep
Madmin
Posts: 9190
Joined: Thu Oct 30, 2014 9:02 am

Re: SNMP Divide...

Post by tgriep »

If you don't have any more questions, shall we close and lock this post?
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked