puppet: Add monitoring for camo.

(imported from commit b3cf29b02de285cf860fc173183cb6f4f3a17c74)
This commit is contained in:
Tim Abbott
2013-11-16 11:32:44 -05:00
parent 1bcf37664f
commit b50db26a18
4 changed files with 214 additions and 0 deletions

View File

@@ -160,3 +160,9 @@ define command {
command_name check_email_deliverer_backlog
command_line /usr/lib/nagios/plugins/check_by_ssh -l zulip -t 30 -i /var/lib/nagios/.ssh/id_rsa -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/check_email_deliverer_backlog'
}
define command{
command_name check_website_response
command_line /usr/lib/nagios/plugins/check_website_response.sh -u $ARG1$ -w $ARG2$ -c $ARG3$
}

View File

@@ -50,3 +50,10 @@ define service{
service_description Check postgres replication lag
check_command check_pg_replication_lag
}
define service{
use generic-service
host_name nagios
service_description Check Camo is operational
check_command check_website_response!https://external-content.zulipcdn.net/e9e01825634805fcf710af13c0e68f344663fc83/687474703a2f2f692e696d6775722e636f6d2f5a713131627a732e676966!6000!12000!
}

View File

@@ -0,0 +1,199 @@
#!/bin/sh
#
# Nagios script to check website is up and responding in a timely manner
# Written by Chris Freeman (cfree6223@gmail.com)
# Version 1.1
# (c) GPLv2 2011
#
# Special thanks to dkwiebe and Konstantine Vinogradov for suggestions and feedback
#
### Environment paths
NETCAT=/bin/nc
DATE=/bin/date
WGET=/usr/bin/wget
ECHO=/bin/echo
AWK=/usr/bin/awk
CKSUM=/usr/bin/cksum
TR=/usr/bin/tr
# Temp file
WGETOUT=/tmp/wgetoutput
### Functions
# Check dependencies and paths
checkpaths(){
for PATH in $NETCAT $DATE $WGET $ECHO $AWK $CKSUM $TR; do
if [ ! -f "$PATH" ]; then
STATUS=UNKNOWN
OUTMSG="ERROR: $PATH does does not exist"
output
fi
done
}
# Check inputs and formats
checkinputs(){
if [ ! -n "$WARN" ]; then
ERROR="Warning not set"
usage
fi
case $WARN in
*[!0-9]*)
ERROR="Warning must be an integer in milliseconds"
usage
esac
if [ ! -n "$CRIT" ]; then
ERROR="Critical not set"
usage
fi
case $CRIT in
*[!0-9]*)
ERROR="Critical must be an integer in milliseconds"
usage
esac
if [ "$CRIT" -lt "$WARN" ]; then
ERROR="Critical must be greater than Warning"
usage
fi
if [ ! -n "$URL" ]; then
ERROR="URL not set"
usage
fi
}
# Make temp file unique for URL
mktmpfile(){
WGETOUTCKSUM=$WGETOUT`$ECHO $URL |$CKSUM |$AWK '{print $1}'`
}
# Print usage statement
usage(){
$ECHO "RESPONSE: UNKNOWN - Error: $ERROR"
$ECHO "Usage: check_website_response.sh -w <warning milliseconds> -c <critical milliseconds> -u <url> [ -nocert ]"
exit 3
}
# Check if URL resolves, port is open and webpage contains data
checkopen(){
# Determine PORT from scheme
SCHEME=`$ECHO $URL |$AWK -F: '{print $1}'| $TR [:upper:] [:lower:]`
# Strip scheme out of URL
case $URL in
*://*)
SHORTURL=`$ECHO $URL |$AWK -F"://" '{print $2}'`;;
*)
SHORTURL=$URL;;
esac
# Strip path out of URL
case $SHORTURL in
*/*)
SHORTURL=`$ECHO $SHORTURL |$AWK -F/ '{print $1}'`;;
esac
# if no scheme check for ports in SHORTURL or else default to 80
case $SHORTURL in
*:*@*:*)
if [ ! -n "$PORT" ]; then
PORT=`$ECHO $SHORTURL |$AWK -F: '{print $3}'`
fi
SHORTURL=`$ECHO $SHORTURL |$AWK -F@ '{print $2}'`
SHORTURL=`$ECHO $SHORTURL |$AWK -F: '{print $1}'`;;
*:*@*)
if [ ! -n "$PORT" ]; then
PORT=80
fi
SHORTURL=`$ECHO $SHORTURL |$AWK -F@ '{print $2}'`;;
*:*)
if [ ! -n "$PORT" ]; then
PORT=`$ECHO $SHORTURL |$AWK -F: '{print $2}'`
fi
SHORTURL=`$ECHO $SHORTURL |$AWK -F: '{print $1}'`;;
*)
if [ "$SCHEME" = "https" ]; then
PORT=443
fi
if [ ! -n "$PORT" ]; then
PORT=80
fi;;
esac
# Check if URL resolves and port is open
if ! $NETCAT -z $SHORTURL $PORT > /dev/null 2>&1; then
OUTMSG="URL $SHORTURL can't resolve or port $PORT not open"
STATUS=CRITICAL
output
fi
# Check if page can be loaded and contains data
if [ -n "$NOCERT" ]; then
$WGET --no-check-certificate -q -O $WGETOUTCKSUM $URL
else
$WGET -q -O $WGETOUTCKSUM $URL
fi
if [ ! -s "$WGETOUTCKSUM" ]; then
OUTMSG="$URL does not contain any data"
STATUS=CRITICAL
output
fi
}
# Check page response time
pageload(){
if [ -n "$NOCERT" ]; then
STARTTIME=$($DATE +%s%N)
$WGET --no-check-certificate -q $URL
ENDTIME=$($DATE +%s%N)
else
STARTTIME=$($DATE +%s%N)
$WGET -q $URL
ENDTIME=$($DATE +%s%N)
fi
TIMEDIFF=$((($ENDTIME-$STARTTIME)/1000000))
if [ "$TIMEDIFF" -lt "$WARN" ]; then
STATUS=OK
elif [ "$TIMEDIFF" -ge "$WARN" ] && [ "$TIMEDIFF" -lt "$CRIT" ]; then
STATUS=WARNING
elif [ "$TIMEDIFF" -ge "$CRIT" ]; then
STATUS=CRITICAL
fi
OUTMSG="$TIMEDIFF ms"
}
# Output statement and exit
output(){
$ECHO "RESPONSE: $STATUS - $OUTMSG""|Response="$TIMEDIFF"ms;"$WARN";"$CRIT";0"
if [ "$STATUS" = "OK" ]; then
exit 0
elif [ "$STATUS" = "WARNING" ]; then
exit 1
elif [ "$STATUS" = "CRITICAL" ]; then
exit 2
fi
exit 3
}
### Main
# Input variables
while getopts w:c:u:n: option
do case "$option" in
w) WARN=$OPTARG;;
c) CRIT=$OPTARG;;
u) URL=$OPTARG;;
n) NOCERT=$OPTARG;;
*) ERROR="Illegal option used"
usage;;
esac
done
checkpaths
checkinputs
mktmpfile
checkopen
pageload
output

View File

@@ -7,6 +7,8 @@ class zulip_internal::nagios {
"autossh",
# Packages needed for munin
"munin",
# Needed for check_website_response
"netcat",
]
package { $nagios_packages: ensure => "installed" }