More efficient log updates.

This commit is contained in:
Pēteris Caune 2018-08-19 12:52:51 +03:00
parent a883fe38aa
commit ecba1eb40b
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 92 additions and 90 deletions

View File

@ -386,14 +386,18 @@ def status_single(request, code):
events = _get_events(check, 20) events = _get_events(check, 20)
updated = None updated = None
if len(events): if len(events):
updated = events[0].created.isoformat() updated = events[0].created.replace(tzinfo=None).isoformat()
return JsonResponse({ doc = {
"status": status, "status": status,
"status_text": STATUS_TEXT_TMPL.render({"check": check}), "status_text": STATUS_TEXT_TMPL.render({"check": check}),
"events": EVENTS_TMPL.render({"check": check, "events": events}),
"updated": updated "updated": updated
}) }
if updated != request.GET.get("u"):
doc["events"] = EVENTS_TMPL.render({"check": check, "events": events})
return JsonResponse(doc)
@login_required @login_required

View File

@ -30,7 +30,7 @@ $(function () {
var lastUpdated = ""; var lastUpdated = "";
adaptiveSetInterval(function() { adaptiveSetInterval(function() {
$.ajax({ $.ajax({
url: statusUrl, url: statusUrl + (lastUpdated ? "?u=" + lastUpdated : ""),
dataType: "json", dataType: "json",
timeout: 2000, timeout: 2000,
success: function(data) { success: function(data) {
@ -40,7 +40,7 @@ $(function () {
$("#log-status-text").text(data.status_text); $("#log-status-text").text(data.status_text);
} }
if (data.updated != lastUpdated) { if (data.events) {
lastUpdated = data.updated; lastUpdated = data.updated;
$("#events").html(data.events); $("#events").html(data.events);
switchDateFormat(lastFormat); switchDateFormat(lastFormat);
@ -67,7 +67,7 @@ $(function () {
prompt("Press Ctrl+C to select:", text) prompt("Press Ctrl+C to select:", text)
}); });
$("#log tr.ok").on("click", function() { $("#events").on("click", "tr.ok", function() {
$("#ping-details-body").text("Updating..."); $("#ping-details-body").text("Updating...");
$('#ping-details-modal').modal("show"); $('#ping-details-modal').modal("show");

View File

@ -16,94 +16,92 @@
</div> </div>
</h2> </h2>
<div id="log-container"> <table class="table" id="log">
<table class="table" id="log"> {% for event in events %}
{% for event in events %} {% if event.n %}
{% if event.n %} <tr class="ok" data-dt="{{ event.created.isoformat }}" data-url="{% url 'hc-ping-details' check.code event.n %}">
<tr class="ok" data-dt="{{ event.created.isoformat }}" data-url="{% url 'hc-ping-details' check.code event.n %}"> <td class="n-cell">
<td class="n-cell"> <span class="hash">#</span>{{ event.n }}
<span class="hash">#</span>{{ event.n }} </td>
</td> <td class="date"></td>
<td class="date"></td> <td class="time"></td>
<td class="time"></td> <td class="text-right">
<td class="text-right"> {% if event.fail %}
{% if event.fail %} <span class="label label-danger">Failure</span>
<span class="label label-danger">Failure</span> {% else %}
{% else %} <span class="label label-success">OK</span>
<span class="label label-success">OK</span> {% endif %}
{% endif %} </td>
</td> <td class="details">
<td class="details"> <div>
<div> {% if event.scheme == "email" %}
{% if event.scheme == "email" %} {{ event.ua }}
{{ event.ua }} <span class="ua-body">
<span class="ua-body"> {% if event.body %}
{% if event.body %} - {{ event.body|trunc }}
- {{ event.body|trunc }}
{% endif %}
</span>
{% else %}
{{ event.scheme|upper }}
{{ event.method }}
{% if event.remote_addr %}
from {{ event.remote_addr }}
{% endif %} {% endif %}
<span class="ua-body"> </span>
{% if event.ua %} {% else %}
- {{ event.ua }} {{ event.scheme|upper }}
{% endif %} {{ event.method }}
</span> {% if event.remote_addr %}
from {{ event.remote_addr }}
{% endif %} {% endif %}
</div> <span class="ua-body">
</td> {% if event.ua %}
</tr> - {{ event.ua }}
{% endif %}
{% if event.check_status %}
<tr class="missing" data-dt="{{ event.created.isoformat }}">
<td class="n-cell">
<span class="icon-missing"></span>
</td>
<td class="date"></td>
<td class="time"></td>
<td class="alert-info" colspan="2">
{% if event.channel.kind == "email" %}
Sent email alert to {{ event.channel.value }}
{% elif event.channel.kind == "slack" %}
Sent Slack alert
{% if event.channel.slack_channel %}
to {{ event.channel.slack_channel }}
{% endif %} {% endif %}
{% elif event.channel.kind == "pd" %} </span>
Sent alert to PagerDuty {% endif %}
{% elif event.channel.kind == "pagertree" %} </div>
Sent alert to PagerTree </td>
{% elif event.channel.kind == "opsgenie" %} </tr>
Sent alert to OpsGenie {% endif %}
{% elif event.channel.kind == "hipchat" %} {% if event.check_status %}
Sent alert to HipChat <tr class="missing" data-dt="{{ event.created.isoformat }}">
{% elif event.channel.kind == "po" %} <td class="n-cell">
Sent a Pushover notification <span class="icon-missing"></span>
{% elif event.channel.kind == "webhook" %} </td>
Called webhook {{ event.channel.url_down }} <td class="date"></td>
{% else %} <td class="time"></td>
Sent alert to {{ event.channel.kind|capfirst }} <td class="alert-info" colspan="2">
{% if event.channel.kind == "email" %}
Sent email alert to {{ event.channel.value }}
{% elif event.channel.kind == "slack" %}
Sent Slack alert
{% if event.channel.slack_channel %}
to {{ event.channel.slack_channel }}
{% endif %} {% endif %}
{% if event.error %} {% elif event.channel.kind == "pd" %}
<br /> Sent alert to PagerDuty
<strong>Error: {{ event.error }}</strong> {% elif event.channel.kind == "pagertree" %}
{% endif %} Sent alert to PagerTree
</td> {% elif event.channel.kind == "opsgenie" %}
</tr> Sent alert to OpsGenie
{% endif %} {% elif event.channel.kind == "hipchat" %}
{% endfor %} Sent alert to HipChat
</table> {% elif event.channel.kind == "po" %}
Sent a Pushover notification
{% elif event.channel.kind == "webhook" %}
Called webhook {{ event.channel.url_down }}
{% else %}
Sent alert to {{ event.channel.kind|capfirst }}
{% endif %}
{% if event.error %}
<br />
<strong>Error: {{ event.error }}</strong>
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% if check.n_pings > 20 %} {% if check.n_pings > 20 %}
<p class="text-center"> <p class="text-center">
<a href="{% url 'hc-log' check.code %}">Show More&hellip;</a> <a href="{% url 'hc-log' check.code %}">Show More&hellip;</a>
</p> </p>
{% endif %} {% endif %}
</div>
{% else %} {% else %}
<h2>Log</h2> <h2>Log</h2>
<div class="alert alert-info">This check has not received any pings yet.</div> <div class="alert alert-info">This check has not received any pings yet.</div>