Created
September 7, 2016 20:19
-
-
Save nhumrich/8bb1503eaef312e65ebd65b2fb075e9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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