Created
August 1, 2012 09:24
-
-
Save eidantoei/3225392 to your computer and use it in GitHub Desktop.
Run all NRPE commands in nrpe.cfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grep '^command\[' /etc/nagios/nrpe.cfg | while read l; do n=$(cut -f2 -d'['<<<"$l"|cut -f1 -d']'); c=$(cut -f2- -d'='<<<"$l"); r=$(bash <<<"$c"); case $? in 0) echo -ne "\033[42m\033[1;37m OK \033[0m";; 1) echo -ne "\033[43m\033[1;37m WARN \033[0m";; 2) echo -ne "\033[41m\033[1;37m CRIT \033[0m";; *) echo -ne "\033[45m\033[1;37m UNKN \033[0m";; esac; echo -ne " \033[4m$n\033[0m $c\n$r\n\n"; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
nrpe_cfg="/etc/nagios/nrpe.cfg" | |
c_bg_gre="\033[42m" | |
c_bg_yel="\033[43m" | |
c_bg_red="\033[41m" | |
c_bg_pin="\033[45m" | |
c_whi="\033[1;37m" | |
c_ul="\033[4m" | |
c_r="\033[0m" | |
grep '^command\[' ${nrpe_cfg} | while read l; do | |
name=$(cut -f2 -d'['<<<"$l"|cut -f1 -d']') | |
cmd=$(cut -f2- -d'='<<<"$l") | |
result=$(bash <<<"${cmd}") | |
case $? in | |
0) echo -ne "${c_bg_gre}${c_whi} OK ${c_r}";; | |
1) echo -ne "${c_bg_yel}${c_whi} WARN ${c_r}";; | |
2) echo -ne "${c_bg_red}${c_whi} CRIT ${c_r}";; | |
*) echo -ne "${c_bg_pin}${c_whi} UNKN ${c_r}";; | |
esac | |
echo -ne " ${c_ul}${name}${c_r} ${cmd}\n${result}\n\n" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment