This commit is contained in:
Saravanan Palanisamy 2020-03-11 18:09:29 +04:00 committed by GitHub
commit d029e7182e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 126 additions and 62 deletions

View File

@ -10,6 +10,7 @@ import datetime
from collections import OrderedDict from collections import OrderedDict
from operator import itemgetter from operator import itemgetter
import utils import utils
import re
urls = ('/', 'index', urls = ('/', 'index',
'/help', 'help', '/help', 'help',
@ -26,21 +27,41 @@ web.config.debug = False
output = [] output = []
# Functions # Functions
def calculate_count(data): def calculate_count(data):
count = {} count = {}
ls = data.values()
z, nz = 0, 0 z, nz = 0, 0
for v in ls: for _,v in data.items():
if v == 0: ls = v.values()
z += 1 for v in ls:
else: if v == 0:
nz += 1 z += 1
else:
nz += 1
count['green'] = z count['green'] = z
count['red'] = nz count['red'] = nz
return count return count
def arrange_services(services):
checks = {}
for service in services:
name = service['name']
name1, _, name2 = name.partition('-')
if name2 == '':
name2 = name1
name1 = 'others'
name1 = re.sub("([a-z])([A-Z])","\g<1> \g<2>",name1)
if name1 not in list(checks.keys()):
checks[name1] = OrderedDict()
checks[name1][name2] = int(service['status'])
return checks
def sorted_checks(checks):
s_checks = {}
for k,v in checks.iteritems():
s_checks[k] = OrderedDict(
sorted(v.iteritems(),key=itemgetter(1), reverse=True)
)
return s_checks
def getMonit(): def getMonit():
output = [] output = []
@ -57,22 +78,13 @@ def getMonit():
allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit'])) allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit']))
services = allstat['service'] services = allstat['service']
status = {}
server = {} server = {}
checks = OrderedDict()
for service in services: checks = arrange_services(services)
name = service['name'] s_checks = sorted_checks(checks)
status[name] = int(service['status']) count = calculate_count(s_checks)
checks[name] = status[name]
sorted_checks = OrderedDict()
sorted_checks = OrderedDict(sorted(checks.iteritems(),
key=itemgetter(1), reverse=True))
count = calculate_count(sorted_checks)
server = dict(name=site, url=s['url'], server = dict(name=site, url=s['url'],
result=sorted_checks, s_rate=count) result=s_checks, s_rate=count)
output.append(server) output.append(server)
print(datetime.datetime.now()) print(datetime.datetime.now())
return(output) return(output)

View File

@ -10,6 +10,11 @@ th {
padding: 10px; padding: 10px;
} }
.th-custom {
padding: 10px;
font-weight: 300;
}
td { td {
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
padding: 15px; padding: 15px;
@ -68,11 +73,11 @@ div.download-header {
div.panel { div.panel {
padding: 0 18px; padding: 0 18px;
background-color: white; background-color: white;
display: none; display: block;
} }
div.panel.show { div.panel.show {
display: block; display: none;
} }
.green { .green {
@ -117,3 +122,11 @@ div.panel.show {
background-color: #F2F2F2; background-color: #F2F2F2;
text-align: center; text-align: center;
} }
tbody.toggle-id {
display: none;
}
tbody.toggle-id.show {
display: contents;
}

View File

@ -8,6 +8,16 @@ for (i = 0; i < acc.length; i++) {
} }
} }
var acc = document.getElementsByClassName("inner-rows");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function() {
this.classList.toggle("active");
this.nextElementSibling.classList.toggle("show");
}
}
function draw(rate) { function draw(rate) {
var count = [rate['green'], rate['red']]; var count = [rate['green'], rate['red']];
var percentage = [ var percentage = [
@ -41,13 +51,11 @@ function draw(rate) {
ctx.moveTo(200 + offsetX, 200 + offsetY); ctx.moveTo(200 + offsetX, 200 + offsetY);
ctx.arc(200 + offsetX, 200 + offsetY, 120, beginAngle, endAngle); ctx.arc(200 + offsetX, 200 + offsetY, 120, beginAngle, endAngle);
ctx.lineTo(200 + offsetX, 200 + offsetY); ctx.lineTo(200 + offsetX, 200 + offsetY);
// ctx.stroke();
ctx.fill(); ctx.fill();
ctx.rect(canvas.width - 129, i * 20 + 10, 10, 10); ctx.rect(canvas.width - 129, i * 20 + 10, 10, 10);
ctx.fill(); ctx.fill();
ctx.font = "13px sans-serif"; ctx.font = "13px sans-serif";
//ctx.font = "20px Georgia";
ctx.fillText(status[i] + " - " + count[i] + " (" + ctx.fillText(status[i] + " - " + count[i] + " (" +
Number(percentage[i]).toFixed(1) + "%)", Number(percentage[i]).toFixed(1) + "%)",
canvas.width - 109, i * 20 + 20); canvas.width - 109, i * 20 + 20);

View File

@ -1,5 +1,36 @@
$def with (output, now) $def with (output, now)
<!-- Functions -->
$def row_error(check):
<tr>
<td><a href="$output[server]['url']/$env-$check"
target="_blank" style="text-decoration:none;">$check</a></td>
<td><img src="static/img/error.png"></td>
</tr>
$def row_ok(check):
<tr>
<td><a href="$output[server]['url']/$env-$check"
target="_blank" style="text-decoration:none; color:black;">$check</a></td>
<td><img src="static/img/ok.png"></td>
</tr>
$def table_contents(color, text, services):
<thead class="inner-rows">
<tr><th class="th-custom ${color}" colspan="2">
<a style="color: white">$text</a>
</th></tr>
</thead>
<tbody class="toggle-id">
$for check in services.keys():
$ isError = services.get(check)
$if isError != 0:
$:row_error(check)
$else:
$:row_ok(check)
</tbody>
<!-- Main Content -->
<body onload="draw($output[0]['s_rate']);"> <body onload="draw($output[0]['s_rate']);">
$ errors = 0 $ errors = 0
$ color = "green" $ color = "green"
@ -13,11 +44,12 @@ $def with (output, now)
errors = 0 errors = 0
color = "green" color = "green"
$for check in output[server]['result'].keys(): $for _,v in output[server]['result'].items():
$ isError = output[server]['result'].get(check) $for check in v.keys():
$if isError != 0: $ isError = v.get(check)
$code: $if isError != 0:
errors=errors+1 $code:
errors=errors+1
$if errors > 0: $if errors > 0:
$code: $code:
@ -27,26 +59,26 @@ $def with (output, now)
<br> <br>
<table width=100%> <table width=100%>
<thead class="server-link"> <!-- <thead class="server-link">
<tr><th colspan="2"> <tr><th colspan="2">
<a href="$output[server]['url']" target="_blank">$output[server]['name']</a> <a href="$output[server]['url']" target="_blank">$output[server]['name']</a>
</th></tr> </th></tr>
</thead> </thead> -->
$for check in output[server]['result'].keys(): $for env, services in output[server]['result'].items():
$ isError = output[server]['result'].get(check) $ errors = 0
$for check in services.keys():
$ isError = services.get(check)
$if isError != 0: $if isError != 0:
<tr> $ errors=errors+1
<td><a href="$output[server]['url']/$check" $if errors > 0:
target="_blank">$check</a></td> $code:
<td><a href="$output[server]['url']/$check" color = "red"
target="_blank"><img src="static/img/error.png"></a></td> txt = "{}: {} error(s)".format(env, errors)
</tr> $:table_contents(color, txt, services)
$else: $else:
<tr> $code:
<td>$check</td> color = "green"
<td><img src="static/img/ok.png"></td> $:table_contents(color, env, services)
</tr>
</table> </table>
</div> </div>
$else: $else:
@ -57,26 +89,25 @@ $def with (output, now)
<br> <br>
<table width=100%> <table width=100%>
<thead class="server-link"> <!-- <thead class="server-link">
<tr><th colspan="2"> <tr><th colspan="2">
<a href="$output[server]['url']" target="_blank">$output[server]['name']</a> <a href="$output[server]['url']" target="_blank">$output[server]['name']</a>
</th></tr> </th></tr>
</thead> </thead> -->
$for check in output[server]['result'].keys(): $for env, services in output[server]['result'].items():
$ isError = output[server]['result'].get(check) $ errors = 0
$for check in services.keys():
$ isError = services.get(check)
$if isError != 0: $if isError != 0:
<tr> $ errors=errors+1
<td><a href="$output[server]['url']/$check" $if errors > 0:
target="_blank">$check</a></td> $code:
<td><a href="$output[server]['url']/$check" color = "red"
target="_blank"><img src="static/img/error.png"></a></td> txt = "{}: {} error(s)".format(env, errors)
</tr> $:table_contents(color, txt, services)
$else: $else:
<tr> $ color = "green"
<td>$check</td> $:table_contents(color, env, services)
<td><img src="static/img/ok.png"></td>
</tr>
</table> </table>
</div> </div>
</div> </div>