Skip to content

Instantly share code, notes, and snippets.

@benoitjpnet
Last active August 29, 2015 14:11
Show Gist options
  • Save benoitjpnet/cc21ae3b2c0586f568a1 to your computer and use it in GitHub Desktop.
Save benoitjpnet/cc21ae3b2c0586f568a1 to your computer and use it in GitHub Desktop.
Nagios wrapper for check_http and other http related checks.
#!/bin/bash
result=/tmp/nagios.check_http_many.result
trap "rm ${result}*" EXIT
warning=false
critical=false
check_state() {
if [[ $1 -eq 0 ]]; then
cat $result >> ${result}.ok
:> $result
fi
if [[ $1 -eq 1 ]]; then
warning=true
cat $result >> ${result}.err
:> $result
fi
if [[ $1 -eq 2 ]]; then
critical=true
cat $result >> ${result}.err
:> $result
fi
}
# Check HTTP
sites="a.fr b.com"
for site in $sites; do
/usr/lib/nagios/plugins/check_http -I 127.0.0.1 H $site >> $result
check_state $?
done
# Check HTTPs
sites="a.fr b.com"
for site in $sites; do
/usr/lib/nagios/plugins/check_http -p 443 -S -I 127.0.0.1 --sni -H $site >> $result
check_state $?
done
# Check HTTPs certs
sites="a.fr b.com"
for site in $sites; do
/usr/lib/nagios/plugins/check_http -p 443 -S --sni -H $site -C14,7 >> $result
check_state $?
done
# Check Sockets
sockets="/tmp/a.sock /tmp/b.sock"
for socket in $sockets; do
/usr/lib/nagios/plugins/check_tcp -H $socket >> $result
check_state $?
done
if ($critical); then
cat ${result}.err
exit 2
fi
if ($warning); then
cat ${result}.err
exit 1
else
cat ${result}.ok
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment