Page 1 of 2
SNMP Divide...
Posted: Fri Apr 29, 2016 5:10 pm
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
Re: SNMP Divide...
Posted: Sun May 01, 2016 11:32 pm
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

)
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.
Re: SNMP Divide...
Posted: Mon May 02, 2016 10:01 am
by spyder13337
i got the our put of this
External command error with no output (return code: 3)- 0|=0
Re: SNMP Divide...
Posted: Mon May 02, 2016 3:07 pm
by spyder13337
nevermind it works you are the best i dont care what anybody said... it was my falut snmp config correct
Re: SNMP Divide...
Posted: Mon May 02, 2016 3:13 pm
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
Re: SNMP Divide...
Posted: Mon May 02, 2016 4:19 pm
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?
Re: SNMP Divide...
Posted: Mon May 02, 2016 5:17 pm
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
Re: SNMP Divide...
Posted: Mon May 02, 2016 7:03 pm
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.
Re: SNMP Divide...
Posted: Wed May 04, 2016 4:24 pm
by spyder13337
thank that worked perfectly you guys are the best
Re: SNMP Divide...
Posted: Wed May 04, 2016 4:53 pm
by tgriep
If you don't have any more questions, shall we close and lock this post?