[minor] track activity status, modify html output for stylesheet
This commit is contained in:
parent
d35c176aab
commit
ae0c2ef4e9
@ -8,7 +8,7 @@ channel_names: ["Temperature (°)", "Voltage (V)", "Voltage (V)", "Voltage (V)"]
|
|||||||
stations_blacklist: ["TEST", "EREA"]
|
stations_blacklist: ["TEST", "EREA"]
|
||||||
networks_blacklist: []
|
networks_blacklist: []
|
||||||
interval: 60 # Perform checks every x seconds
|
interval: 60 # Perform checks every x seconds
|
||||||
n_track: 120 # wait number of intervals after FAIL before performing an action (i.e. send mail)
|
n_track: 120 # wait n FAIL intervals before performing an action (i.e. send mail + end highlight status)
|
||||||
timespan: 3 # Check data of the recent x days
|
timespan: 3 # Check data of the recent x days
|
||||||
verbosity: 0
|
verbosity: 0
|
||||||
track_changes: True # tracks all changes since GUI startup by text highlighting (GUI only)
|
track_changes: True # tracks all changes since GUI startup by text highlighting (GUI only)
|
||||||
|
22
survBot.py
22
survBot.py
@ -352,7 +352,7 @@ class SurveillanceBot(object):
|
|||||||
fig.savefig(fnout, dpi=150., bbox_inches='tight')
|
fig.savefig(fnout, dpi=150., bbox_inches='tight')
|
||||||
plt.close(fig)
|
plt.close(fig)
|
||||||
|
|
||||||
def write_html_table(self, default_color='#e6e6e6'):
|
def write_html_table(self, default_color='#e6e6e6', default_header_color='#999'):
|
||||||
self.check_html_dir()
|
self.check_html_dir()
|
||||||
fnout = pjoin(self.outpath_html, 'survBot_out.html')
|
fnout = pjoin(self.outpath_html, 'survBot_out.html')
|
||||||
if not fnout:
|
if not fnout:
|
||||||
@ -368,16 +368,17 @@ class SurveillanceBot(object):
|
|||||||
# add columns for additional links
|
# add columns for additional links
|
||||||
for key in self.add_links:
|
for key in self.add_links:
|
||||||
header.insert(-1, key)
|
header.insert(-1, key)
|
||||||
header_items = [dict(text='Station', color=default_color)]
|
header_items = [dict(text='Station', color=default_header_color)]
|
||||||
for check_key in header:
|
for check_key in header:
|
||||||
item = dict(text=check_key, color=default_color)
|
item = dict(text=check_key, color=default_header_color)
|
||||||
header_items.append(item)
|
header_items.append(item)
|
||||||
write_html_row(outfile, header_items, html_key='th')
|
write_html_row(outfile, header_items, html_key='th')
|
||||||
|
|
||||||
# Write all cells
|
# Write all cells
|
||||||
for nwst_id in self.station_list:
|
for nwst_id in self.station_list:
|
||||||
fig_name = self.get_fig_path_rel(nwst_id)
|
fig_name = self.get_fig_path_rel(nwst_id)
|
||||||
col_items = [dict(text=nwst_id.rstrip('.'), color=default_color, hyperlink=fig_name)]
|
col_items = [dict(text=nwst_id.rstrip('.'), color=default_color, hyperlink=fig_name,
|
||||||
|
bold=True)]
|
||||||
for check_key in header:
|
for check_key in header:
|
||||||
if check_key in self.keys:
|
if check_key in self.keys:
|
||||||
status_dict = self.analysis_results.get(nwst_id)
|
status_dict = self.analysis_results.get(nwst_id)
|
||||||
@ -395,7 +396,8 @@ class SurveillanceBot(object):
|
|||||||
if not type(message) in [str]:
|
if not type(message) in [str]:
|
||||||
message = str(message) + deg_str
|
message = str(message) + deg_str
|
||||||
|
|
||||||
item = dict(text=str(message), tooltip=str(detailed_message), color=bg_color)
|
item = dict(text=str(message), tooltip=str(detailed_message), color=bg_color,
|
||||||
|
blink=status.is_active)
|
||||||
elif check_key in self.add_links:
|
elif check_key in self.add_links:
|
||||||
value = self.add_links.get(check_key).get('URL')
|
value = self.add_links.get(check_key).get('URL')
|
||||||
link_text = self.add_links.get(check_key).get('text')
|
link_text = self.add_links.get(check_key).get('text')
|
||||||
@ -517,18 +519,21 @@ class StationQC(object):
|
|||||||
current_status.count += count
|
current_status.count += count
|
||||||
else:
|
else:
|
||||||
current_status = new_error
|
current_status = new_error
|
||||||
# refresh plot (using parent class) if error is new and not on program-startup
|
# if error is new and not on program-startup set active and refresh plot (using parent class)
|
||||||
if self.search_previous_errors(key, n_errors=1):
|
if self.search_previous_errors(key, n_errors=1):
|
||||||
|
current_status.is_active = True
|
||||||
self.parent.write_html_figure(self.nwst_id)
|
self.parent.write_html_figure(self.nwst_id)
|
||||||
|
|
||||||
self._update_status(key, current_status, detailed_message, last_occurrence)
|
|
||||||
|
|
||||||
if self.verbosity:
|
if self.verbosity:
|
||||||
self.print(f'{UTCDateTime()}: {detailed_message}', flush=False)
|
self.print(f'{UTCDateTime()}: {detailed_message}', flush=False)
|
||||||
|
|
||||||
# do not send error mail if this is the first run (e.g. program startup) or state was already error (unchanged)
|
# do not send error mail if this is the first run (e.g. program startup) or state was already error (unchanged)
|
||||||
if self.search_previous_errors(key):
|
if self.search_previous_errors(key):
|
||||||
self.send_mail(key, detailed_message)
|
self.send_mail(key, detailed_message)
|
||||||
|
# set status to "inactive" after sending info mail
|
||||||
|
current_status.is_active = False
|
||||||
|
|
||||||
|
self._update_status(key, current_status, detailed_message, last_occurrence)
|
||||||
|
|
||||||
def search_previous_errors(self, key, n_errors=None):
|
def search_previous_errors(self, key, n_errors=None):
|
||||||
"""
|
"""
|
||||||
@ -908,6 +913,7 @@ class Status(object):
|
|||||||
self.is_warn = None
|
self.is_warn = None
|
||||||
self.is_error = None
|
self.is_error = None
|
||||||
self.is_other = False
|
self.is_other = False
|
||||||
|
self.is_active = False
|
||||||
|
|
||||||
def set_warn(self):
|
def set_warn(self):
|
||||||
self.is_warn = True
|
self.is_warn = True
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
def write_html_table_title(fobj, parameters):
|
def write_html_table_title(fobj, parameters):
|
||||||
title = get_print_title_str(parameters)
|
title = get_print_title_str(parameters)
|
||||||
fobj.write(f'<h3>{title}</h3>\n')
|
fobj.write(f'<h3>{title}</h3>\n')
|
||||||
|
|
||||||
|
|
||||||
def write_html_text(fobj, text):
|
def write_html_text(fobj, text):
|
||||||
fobj.write(f'<p>{text}</p>\n')
|
fobj.write(f'<p>{text}</p>\n')
|
||||||
|
|
||||||
|
|
||||||
def write_html_header(fobj, refresh_rate=10):
|
def write_html_header(fobj, refresh_rate=10):
|
||||||
header = ['<!DOCTYPE html>',
|
header = ['<!DOCTYPE html>',
|
||||||
'<html>',
|
'<html>',
|
||||||
@ -24,35 +27,44 @@ def write_html_header(fobj, refresh_rate=10):
|
|||||||
for item in header:
|
for item in header:
|
||||||
fobj.write(item + '\n')
|
fobj.write(item + '\n')
|
||||||
|
|
||||||
|
|
||||||
def init_html_table(fobj):
|
def init_html_table(fobj):
|
||||||
fobj.write('<table style="width:100%">\n')
|
fobj.write('<table style="width:100%">\n')
|
||||||
|
|
||||||
|
|
||||||
def finish_html_table(fobj):
|
def finish_html_table(fobj):
|
||||||
fobj.write('</table>\n')
|
fobj.write('</table>\n')
|
||||||
|
|
||||||
|
|
||||||
def write_html_footer(fobj):
|
def write_html_footer(fobj):
|
||||||
footer = ['</body>',
|
footer = ['</body>',
|
||||||
'</html>']
|
'</html>']
|
||||||
for item in footer:
|
for item in footer:
|
||||||
fobj.write(item + '\n')
|
fobj.write(item + '\n')
|
||||||
|
|
||||||
|
|
||||||
def write_html_row(fobj, items, html_key='td'):
|
def write_html_row(fobj, items, html_key='td'):
|
||||||
default_space = ' '
|
default_space = ' '
|
||||||
fobj.write(default_space + '<tr>\n')
|
fobj.write(default_space + '<tr>\n')
|
||||||
for item in items:
|
for item in items:
|
||||||
text = item.get('text')
|
text = item.get('text')
|
||||||
|
if item.get('bold'):
|
||||||
|
text = '<b>' + text + '</b>'
|
||||||
|
if item.get('italic'):
|
||||||
|
text = '<i>' + text + '</i>'
|
||||||
tooltip = item.get('tooltip')
|
tooltip = item.get('tooltip')
|
||||||
color = item.get('color')
|
color = item.get('color')
|
||||||
# check for black background of headers (shouldnt happen anymore)
|
# check for black background of headers (shouldnt happen anymore)
|
||||||
color = '#e6e6e6' if color == '#000000' else color
|
color = '#e6e6e6' if color == '#000000' else color
|
||||||
hyperlink = item.get('hyperlink')
|
hyperlink = item.get('hyperlink')
|
||||||
image_str = f'<a href="{hyperlink}">' if hyperlink else ''
|
image_str = f'<a href="{hyperlink}">' if hyperlink else ''
|
||||||
fobj.write(2 * default_space + f'<{html_key} bgcolor="{color}" title="{tooltip}"> {image_str}'
|
blink_str = f' class="blink-bg"' if item.get('blink') else ''
|
||||||
|
fobj.write(2 * default_space + f'<{html_key}{blink_str} bgcolor="{color}" title="{tooltip}"> {image_str}'
|
||||||
+ text + f'</{html_key}>\n')
|
+ text + f'</{html_key}>\n')
|
||||||
fobj.write(default_space + '</tr>\n')
|
fobj.write(default_space + '</tr>\n')
|
||||||
|
|
||||||
|
|
||||||
def get_print_title_str(parameters):
|
def get_print_title_str(parameters):
|
||||||
timespan = parameters.get('timespan') * 24 * 3600
|
timespan = parameters.get('timespan') * 24 * 3600
|
||||||
tdelta_str = str(timedelta(seconds=int(timespan))).replace(', 0:00:00', '')
|
tdelta_str = str(timedelta(seconds=int(timespan))).replace(', 0:00:00', '')
|
||||||
return f'Analysis table of router quality within the last {tdelta_str}'
|
return f'Analysis table of router quality within the last {tdelta_str}'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user