Skip to content

Instantly share code, notes, and snippets.

@timbillstrom
Created December 9, 2016 13:37
Show Gist options
  • Save timbillstrom/9d6d5fb16d638e3741e254f50e1e2942 to your computer and use it in GitHub Desktop.
Save timbillstrom/9d6d5fb16d638e3741e254f50e1e2942 to your computer and use it in GitHub Desktop.
Bash - Check status for API, if status is unknown PING admin via SMS. To avoid extra text messages that day we save a textfile with a prefix specific to the day of alert.
#!/bin/bash
response=$(curl http://localhost:3000/api/status)
alert () {
curl -X POST \
-u username:password \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "from=BRON" \
-d "message=Status for API is unknown! 😭" \
-d "to=+467900000" \
'https://api.46elks.com/a1/SMS'
}
if [ "$response" = "true" ]; then
echo "All is well.. $(date)"
else
$today=$(date +%y%m%d).txt
if [ -e $today ]; then
echo "File $today already exists!"
else
echo >> $today
alert
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment