Skip to content

Instantly share code, notes, and snippets.

@threewordphrase
Last active January 12, 2016 18:26
Show Gist options
  • Save threewordphrase/89d8c16cc67598781f46 to your computer and use it in GitHub Desktop.
Save threewordphrase/89d8c16cc67598781f46 to your computer and use it in GitHub Desktop.
Simple "Oh shit" uptime checker for when nothing else is set up yet, displays OSX notification when URL returns a non-200 code.
cd ~/Library/LaunchAgents/
# plist goes in this directory
launchctl load com.aaron.whatever.plist
# Disable:
launchctl unload com.aaron.whatever.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.aaron.urgent</string>
<key>ProgramArguments</key>
<array>
<string>/Users/aaron/scripts/urgent.sh</string>
</array>
<key>StartInterval</key>
<integer>15</integer>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/aaronurgent.err</string>
<key>StandardOutPath</key>
<string>/tmp/aaronurgent.out</string>
</dict>
</plist>
#!/bin/bash
#
# Runs every 15 seconds, see /Users/aaron/Library/LaunchAgents/com.aaron.urgent.plist
#
code=$(curl --silent --output /dev/null -w "%{http_code}" http://host.com/api/products/squirt-1-5-lts)
if [ "$code" -ne "200" ]
then
osascript -e "display notification \"SITE RETURNING $code\" with title \"MAJOR FUCKUP ALERT\""
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment