Skip to content

Instantly share code, notes, and snippets.

@farmdawgnation
Created August 22, 2012 04:27
Show Gist options
  • Save farmdawgnation/3422278 to your computer and use it in GitHub Desktop.
Save farmdawgnation/3422278 to your computer and use it in GitHub Desktop.
Internal HTTP Monitor for CloudKick
#!/bin/bash
####
# Internal HTTP Monitor Script Plugin for Cloudkick.
#
# This script does a curl to a URL passed in on the command line and
# checks the return code provided by curl to determine whether or not
# the request was successuful or not. Useful for situations where you
# need to monitor the health of app servers behind a firewall/HAProxy
# setup.
#
# Released under the terms of the Apache License.
####
# Fail on pipe errors
set -o pipefail
# The url to hit
URL=$1
# HIT IT!
statusline=`curl ${URL} --max-time 15 -I -s | head -1`
code=$?
# What happened?
if [ $code -eq 0 ]; then
status=`echo $statusline | cut -d ' ' -f 2`
if [ $status -lt 400 ]; then
echo "status ok Server OK. Gold star."
else
echo "status err Problems, captian:" $statusline
fi
elif [ $code -eq 7 ]; then
echo "status err Server down!"
elif [ $code -eq 28 ]; then
echo "status warn Request timeout. Sleeping on the job?"
else
echo "status warn Check failed with code" $code
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment