From ecba1eb40ba327e7007019cdcf0f2a00157d58f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Sun, 19 Aug 2018 12:52:51 +0300 Subject: [PATCH] More efficient log updates. --- hc/front/views.py | 12 +- static/js/details.js | 6 +- templates/front/details_events.html | 164 ++++++++++++++-------------- 3 files changed, 92 insertions(+), 90 deletions(-) diff --git a/hc/front/views.py b/hc/front/views.py index 7c01173e..a1dadbd1 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -386,14 +386,18 @@ def status_single(request, code): events = _get_events(check, 20) updated = None if len(events): - updated = events[0].created.isoformat() + updated = events[0].created.replace(tzinfo=None).isoformat() - return JsonResponse({ + doc = { "status": status, "status_text": STATUS_TEXT_TMPL.render({"check": check}), - "events": EVENTS_TMPL.render({"check": check, "events": events}), "updated": updated - }) + } + + if updated != request.GET.get("u"): + doc["events"] = EVENTS_TMPL.render({"check": check, "events": events}) + + return JsonResponse(doc) @login_required diff --git a/static/js/details.js b/static/js/details.js index e192884c..15ce68ae 100644 --- a/static/js/details.js +++ b/static/js/details.js @@ -30,7 +30,7 @@ $(function () { var lastUpdated = ""; adaptiveSetInterval(function() { $.ajax({ - url: statusUrl, + url: statusUrl + (lastUpdated ? "?u=" + lastUpdated : ""), dataType: "json", timeout: 2000, success: function(data) { @@ -40,7 +40,7 @@ $(function () { $("#log-status-text").text(data.status_text); } - if (data.updated != lastUpdated) { + if (data.events) { lastUpdated = data.updated; $("#events").html(data.events); switchDateFormat(lastFormat); @@ -67,7 +67,7 @@ $(function () { 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-modal').modal("show"); diff --git a/templates/front/details_events.html b/templates/front/details_events.html index c467f30d..99f7e0b7 100644 --- a/templates/front/details_events.html +++ b/templates/front/details_events.html @@ -16,94 +16,92 @@ -
- - {% for event in events %} - {% if event.n %} - - - - - - + + {% endif %} + {% endfor %} +
- #{{ event.n }} - - {% if event.fail %} - Failure - {% else %} - OK - {% endif %} - -
- {% if event.scheme == "email" %} - {{ event.ua }} - - {% if event.body %} - - {{ event.body|trunc }} - {% endif %} - - {% else %} - {{ event.scheme|upper }} - {{ event.method }} - {% if event.remote_addr %} - from {{ event.remote_addr }} + + {% for event in events %} + {% if event.n %} + + + + + + - - {% endif %} - {% if event.check_status %} - - - - - + + {% endif %} + {% if event.check_status %} + + + + + - - {% endif %} - {% endfor %} -
+ #{{ event.n }} + + {% if event.fail %} + Failure + {% else %} + OK + {% endif %} + +
+ {% if event.scheme == "email" %} + {{ event.ua }} + + {% if event.body %} + - {{ event.body|trunc }} {% endif %} - - {% if event.ua %} - - {{ event.ua }} - {% endif %} - + + {% else %} + {{ event.scheme|upper }} + {{ event.method }} + {% if event.remote_addr %} + from {{ event.remote_addr }} {% endif %} -
-
- - - {% 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 }} + + {% if event.ua %} + - {{ event.ua }} {% endif %} - {% elif event.channel.kind == "pd" %} - Sent alert to PagerDuty - {% elif event.channel.kind == "pagertree" %} - Sent alert to PagerTree - {% elif event.channel.kind == "opsgenie" %} - Sent alert to OpsGenie - {% elif event.channel.kind == "hipchat" %} - Sent alert to HipChat - {% 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 %} -
- Error: {{ event.error }} +
+ {% endif %} + +
+ + + {% 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 %} -
+ {% elif event.channel.kind == "pd" %} + Sent alert to PagerDuty + {% elif event.channel.kind == "pagertree" %} + Sent alert to PagerTree + {% elif event.channel.kind == "opsgenie" %} + Sent alert to OpsGenie + {% elif event.channel.kind == "hipchat" %} + Sent alert to HipChat + {% 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 %} +
+ Error: {{ event.error }} + {% endif %} +
- {% if check.n_pings > 20 %} -

- Show More… -

- {% endif %} -
+ {% if check.n_pings > 20 %} +

+ Show More… +

+ {% endif %} {% else %}

Log

This check has not received any pings yet.