Skip to content

Instantly share code, notes, and snippets.

@jwood
Created October 17, 2011 16:32
Show Gist options
  • Save jwood/1293018 to your computer and use it in GitHub Desktop.
Save jwood/1293018 to your computer and use it in GitHub Desktop.
Proby command line wrapper script
#!/bin/bash
#
# This script surrounds the command passed in with start and finish notifications
# to the Proby task monitoring application.
#
#
# === SETUP
#
# * Make sure the proby script is executable.
#
# chmod +x proby
#
# * Please specify your Proby API key, by itself, in ~/.proby.conf or /etc/proby.conf.
# The API key specified in ~/.proby.conf will take precedence over the one specified
# in /etc/proby.conf.
#
#
# === USAGE
#
# PROBY_TASK_ID=<your Proby Task ID> /path/to/proby '<command>'
#
#
# === EXAMPLE
#
# PROBY_TASK_ID=83a8d6c0c103012efde3lk8092kasdf6 /path/to/proby 'ls -l | grep foo | cut -f 3 -d " "'
#
# If invoking using cron, your crontab entry may look something like
#
# * * * * * PROBY_TASK_ID=83a8d6c0c103012efde3lk8092kasdf6 /path/to/proby 'ls -l | grep couch | cut -f 3 -d " "'
#
#
# === DEPENDENCIES
#
# * curl
#
#
# http://probyapp.com
#
if [ $# -ne 1 ]; then
echo "Usage: PROBY_TASK_ID=<your Proby task id> proby '<command>'"
exit 1
fi
test -f ~/.proby.conf
if [ $? -eq 0 ]; then
api_key=`cat ~/.proby.conf`
fi
if [ -z "$api_key" ]; then
test -f /etc/proby.conf
if [ $? -eq 0 ]; then
api_key=`cat /etc/proby.conf`
fi
fi
if [ -z "$api_key" ]; then
echo "API key not set. Please specify it in ~/.proby.conf or /etc/proby.conf"
exit 1
fi
# Trim extra whitespace from api key
api_key=`echo $api_key`
# The --insecure option is needed because the root certificate for our
# certificate authority is not bundled with many common HTTP clients.
# See http://curl.haxx.se/docs/sslcerts.html for details.
curl --header "api_key: $api_key" --header "ContentType: application/json" -X POST --insecure https://proby.signalhq.com/api/v1/tasks/$PROBY_TASK_ID/start.json
cmd="$@"
bash -c "$cmd"
if [ $? -ne 0 ]; then
failed_data="-d 'failed=true'"
fi
curl --header "api_key: $api_key" --header "ContentType: application/json" -X POST --insecure $failed_data https://proby.signalhq.com/api/v1/tasks/$PROBY_TASK_ID/finish.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment