From e3707750b4c0aa14aedaa66124689d412ba8f768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0?= Date: Mon, 27 Jan 2020 00:21:03 +0100 Subject: [PATCH] Beautify --- bin/monit-dashboard.py | 19 ++++--- bin/utils.py | 1 + static/monit-dashboard.css | 108 ++++++++++++++++++------------------- static/monit-dashboard.js | 24 ++++----- templates/help.html | 4 +- templates/index.html | 44 +++++++-------- templates/layout.html | 8 +-- 7 files changed, 108 insertions(+), 100 deletions(-) diff --git a/bin/monit-dashboard.py b/bin/monit-dashboard.py index 9cb90b1..d502b1a 100755 --- a/bin/monit-dashboard.py +++ b/bin/monit-dashboard.py @@ -27,10 +27,11 @@ output = [] # Functions + def calculate_count(data): count = {} ls = data.values() - z, nz = 0,0 + z, nz = 0, 0 for v in ls: if v == 0: z += 1 @@ -67,10 +68,10 @@ def getMonit(): sorted_checks = OrderedDict() sorted_checks = OrderedDict(sorted(checks.iteritems(), - key=itemgetter(1), reverse=True)) + key=itemgetter(1), reverse=True)) count = calculate_count(sorted_checks) server = dict(name=site, url=s['url'], - result=sorted_checks, s_rate=count) + result=sorted_checks, s_rate=count) output.append(server) print(datetime.datetime.now()) @@ -78,6 +79,7 @@ def getMonit(): # Classes + class monitDashboard(web.application): def run(self, port=8080, *middleware): func = self.wsgifunc(*middleware) @@ -87,23 +89,26 @@ class monitDashboard(web.application): class index(object): def GET(self): return render.index(output=getMonit(), - now=datetime.datetime.now()) + now=datetime.datetime.now()) + class help(object): def GET(self): return render.help() + class download(object): def GET(self): filename = 'health_report.xlsx' output = getMonit() utils.generate_report_excel(output, filename) web.header('Content-Disposition', - 'attachment; filename="health_report.xlsx"') - web.header('Content-type','application/octet-stream') - web.header('Cache-Control','no-cache') + 'attachment; filename="health_report.xlsx"') + web.header('Content-type', 'application/octet-stream') + web.header('Cache-Control', 'no-cache') return open(filename, 'rb').read() + # Main if __name__ == "__main__": app = monitDashboard(urls, globals()) diff --git a/bin/utils.py b/bin/utils.py index cd58daa..e318a75 100644 --- a/bin/utils.py +++ b/bin/utils.py @@ -1,6 +1,7 @@ import xlsxwriter import os + def generate_report_excel(output, filename): if os.path.exists(filename): os.remove(filename) diff --git a/static/monit-dashboard.css b/static/monit-dashboard.css index ab229bc..deba533 100644 --- a/static/monit-dashboard.css +++ b/static/monit-dashboard.css @@ -1,104 +1,104 @@ .server-link a { - color: #fff; - text-decoration: none; - text-transform: uppercase; - text-decoration: underline; + color: #fff; + text-decoration: none; + text-transform: uppercase; + text-decoration: underline; } th { - background-color: #999; - padding: 10px; + background-color: #999; + padding: 10px; } td { - border-bottom: 1px solid #ccc; - padding: 15px; + border-bottom: 1px solid #ccc; + padding: 15px; } body { - font-family: arial; + font-family: arial; } tr:nth-child(odd) { - background-color: #fff; + background-color: #fff; } tr:nth-child(even) { - background-color: #f2f2f2; + background-color: #f2f2f2; } a { - color: #cb0017; - font-weight: bolder; + color: #cb0017; + font-weight: bolder; } button.accordion { - color: #FFF; - cursor: pointer; - padding: 18px; - width: 100%; - text-align: center; - border: none; - outline: none; - transition: 0.4s; - margin: 0.6rem 0; + color: #FFF; + cursor: pointer; + padding: 18px; + width: 100%; + text-align: center; + border: none; + outline: none; + transition: 0.4s; + margin: 0.6rem 0; } button.download-button { - color: white; - background-color: #00a8ff; - cursor: pointer; - padding: 18px; - text-align: center; - border: none; - outline: none; - transition: 0.4s; - float: right; - margin: auto 0; + color: white; + background-color: #00a8ff; + cursor: pointer; + padding: 18px; + text-align: center; + border: none; + outline: none; + transition: 0.4s; + float: right; + margin: auto 0; } div.download-header { - height: 7%; - background-color: #273c75; - display: flex; - justify-content: flex-end; - padding-right: 20px; + height: 7%; + background-color: #273c75; + display: flex; + justify-content: flex-end; + padding-right: 20px; } div.panel { - padding: 0 18px; - background-color: white; - display: none; + padding: 0 18px; + background-color: white; + display: none; } div.panel.show { - display: block; + display: block; } .green { - background-color: #79bd8f; - font-size: 20px; + background-color: #79bd8f; + font-size: 20px; } .green:hover { - background-color: #588a68; + background-color: #588a68; } .red { - background-color: #d9534f; - font-size: 20px; + background-color: #d9534f; + font-size: 20px; } .red:hover { - background-color: #c9302c; + background-color: #c9302c; } .canvas-container { width: 50%; display: flex; justify-content: center; - margin-top:200; - margin-bottom:100; + margin-top: 200; + margin-bottom: 100; } .canvas-graph { @@ -108,12 +108,12 @@ div.panel.show { position: relative; background-color: white; margin: 20px 0; - box-shadow: 0 2px 4px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12) + box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12) } .canvas-header { - padding: 1rem; - height: 2rem; - background-color: #F2F2F2; - text-align: center; + padding: 1rem; + height: 2rem; + background-color: #F2F2F2; + text-align: center; } diff --git a/static/monit-dashboard.js b/static/monit-dashboard.js index ef0c7d3..2e9b523 100644 --- a/static/monit-dashboard.js +++ b/static/monit-dashboard.js @@ -2,32 +2,32 @@ var acc = document.getElementsByClassName("accordion"); var i; for (i = 0; i < acc.length; i++) { - acc[i].onclick = function() { - this.classList.toggle("active"); - this.nextElementSibling.classList.toggle("show"); - } + acc[i].onclick = function() { + this.classList.toggle("active"); + this.nextElementSibling.classList.toggle("show"); + } } function draw(rate) { var count = [rate['green'], rate['red']]; var percentage = [ - (count[0]*100)/(count[0]+count[1]), - (count[1]*100)/(count[0]+count[1]) + (count[0] * 100) / (count[0] + count[1]), + (count[1] * 100) / (count[0] + count[1]) ] var status = ['Ok', 'Error']; - var green = (percentage[0]*2)/100; - var red = (percentage[1]*2)/100; + var green = (percentage[0] * 2) / 100; + var red = (percentage[1] * 2) / 100; var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); - var colors = ['#00a90e','#ff9a02']; + var colors = ['#00a90e', '#ff9a02']; var angles = [Math.PI * green, Math.PI * red]; var offset = 0; var beginAngle = 0; var endAngle = 0; var offsetX, offsetY, medianAngle; - ctx.clearRect(0,0,canvas.width, canvas.height); - for(var i = 0; i < angles.length; i = i + 1) { + ctx.clearRect(0, 0, canvas.width, canvas.height); + for (var i = 0; i < angles.length; i = i + 1) { beginAngle = endAngle; endAngle = endAngle + angles[i]; medianAngle = (endAngle + beginAngle) / 2; @@ -36,7 +36,7 @@ function draw(rate) { ctx.beginPath(); - if(percentage[i] !== 0) { + if (percentage[i] !== 0) { ctx.fillStyle = colors[i % colors.length]; ctx.moveTo(200 + offsetX, 200 + offsetY); ctx.arc(200 + offsetX, 200 + offsetY, 120, beginAngle, endAngle); diff --git a/templates/help.html b/templates/help.html index 2b450cc..ba5755f 100644 --- a/templates/help.html +++ b/templates/help.html @@ -1,3 +1,3 @@
-

Please check the README file.

-
\ No newline at end of file +

Please check the README file.

+ diff --git a/templates/index.html b/templates/index.html index 2d7e251..002a631 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,14 +1,14 @@ $def with (output, now) -$ errors = 0 -$ color = "green" -
-
- -
-
-$for server in range(len(output)): + $ errors = 0 + $ color = "green" +
+
+ +
+
+ $for server in range(len(output)): $code: errors = 0 color = "green" @@ -82,21 +82,23 @@ $for server in range(len(output)):
-
-
-

Hosts status

- -
-
+
+
+
+

Hosts status

+
+ +
+
-
-


-Latest update: $now.day/$now.month/$now.year, $now.hour:$now.minute:$now.second -

-Home | Help -
+
+


+ Latest update: $now.day/$now.month/$now.year, $now.hour:$now.minute:$now.second +

+ Home | Help +
-
+
diff --git a/templates/layout.html b/templates/layout.html index d2fc766..7d48b57 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -3,14 +3,14 @@ $def with (content) - Monit Dashboard - - + Monit Dashboard + + - $:content + $:content