-
-
Save Urban-Hacker/822d00c0a1c14e5e4a92a70e0f11579a to your computer and use it in GitHub Desktop.
A very basic status page
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
import os | |
# Very basic status page script | |
# * Read the blog post here: https://urbanhacker.net/creating-our-own-status-page-to-monitor-the-local-network/ | |
# * You will need https://vanillacss.com/ if you want a bit more fancy style | |
# List of all tests we want to run | |
tests = [ | |
{"cmd": "ping 192.168.1.1", "name": "Gateway"}, | |
{"cmd": "ping 8.8.8.8", "name": "Google DNS"}, | |
{"cmd": "ping urbanhacker.net", "name": "UrbanHacker Website"}, ] | |
# Running all the tests and creating the report | |
html = """ | |
<style> | |
.failure{ | |
color: red; | |
} | |
.success{ | |
color: #418a38; | |
} | |
</style> | |
<link rel="stylesheet" href="vanilla.css"> | |
<h1>UrbanHacker Network Status</h1> | |
""" | |
errors = 0 | |
test_html = "" | |
for test in tests: | |
result = os.system(test["cmd"]) | |
if result == 0: | |
test_html += test["name"] + \ | |
" <strong class='success'>Success</strong><br />" | |
else: | |
errors += 1 | |
test_html += test["name"] + \ | |
" <strong class='failure'>Failure</strong><br />" | |
if errors > 0: | |
html += "<h3 class='failure'>One or more service(s) are experiencing outages</h3>" | |
else: | |
html += "<h3 class='success'>No outages</h3>" | |
html += test_html | |
with open("report.html", "w") as report: | |
report.write(html) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment