Check_snmp wrapper divide by x


#1

hallo an alle,
ich versuche gerade einen wrapper für check_snmp zu bauen.
habe einen Code für meine aufgabe gefunden, aber dieser macht mir Probleme weil das parsen so nicht klappt
http://sites.box293.com/nagios/guides/tricks/string-manipulation

wenn ich einen check mache, bekomme ich kein = wo ich den wert ändern könnte

/usr/lib/nagios/plugins/check_snmp -H 192.168.1.102 -C public -o 1.3.6.1.4.1.36791.2.1.3
SNMP OK - “0001159680” | <<

bei snmpget:

snmpget -v 1 -c public 192.168.1.102 1.3.6.1.4.1.36791.2.1.3
iso.3.6.1.4.1.36791.2.1.3 = STRING: “0001170596”<<

/usr/lib/nagios/plugins/check_snmp -H 192.168.1.102 -C public -o 1.3.6.1.4.1.36791.2.1.3 | awk ‘{print $1,$2,$3,$4/1000,$5}’
gibt mir
SNMP OK - 0 |

ich will den wert einfach nur durch 1000 dividieren;

könnt ihr mir helfen?
danke und gruß


#2

It’s not approved yet but you might want to test a pull request for check_snmp.

BTW: Please switch to english so others can follow as well.


#3

thanks for your reply.
i did some seaching and found that i need a wrapper to manipulate the check_snmp check output.
so i made following things.

check_ipswitch (wrapperfile)
#!/bin/bash
/usr/lib/nagios/plugins/check_snmp | awk -F" ‘{print $1 $2/1000 $3}’
<

if i use this manually i get the expected result; just one Thing that disturbes me is the pipe behind unit

/usr/lib/nagios/plugins/check_snmp -H 192.168.1.102 -o 1.3.6.1.4.1.36791.2.1.3 -l label -u unit | awk -F" ‘{print $1 $2/1000 $3}’
SNMP OK - label 1225.26 unit |

command.conf
object CheckCommand “check_ipswitch_smnp” {
import “plugin-check-command”
command = [ PluginDir + “/check_ipswitch_smnp” ]
arguments = {
“-H” = “$snmp_address$”
“-o” = “$snmp_oid$”
“-C” = “$snmp_community$”
“-t” = “$snmp_timeout$”
“-e” = “$snmp_retries$”
“-u” = “$snmp_units$”
“-l” = “$snmp_label$”
“-P” = “$snmp_version$”
}

}
<

host.conf
object Host “ipswitch-kwh.1.local” {
address = “192.168.1.102”
check_command = “hostalive”
vars.client_endpoint = “raspberrypi.local”
//basis snmp daten
vars.snmp_community = “public”
vars.snmp_version = “1”
vars.snmp_timeout = “10”
vars.snmp_retries = “3”
}
object Service “Sensor_S0_1” {
host_name = “ipswitch-kwh.1.local”
import “generic-service”
check_command = “check_ipswitch_smnp”
// spezifische daten
vars.snmp_oid = “1.3.6.1.4.1.36791.2.1.3”
#vars.snmp_label = “Sensor_S0_1_Z-Stand”
vars.snmp_units = “kwH”
command_endpoint = host.vars.client_endpoint
}
<

i want to review the data for longterm analytics in graphana later on
i cant get the values to the wrapper script… please give me a hint… maybe i did it all wrong …


#4

Looking here you’ll find that the pipe symbol separates plugin output from performance data so you’ve to add the necessary information.

Edit: attached you’ll find the compiled binary of check_snmp as mentioned above. Adding -M 0.001 -f "%.f" to your call you’ll probably get the result you’re seeking. check_snmp.tgz (183.7 KB)


#5

Thanks Wolfgang but the provided tgz will not work since the Computer doing the checks is a Raspberry.

I still have Problems getting the Host and Service Variables to the check script.

host.conf

object Host “ipswitch-kwh.1.local” {
address = “192.168.1.102”
check_command = “ping4”
vars.client_endpoint = “raspberrypi.local”
//basis snmp daten
vars.snmp_community = “public”
vars.snmp_version = “1”
vars.snmp_timeout = “10”
vars.snmp_retries = “3”
}
object Service “Sensor_S0_1” {
host_name = “ipswitch-kwh.1.local”
import “generic-service”
check_command = “check_ipswitch_smnp”
// spezifische daten
vars.snmp_oid = “1.3.6.1.4.1.36791.2.1.3”
vars.snmp_label = “Sensor_S0_1_Z-Stand”
vars.snmp_units = “kwH”
command_endpoint = host.vars.client_endpoint

command.conf

object CheckCommand “check_ipswitch_smnp” {
import “plugin-check-command”
command = [ PluginDir + “check_ipswitch_smnp” ]
}

check_ipswitch_smnp - “script”

#!/bin/bash
snmp=$(/usr/lib/nagios/plugins/check_snmp -H $address$ -o $Service.vars.snmp_oid$ | awk -F" ‘{print $1 $2/1000}’)
echo $snmp

Maybe anyone can put me in the Right direction…tried a lot of variants but i cant get it to work :frowning:


(watermelon) #6

snmp=$(/usr/lib/nagios/plugins/check_snmp -H $address$ -o $Service.vars.snmp_oid$ | awk -F" ‘{print $1 $2/1000}’)

How would this script know what the parameters (address, service.vars.snmp_oid) are?

You need to
1) set up an arguments section in your CheckCommand to pass these arguments into your wrapper script
2) add a section in your wrapper script to handle arguments.

Check this howto out I did a little while ago, it should have all the information you need as far as script wrapping (though the example given is slightly different than your situation).


#7

hello and thanks for your input
i changed the command.conf like so

object CheckCommand “check_ipswitch_smnp” {
import “plugin-check-command”
command = [ PluginDir + “check_ipswitch_smnp” ]
arguments = {
“-H” = “$hostname$”
“-o” = “$snmp_oid$”
}
}

and the check-wrapper

#!/bin/bash
while getopts “:H:o:” option; do
case “${option}” in
H) hostname=${OPTARG};;
o) oid=${OPTARG};;
*) usage;;
esac
done
snmp=$(/usr/lib/nagios/plugins/check_snmp -H ${hostname} -o ${oid} | awk -F" ‘{print $1 $2/1000}’)
echo $snmp

still not working, i do not really understand how the handle should work … i am confused with the $variables how they find togehter in the check wrapper :disappointed_relieved:


#8

The output of the plugin call should give all the information you need so awk only has to be print some text and variables.