Skip to content

Instantly share code, notes, and snippets.

@nhumrich
Created September 7, 2016 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhumrich/8bb1503eaef312e65ebd65b2fb075e9f to your computer and use it in GitHub Desktop.
Save nhumrich/8bb1503eaef312e65ebd65b2fb075e9f to your computer and use it in GitHub Desktop.
import dns.resolver
import os
from urllib import request
import json
import time
WEBHOOK_URL = 'https://hooks.slack.com/services/' \
'{keyhere}'
DNS_CHECK_URL = '{url.to.check}'
ENV = os.getenv('ENV', None)
def report_to_slack(exception):
message = {
'channel': '#slack-channel',
'text': 'Could not resolve dns for {} on env {}. Issue: {}'
.format(DNS_CHECK_URL, ENV, str(exception)),
'username': '{username}',
}
with request.urlopen(WEBHOOK_URL, json.dumps(message).encode()) as response:
html = response.read()
resolver = dns.resolver.Resolver()
while True:
try:
result = resolver.query(DNS_CHECK_URL)
if len(result) > 1:
report_to_slack(Exception('No A name can be resolved'))
except Exception as ex:
report_to_slack(ex)
time.sleep(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment