Comments on How to Write a Custom Nagios Check Plugin
Even though Nagios Exchange has thousands of available plugins to freely download, sometimes the status needed to be checked is very specific for your scenario.
10 Comment(s)
Comments
I don't know if it's best practice or not , but i would declare count Warnings as an integer variable when doing arithmetic operations
Hi, thanks for your comment. I just used that simple script as an example, any language can be used to write your own custom plugin.
Nevertheless, in response to your comment, I don't think there's an error in that, as Bash variables are untyped. Please refer to http://tldp.org/LDP/abs/html/untyped.html
hi! i'm very new on that kind of progamming... what does this line "
countWarnings=$(/usr/local/nagios/bin/nagiostats | grep "Ok/Warn/Unk/Crit:" | sed 's/[[:space:]]//g' | cut -d"/" -f5)" means i really want to lear some but i need help ... please helpme
Hello, basically variable
countWarningswill hold the return value of commands between $( ... ). nagiostats provides statistics of which only the part `Services Ok/Warn/Unk/Crit: 8 / 0 / 0 / 0` are interesting to us, so we are using grep to extract this line. Then we are removing spaces using sed and finally cut the appropriate field using cut, i this case field 5 is what we want.
If you want know more, just read and play with:
man bash
man grep
man cut
man sed
Hope this helps,
cheers!
Hi there,
I'm new to shell and would like to understand and adapt your script... would you comment on why this particular adaptation wont work (results unknown - 0 regardless of input parameter sent by the user)
#!/bin/bash
warn=$1
crit=$2
countWarnings=$(/usr/local/nagios/bin/nagiostats | grep "Ok/Warn/Unk/Crit:" | sed 's/[[:space:]]//g' | cut -d"/" -f5)
if [ -z "$1" ]; then
echo "No argument received!"
echo "example: plugin.sh minimal_counter_for_warning_alert counter_for_critical_alert"
echo
echo "setting values to default: 5 10"
warn=5
crit=10
fi
if (($warn<=$countWarnings ||$countWarnings==0)); then
echo "OK - $countWarnings services in Warning state"
exit 0
elif (($warn<$countWarnings && $countWarnings<=$crit)); then
echo "WARNING - $countWarnings services in Warning state"
exit 1
elif (($crit<$countWarnings)); then
echo "CRITICAL - $countWarnings services in Warning state"
exit 2
else
echo "UNKNOWN - $countWarnings"
exit 3
fi
nagios@lab:/usr/local/nagios/libexec$ echo $(/usr/local/nagios/bin/nagiostats | grep "Ok/Warn/Unk/Crit:" | sed 's/[[:space:]]//g' | cut -d"/" -f5)
0
Current status from nagios Web interface:
Ok Warning Unknown Critical Pending
12 0 0 2 0
Thank you ... article really help a beginer like me ;-)
this is THE MOST comprehensive and straight forward turorial I've seen. thank you!
Hi, When I am hiting the below command:
/usr/lib/nagios/plugins/check_nrpe -H 3.6.123.156 -c check_root_home_du
I am getting:
"NRPE: Unable to read output"
Please help me on this.
Hi, this is a fantastic article, i managed to learn how to make plugins myself.
Thank You