Skip to content

Commit

Permalink
Add a status dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Hubl committed Jun 17, 2015
1 parent e443d84 commit 747941d
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
61 changes: 61 additions & 0 deletions watchman/templates/watchman/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends "base.html" %}

{% load i18n %}

{% block content %}
<h2>System Status{% if overall_status == 'OK' %} <small>All systems up and running!</small>{% endif %}</h2>

<table class="table table-bordered table-hover">
<thead>
<tr>
<th>{% trans 'Type' %}</th>
<th>{% trans 'Name' %}</th>
<th>{% trans 'Status' %}</th>
</tr>
</thead>
<tbody>
{% for type in checks %}
{% for thing in type.statuses %}
<tr>
<td class="{% if type.overall_status == 'OK' %}bg-success{% endif %}">{{ type.type|title }}</td>
<td>{{ thing.name|title }}</td>

{% if thing.status == 'OK' %}
<td class="success">{{ thing.status }}</td>

{% else %}
<td class="danger">
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#{{ type.type }}-{{ thing.name }}">ERROR!</button>

<div class="modal fade" id="{{ type.type }}-{{ thing.name }}" tabindex="-1" role="dialog" aria-labelledby="{{ type.type }}-{{ thing.name }}-title">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="{{ type.type }}-{{ thing.name }}-title">{{ type.type|title }} - {{ thing.name|title }}</h4>
</div><!-- class="modal-header" -->
<div class="modal-body">
<h4><pre>{{ thing.error }}</pre></h4>
<pre>{{ thing.traceback }}</pre>
</div><!-- class="model-body" -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div><!-- class="modal-footer" -->
</div>
</div>
</div>
</td>
{% endif %}{# thing.status == 'OK' #}

</tr>
{% endfor %}{# for thing in type.statuses #}
{% empty %}
<tr>
<td colspan="3">No checks indicated</td>
</tr>
{% endfor %}{# for type in checks #}
</tbody>
</table>

<span class="pull-right"><small>Click an error button to see the full traceback</small></span>
{% endblock %}{# status_content #}
1 change: 1 addition & 0 deletions watchman/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
urlpatterns = patterns(
'',
url(r'^$', 'watchman.views.status', name="status"),
url(r'^dashboard/$', 'watchman.views.dashboard', name="dashboard"),
)
45 changes: 45 additions & 0 deletions watchman/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import unicode_literals

from django.http import Http404
from django.shortcuts import render

from jsonview.decorators import json_view
from watchman.decorators import token_required
Expand Down Expand Up @@ -31,3 +32,47 @@ def status(request):
raise Http404('No checks found')

return response


@token_required
def dashboard(request):
check_types = []
checks = {}

for check in get_checks(None, None):
if callable(check):
_check = check()

for _type in _check:
# _check[_type] is a list of dictionaries:
# Example: [{'default': {'ok': True}}]
statuses = []

for a in _check[_type]:
status = {}

# Systems like storage don't have names
if a == 'ok':
status['name'] = ''
status['status'] = 'OK'
status['error'] = ''
status['stacktrace'] = ''
else:
for name in a:
status['name'] = name
status['status'] = 'OK' if a[name]['ok'] else 'ERROR'
status['error'] = a[name]['error'] if not a[name]['ok'] else ''
status['stacktrace'] = a[name]['stacktrace'] if not a[name]['ok'] else ''

statuses.append(status)

type_overall_status = 'OK' if all([status['status'] == 'OK' for status in statuses]) else 'ERROR'

check_types.append({
'type': _type,
'overall_status': type_overall_status,
'statuses': statuses})

overall_status = 'OK' if all([type_status['overall_status'] == 'OK' for type_status in check_types]) else 'ERROR'

return render(request, 'watchman/dashboard.html', {'checks': check_types, 'overall_status': overall_status})

0 comments on commit 747941d

Please sign in to comment.