Combining two nagios checks into one
Last week I felt the need to combine the output of two nagios checks into one to check the state of my puppet clients. Because I couldn’t find any fast enough, I decided to write one quickly.
I thought I’d share this with the world, should anyone need this too…
#!/bin/bash # A simple nagioscheck to combine 2 checks # cmd=$@ script=$0 OK=0 WARN=1 CRIT=2 UNKNOWN=3 usage () { echo "check_combine usage" echo "check_combine check1 check1_params -- check2 check2_params" } parse () { check1=$(echo $cmd | sed -e "s/\$script //" -e "s/ -- .*//") check2=$(echo $cmd | sed -e "s/\$script //" -e "s/.* -- //") } execute () { output1=$($check1) code1=$? output2=$($check2) code2=$? } analyse(){ code=$code1$code2 case "$code" in "00"|"01"|"02"|"03"|"11"|"22"|"33") echo $output2 exit $code2 ;; "10"|"20"|"21"|"23"|"30"|"31") echo $output1 exit $code1 ;; "12"|"13"|"32") echo $output2 exit $code2 ;; esac } parse execute analyse