Skip to content

Instantly share code, notes, and snippets.

@mskian
Last active April 11, 2019 15:09
Show Gist options
  • Save mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9 to your computer and use it in GitHub Desktop.
Save mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9 to your computer and use it in GitHub Desktop.
Website HTTP Status Checker - Get Monitor Notification on Pushbullet
#!/bin/bash
# Purpose: Website HTTP Status Checker
# Source: https://gist.github.com/mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9
# Developer: Santhosh Veer
# Domain to check
DOMAIN="https://example.com"
# Pushbullet API Key - https://docs.pushbullet.com/
PUSHBULLET="<PUSHBULLET API KEY>"
# HTTP Status Code - https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
HTTP200="200"
HTTP503="503"
HTTP404="404"
HTTP500="500"
HTTP502="502"
HTTP400="400"
HTTP408="408"
# make the HTTP Status Check
GETSTATUS(){
curl -s -I $DOMAIN | grep HTTP/ | awk '{print $2}'
}
STATUSCHECK=$(GETSTATUS)
# check if HTTP Status Code are equal and send pushbullet notification
if [ "$STATUSCHECK" == "$HTTP200" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 200 - Health:Good","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP503" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 503 - Health:Service unavailable","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP404" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 404 - Health:Not Found","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP500" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 500 - Health:Internal Server Error","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP502" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 502 - Health:Bad Gateway","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP400" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 400 - Health:Bad Request","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
elif [ "$STATUSCHECK" == "$HTTP408" ]; then
curl --header "Access-Token: $PUSHBULLET" \
--header 'Content-Type: application/json' \
--data-binary '{"body":"Uptimestatus HTTP Code 408 - Health:Request Timeout","title":"'"$DOMAIN"'","type":"note"}' \
--request POST \
https://api.pushbullet.com/v2/pushes
fi
@mskian
Copy link
Author

mskian commented Apr 10, 2019

Requirements

  • Pushbullet (For sending Notification)

How to use

  • install this on your server etc folder (You can also install this script on any location.while setup the Cron job Update the File Location)

Download script to etc folder

wget https://gist.githubusercontent.com/mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9/raw/status.sh -P /etc/

Normal download

wget https://gist.githubusercontent.com/mskian/6f49b45e74ab5c0ef1c5e266bcfa22c9/raw/status.sh
cd /etc/
chmod +x status.sh
  • Setup Cronjob to Monitor your website/blog
# Cron jobs

# Run Every Night at 12 AM

0 0 * * * /etc/status.sh > /dev/null 2>&1

# Run Every 1 Hour in a Day

0 * * * * /etc/status.sh > /dev/null 2>&1

# Run Every 30mins in a Day

*/30 * * * * /etc/status.sh > /dev/null 2>&1

# Run Every 2 Hours in a Day

0 */2 * * * /etc/status.sh > /dev/null 2>&1

  • Don't Forget to Update the website URL & Pushbullet API Key on the Script File

@mcnaveen
Copy link

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment