Snippets

Steve Adams Site status checker for OS X

Created by Steve Adams
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
# Requires Requests:
# http://docs.python-requests.org/en/master/user/install/#distribute-pip
import requests

failures  = []
endpoints = {
    "steve_adams_me": "http://steve-adams.me",
    "sure":           "http://google.ca",
    "nope":           "http://fraaaaap.com",
    "nahhh":          "http://devinareyoureadingthis.com",
    "wow":            "http://imyourgranpappy.com",
    "hoophoop":       "http://i<3u.somuch"
}

# Attempt to get an OK status from each URL.
for name, endpoint in endpoints.iteritems():
    try:
        r = requests.get(endpoint)
    except Exception:
        r = False

    if r == False or r and r.status_code != 200:
        failures.append(endpoint)

# If any failed, report it using osascript 'display notification'.
# This won't work on anything other than OS X Mavericks or better.
if len(failures) > 0:
    msg = ""

    for endpoint in failures:
        msg += endpoint + ", "

    msg = msg.replace("http://", "")
    msg = msg.replace("https://", "")
    msg = msg.rstrip(",")

    os.system("osascript -e 'display notification \"" + msg + "\" with title \"These URLs are down:\"'")

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.