59 lines
1.1 KiB
Bash
Executable File
59 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# bare-bones check_onion plugin for nagios
|
|
|
|
# dependencies: torsocks, curl
|
|
|
|
# TODO: handle torsocks SOCKS failures
|
|
|
|
# default thresholds (pretty high, because tor is slow)
|
|
warn=15
|
|
crit=20
|
|
|
|
while getopts 'H:w:c:' opt
|
|
do
|
|
case "$opt" in
|
|
H) host="$OPTARG";;
|
|
w) warn="$OPTARG";;
|
|
c) crit="$OPTARG";;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$host" ]; then
|
|
echo "usage:" $0 "-H <hostname> [-w <warning-seconds]" \
|
|
"[-c <critical-seconds]"
|
|
exit 3
|
|
fi
|
|
|
|
starttime=$(date '+%s')
|
|
http_code=$(torsocks curl -s -I $host | head -n 1 | awk '{print $2}')
|
|
interval=$(echo $(date '+%s') - $starttime | bc)
|
|
|
|
check_time() {
|
|
if [ $interval -lt $warn ]; then
|
|
status='OK'
|
|
elif [ $interval -lt $crit ]; then
|
|
status='WARNING'
|
|
else
|
|
status='CRITICAL'
|
|
fi
|
|
}
|
|
|
|
case $http_code in
|
|
5*) status='CRITICAL' ;;
|
|
4*) status='CRITICAL' ;;
|
|
3*) check_time ;;
|
|
2*) check_time ;;
|
|
*) status='UNKNOWN' ;;
|
|
esac
|
|
|
|
echo 'Onion' "${status}:" "${host}:" 'got HTTP code:' $http_code \
|
|
'in' $interval 'seconds'
|
|
|
|
case $status in
|
|
OK) exit 0 ;;
|
|
WARNING) exit 1;;
|
|
CRITICAL) exit 2;;
|
|
UNKNOWN) exit 3;;
|
|
esac
|