From 3aa7835802d11dd053621b2f3aaaa3736fae68a2 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sun, 24 Nov 2019 17:25:21 +0400 Subject: [PATCH] add route to download report file --- bin/monit-dashboard.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bin/monit-dashboard.py b/bin/monit-dashboard.py index 9361d14..546e8a3 100755 --- a/bin/monit-dashboard.py +++ b/bin/monit-dashboard.py @@ -66,9 +66,11 @@ 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()) @@ -77,23 +79,31 @@ def getMonit(): # 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()) 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())