Browse Source

More efficient log updates.

pull/193/head
Pēteris Caune 6 years ago
parent
commit
ecba1eb40b
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 92 additions and 90 deletions
  1. +8
    -4
      hc/front/views.py
  2. +3
    -3
      static/js/details.js
  3. +81
    -83
      templates/front/details_events.html

+ 8
- 4
hc/front/views.py View File

@ -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


+ 3
- 3
static/js/details.js View File

@ -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");


+ 81
- 83
templates/front/details_events.html View File

@ -16,94 +16,92 @@
</div>
</h2>
<div id="log-container">
<table class="table" id="log">
{% for event in events %}
{% if event.n %}
<tr class="ok" data-dt="{{ event.created.isoformat }}" data-url="{% url 'hc-ping-details' check.code event.n %}">
<td class="n-cell">
<span class="hash">#</span>{{ event.n }}
</td>
<td class="date"></td>
<td class="time"></td>
<td class="text-right">
{% if event.fail %}
<span class="label label-danger">Failure</span>
{% else %}
<span class="label label-success">OK</span>
{% endif %}
</td>
<td class="details">
<div>
{% if event.scheme == "email" %}
{{ event.ua }}
<span class="ua-body">
{% if event.body %}
- {{ event.body|trunc }}
{% endif %}
</span>
{% else %}
{{ event.scheme|upper }}
{{ event.method }}
{% if event.remote_addr %}
from {{ event.remote_addr }}
<table class="table" id="log">
{% for event in events %}
{% if event.n %}
<tr class="ok" data-dt="{{ event.created.isoformat }}" data-url="{% url 'hc-ping-details' check.code event.n %}">
<td class="n-cell">
<span class="hash">#</span>{{ event.n }}
</td>
<td class="date"></td>
<td class="time"></td>
<td class="text-right">
{% if event.fail %}
<span class="label label-danger">Failure</span>
{% else %}
<span class="label label-success">OK</span>
{% endif %}
</td>
<td class="details">
<div>
{% if event.scheme == "email" %}
{{ event.ua }}
<span class="ua-body">
{% if event.body %}
- {{ event.body|trunc }}
{% endif %}
<span class="ua-body">
{% if event.ua %}
- {{ event.ua }}
{% endif %}
</span>
</span>
{% else %}
{{ event.scheme|upper }}
{{ event.method }}
{% if event.remote_addr %}
from {{ event.remote_addr }}
{% endif %}
</div>
</td>
</tr>
{% 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 }}
<span class="ua-body">
{% 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 %}
<br />
<strong>Error: {{ event.error }}</strong>
</span>
{% endif %}
</div>
</td>
</tr>
{% 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 %}
</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% 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 %}
<br />
<strong>Error: {{ event.error }}</strong>
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% if check.n_pings > 20 %}
<p class="text-center">
<a href="{% url 'hc-log' check.code %}">Show More&hellip;</a>
</p>
{% endif %}
</div>
{% if check.n_pings > 20 %}
<p class="text-center">
<a href="{% url 'hc-log' check.code %}">Show More&hellip;</a>
</p>
{% endif %}
{% else %}
<h2>Log</h2>
<div class="alert alert-info">This check has not received any pings yet.</div>

Loading…
Cancel
Save