Browse Source

Merge pull request #11 from saravanan30erd/download_report

Add download report feature
pull/13/head
adriaaah 1 year ago
committed by GitHub
parent
commit
ce5979b58f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. 1
      README.md
  3. 29
      bin/monit-dashboard.py
  4. 26
      bin/utils.py
  5. 27
      static/monit-dashboard.css
  6. 4
      static/monit-dashboard.js
  7. 5
      templates/index.html

1
.gitignore

@ -1,3 +1,4 @@
*.pyc
.*.swp
conf/servers.json
*.xlsx

1
README.md

@ -37,6 +37,7 @@ thanks to the built-in web server, it is displayed in a single HTML page.
#### Python libaries
- `yum install python-requests python-xmltodict python-simplejson`
- `pip install xlsxwriter`
## Requisites

29
bin/monit-dashboard.py

@ -9,9 +9,11 @@ import sys
import datetime
from collections import OrderedDict
from operator import itemgetter
import utils
urls = ('/', 'index',
'/help', 'help'
'/help', 'help',
'/download', 'download'
)
app = web.application(urls, globals())
@ -64,35 +66,44 @@ def getMonit():
checks[name] = status[name]
sorted_checks = OrderedDict()
sorted_checks = OrderedDict(sorted(checks.iteritems(), key=itemgetter(1), reverse=True))
sorted_checks = OrderedDict(sorted(checks.iteritems(),
key=itemgetter(1), reverse=True))
count = calculate_count(sorted_checks)
server = dict(name=site, url=s['url'], result=sorted_checks, s_rate=count)
server = dict(name=site, url=s['url'],
result=sorted_checks, s_rate=count)
output.append(server)
print(datetime.datetime.now())
return(output)
# Classes
class monitDashboard(web.application):
def run(self, port=8080, *middleware):
func = self.wsgifunc(*middleware)
return web.httpserver.runsimple(func, ('0.0.0.0', port))
class index(object):
def GET(self):
return render.index(output=getMonit(), now=datetime.datetime.now())
return render.index(output=getMonit(),
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')
return open(filename, 'rb').read()
# Main
if __name__ == "__main__":
app = monitDashboard(urls, globals())

26
bin/utils.py

@ -0,0 +1,26 @@
import xlsxwriter
import os
def generate_report_excel(output, filename):
if os.path.exists(filename):
os.remove(filename)
workbook = xlsxwriter.Workbook(filename)
bold = workbook.add_format({'bold': 1})
for server in range(len(output)):
worksheet = workbook.add_worksheet(output[server]['name'])
worksheet.set_column('A:A', 40)
worksheet.set_column('B:B', 15)
worksheet.write('A1', 'Components', bold)
worksheet.write('B1', 'Status', bold)
row = 1
col = 0
for key, value in output[server]['result'].items():
worksheet.write_string(row, col, key)
if value == 0:
status = 'OK'
else:
status = 'Error'
worksheet.write_string(row, col + 1, key)
worksheet.write_string(row, col + 1, status)
row += 1
workbook.close()

27
static/monit-dashboard.css

@ -33,7 +33,7 @@ a {
}
button.accordion {
color: #444;
color: #FFF;
cursor: pointer;
padding: 18px;
width: 100%;
@ -41,7 +41,28 @@ button.accordion {
border: none;
outline: none;
transition: 0.4s;
margin: 0.6rem;
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;
}
div.download-header {
height: 7%;
background-color: #273c75;
display: flex;
justify-content: flex-end;
padding-right: 20px;
}
div.panel {
@ -73,7 +94,7 @@ div.panel.show {
}
.canvas-container {
height: 40%;
height: 35%;
margin: auto;
width: 24%;
}

4
static/monit-dashboard.js

@ -19,7 +19,7 @@ function draw(rate) {
var red = (percentage[1]*2)/100;
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var colors = ['#40ff00', '#ff0000'];
var colors = ['#00a90e','#ff9a02'];
var angles = [Math.PI * green, Math.PI * red];
var offset = 0;
var beginAngle = 0;
@ -41,7 +41,7 @@ function draw(rate) {
ctx.moveTo(200 + offsetX, 200 + offsetY);
ctx.arc(200 + offsetX, 200 + offsetY, 120, beginAngle, endAngle);
ctx.lineTo(200 + offsetX, 200 + offsetY);
ctx.stroke();
// ctx.stroke();
ctx.fill();
ctx.rect(canvas.width - 129, i * 20 + 10, 10, 10);

5
templates/index.html

@ -4,7 +4,10 @@ $def with (output, now)
$ errors = 0
$ color = "green"
<div>
<div style="height: 40%; overflow-y: scroll; overflow-x: hidden;">
<div class="download-header">
<button class="download-button" onclick="window.location.href = 'download';">Download Report</button>
</div>
<div style="height: 38%; overflow-y: scroll; overflow-x: hidden;">
$for server in range(len(output)):
$code:
errors = 0

Loading…
Cancel
Save