Tidy up alert rendering.

This commit is contained in:
Matthew Stratford 2021-09-22 00:57:51 +01:00
parent bc2e60cdc9
commit b8c6f087c6
6 changed files with 23 additions and 20 deletions

View file

@ -5,6 +5,7 @@ from datetime import datetime, timedelta
from helpers.os_environment import resolve_external_file_path from helpers.os_environment import resolve_external_file_path
from helpers.alert_manager import AlertProvider from helpers.alert_manager import AlertProvider
from baps_types.alert import CRITICAL, WARNING, Alert from baps_types.alert import CRITICAL, WARNING, Alert
from baps_types.happytime import happytime
MODULE = "Player" # This should match the log file, so the UI will link to the logs page. MODULE = "Player" # This should match the log file, so the UI will link to the logs page.
@ -86,7 +87,7 @@ class PlayerAlertProvider(AlertProvider):
This likely means there was an unhandled exception in the player code, causing the server to restart the player. This likely means there was an unhandled exception in the player code, causing the server to restart the player.
Please check player logs to investigate the cause. Please restart the server to clear this warning.""" Please check player logs to investigate the cause. Please restart the server to clear this warning."""
.format(channel, str(start_time).rsplit(".",1)[0], str(server_start_time).rsplit(".",1)[0]), .format(channel, happytime(start_time), happytime(server_start_time)),
"module": MODULE+str(channel), "module": MODULE+str(channel),
"severity": WARNING "severity": WARNING
})) }))

View file

@ -5,6 +5,7 @@ from datetime import datetime, timedelta
from helpers.os_environment import resolve_external_file_path from helpers.os_environment import resolve_external_file_path
from helpers.alert_manager import AlertProvider from helpers.alert_manager import AlertProvider
from baps_types.alert import CRITICAL, WARNING, Alert from baps_types.alert import CRITICAL, WARNING, Alert
from baps_types.happytime import happytime
MODULE = "BAPSicleServer" # This should match the log file, so the UI will link to the logs page. MODULE = "BAPSicleServer" # This should match the log file, so the UI will link to the logs page.
@ -66,7 +67,7 @@ class ServerAlertProvider(AlertProvider):
It may have been automatically restarted by the OS. It may have been automatically restarted by the OS.
If this is not expected, please check logs to investigate why BAPSicle restarted/crashed.""" If this is not expected, please check logs to investigate why BAPSicle restarted/crashed."""
.format(str(start_time).rsplit(".",1)[0]), .format(happytime(start_time)),
"module": MODULE, "module": MODULE,
"severity": WARNING "severity": WARNING
})] })]

3
baps_types/happytime.py Normal file
View file

@ -0,0 +1,3 @@
from datetime import datetime
def happytime(date: datetime):
return date.strftime("%Y-%m-%d %H:%M:%S")

View file

@ -5,14 +5,10 @@
{% endblock %} {% endblock %}
{% block content_inner %} {% block content_inner %}
{% if data %} {% if data %}
<h2>Current Alerts: {{ data.alert_count_current }}</h2> <h3 class="h4">Current Alerts: {{ data.alerts_current | length }}</h3>
<div class="accordion" id="accordionExample">
{{ alert_list(data.alerts_current) }} {{ alert_list(data.alerts_current) }}
</div>
<hr> <hr>
<h2>Previous Alerts: {{ data.alert_count_previous }}</h2> <h3 class="h4">Previous Alerts: {{ data.alerts_previous | length }}</h3>
<div class="accordion" id="accordionExample">
{{ alert_list(data.alerts_previous) }} {{ alert_list(data.alerts_previous) }}
</div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -2,21 +2,17 @@
{% for alert in alerts %} {% for alert in alerts %}
<div class="card alert-{{ alert.ui_class }}"> <div class="card alert-{{ alert.ui_class }}">
<div class="card-header" id="headingOne"> <div class="card-header" id="headingOne">
<h2 class="mb-0">
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
{{ alert.title }}
</button>
<span class="badge badge-{{ alert.ui_class}}">{{ alert.severity }}</span> <span class="badge badge-{{ alert.ui_class}}">{{ alert.severity }}</span>
</h2> <h4 class="h5 mb-0 mt-1">{{ alert.title }}</h4>
<span class="badge">Since {{ alert.start_time }}</span> <span class="badge badge-primary">Since {{ alert.start_time | happytime }}</span>
<span class="badge">Last Seen {{ alert.last_time }}</span> <span class="badge badge-secondary">Last Seen {{ alert.last_time | happytime }}</span>
{% if alert.end_time %} {% if alert.end_time %}
<span class="badge">Ended {{ alert.end_time }}</span> <span class="badge badge-success">Ended {{ alert.end_time | happytime }}</span>
{% endif %} {% endif %}
</div> </div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample"> <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body"> <div class="card-body pb-0">
<strong>Module: </strong><a href="/logs/{{ alert.module }}" title="Click for logs">{{ alert.module }}</a> <strong>Module: </strong><a href="/logs/{{ alert.module }}" title="Click for logs">{{ alert.module }}</a>
{% autoescape false %} {% autoescape false %}
<p>{{ alert.description | replace("\n\n", "</p><p>") | replace("\n", "<br/>")}}</p> <p>{{ alert.description | replace("\n\n", "</p><p>") | replace("\n", "<br/>")}}</p>

View file

@ -28,6 +28,7 @@ from helpers.normalisation import get_normalised_filename_if_available
from helpers.myradio_api import MyRadioAPI from helpers.myradio_api import MyRadioAPI
from helpers.alert_manager import AlertManager from helpers.alert_manager import AlertManager
import package import package
from baps_types.happytime import happytime
env = Environment( env = Environment(
loader=FileSystemLoader("%s/ui-templates/" % os.path.dirname(__file__)), loader=FileSystemLoader("%s/ui-templates/" % os.path.dirname(__file__)),
@ -95,6 +96,11 @@ def render_template(file, data, status=200):
return html(html_content, status=status) return html(html_content, status=status)
def _filter_happytime(date):
return happytime(date)
env.filters["happytime"] = _filter_happytime
logger: LoggingManager logger: LoggingManager
server_state: StateManager server_state: StateManager
api: MyRadioAPI api: MyRadioAPI