Last active
July 5, 2020 17:39
-
-
Save UnixSage/0aa4e4f13dc62b14e0609585cdac67ac to your computer and use it in GitHub Desktop.
Simple script that will monitor a list of names and make sure the IPs match. Useful if you not using CNAMES for APEX domains. Output can be put on a web server and monitored for status.
This file contains 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
#!/usr/bin/env python3 | |
import socket | |
import datetime | |
domainlist = { | |
'home.mydomain.com': 'user.myisp.net', | |
'mydomain.com': 'account.myhosting.com' | |
} | |
statusdetail = [] | |
serviceOK = True | |
for domain in domainlist: | |
siteip = socket.gethostbyname_ex(domain)[2] | |
refip = socket.gethostbyname_ex(domainlist[domain])[2] | |
siteip.sort() | |
refip.sort() | |
siteip = ' '.join(siteip) | |
refip = ' '.join(refip) | |
if siteip == refip: | |
statusdetail.append(f"""<div id="status" class="ok">{domain} ({siteip}): OK</div><br>""") | |
else: | |
statusdetail.append(f"""<div id="status" class="error">{domain} ({siteip}): ERROR new IP - {refip}</div><br>""") | |
serviceOK = False | |
report=""" | |
<html> | |
<head> | |
<title>Monitor IP</title> | |
<style> | |
#status.ok {{color: green;}} | |
#status.error {{color: red;}} | |
</style> | |
</head> | |
<h1>Service Status: {status}</h1> | |
<hr> | |
{detail} | |
<div>Updated: {datestamp}</div> | |
</html> | |
""" | |
print(report.format | |
( | |
status = serviceOK, | |
detail = "\n".join(statusdetail), | |
datestamp = datetime.datetime.now().replace(microsecond=0) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment