From a1a39f0b1b2a1ff7f2e8afeadbaeb0d4e87df073 Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sun, 24 Nov 2019 17:23:07 +0400 Subject: [PATCH] create func to generate status report in excel --- bin/monit-dashboard.py | 5 +++-- bin/utils.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 bin/utils.py diff --git a/bin/monit-dashboard.py b/bin/monit-dashboard.py index f34b3c9..9361d14 100755 --- a/bin/monit-dashboard.py +++ b/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()) @@ -69,7 +71,6 @@ def getMonit(): server = dict(name=site, url=s['url'], result=sorted_checks, s_rate=count) output.append(server) - print(datetime.datetime.now()) return(output) diff --git a/bin/utils.py b/bin/utils.py new file mode 100644 index 0000000..cd58daa --- /dev/null +++ b/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()