From 7ec1a038cc6909d6d00b58178a60a59ea437b83f Mon Sep 17 00:00:00 2001 From: saravanan30erd Date: Sun, 8 Mar 2020 18:02:53 +0400 Subject: [PATCH] add errors count in env --- bin/monit-dashboard.py | 3 +- templates/index.html | 75 ++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/bin/monit-dashboard.py b/bin/monit-dashboard.py index 7f8f1ff..fc77235 100755 --- a/bin/monit-dashboard.py +++ b/bin/monit-dashboard.py @@ -47,7 +47,7 @@ def arrange_services(services): name1, _, name2 = name.partition('-') if name2 == '': name2 = name1 - name1 = 'All' + name1 = 'others' if name1 not in list(checks.keys()): checks[name1] = OrderedDict() checks[name1][name2] = int(service['status']) @@ -84,7 +84,6 @@ def getMonit(): server = dict(name=site, url=s['url'], result=s_checks, s_rate=count) output.append(server) - output.append({'url': u'https://monit.xxx.xxx', 'result': {'All': OrderedDict([(u'staging', 32), (u'monitoring1', 0)])}, 's_rate': {'green': 70.0, 'red': 30.0}, 'name': u'Test Environment'}) print(datetime.datetime.now()) return(output) diff --git a/templates/index.html b/templates/index.html index f210aec..35ed1d8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,5 +1,6 @@ $def with (output, now) + $def row_error(check): +$def table_contents(color, text, services): + + + $text + + + + $for check in services.keys(): + $ isError = services.get(check) + $if isError != 0: + $:row_error(check) + $else: + $:row_ok(check) + + + $ errors = 0 $ color = "green" @@ -54,35 +71,14 @@ $def row_ok(check): $if isError != 0: $ errors=errors+1 $if errors > 0: - $ color = "red" - - - $env - - - - $for check in services.keys(): - $ isError = services.get(check) - $if isError != 0: - $:row_error(check) - $else: - $:row_ok(check) - + $code: + color = "red" + txt = "{}: {} error(s)".format(env, errors) + $:table_contents(color, txt, services) $else: - $ color = "green" - - - $env - - - - $for check in services.keys(): - $ isError = services.get(check) - $if isError != 0: - $:row_error(check) - $else: - $:row_ok(check) - + $code: + color = "green" + $:table_contents(color, env, services) $else: @@ -99,18 +95,19 @@ $def row_ok(check): $for env, services in output[server]['result'].items(): - - - $env - - + $ errors = 0 $for check in services.keys(): - $ isError = services.get(check) - $if isError != 0: - $:row_error(check) - $else: - $:row_ok(check) - + $ isError = services.get(check) + $if isError != 0: + $ errors=errors+1 + $if errors > 0: + $code: + color = "red" + txt = "{}: {} error(s)".format(env, errors) + $:table_contents(color, txt, services) + $else: + $ color = "green" + $:table_contents(color, env, services)