Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added groups to history page #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions history.html.theme
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@
color: var(--heading-color);
text-align: center;
}
.history-group {
margin-bottom: 40px;
}
.history-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
margin-bottom: 40px;
}
.history-item {
background: var(--card-bg);
Expand All @@ -59,7 +61,7 @@
max-height: 300px;
overflow: auto;
}
.history-item h2 {
.history-item h3 {
font-size: 1.2rem;
margin: 0;
}
Expand All @@ -86,21 +88,28 @@
</head>
<body>
<h1>TinyStatus History</h1>
<div class="history-grid">
{% for service, entries in history.items() %}
<div class="history-item">
<h2>{{ service }}</h2>
{% for entry in entries|reverse %}
<div class="history-entry">
<span>{{ entry.timestamp.split('T')[0] }} {{ entry.timestamp.split('T')[1][:8] }}</span>
<span class="{% if entry.status %}status-up{% else %}status-down{% endif %}">
{{ 'Up' if entry.status else 'Down' }}
</span>

{% for group in history.groups %}
<div class="history-group">
<h2>{{ group.title }}</h2>
<div class="history-grid">
{% for service, entries in group.checks.items() %}
<div class="history-item">
<h3>{{ service }}</h3>
{% for entry in entries|reverse %}
<div class="history-entry">
<span>{{ entry.timestamp.split('T')[0] }} {{ entry.timestamp.split('T')[1][:8] }}</span>
<span class="{% if entry.status %}status-up{% else %}status-down{% endif %}">
{{ 'Up' if entry.status else 'Down' }}
</span>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endfor %}

<div class="footer">
<p>Last updated: {{ last_updated }}</p>
<p><a href="index.html">Back to Current Status</a></p>
Expand Down
23 changes: 15 additions & 8 deletions tinystatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,20 @@ def save_history(history):


def update_history(results):
# TODO: Configure groups in history page
history = load_history()
current_time = datetime.now().isoformat()
for group in results.keys():
for check in results[group]:
if check['name'] not in history:
history[check['name']] = []
history[check['name']].append({'timestamp': current_time, 'status': check['status']})
history[check['name']] = history[check['name']][-MAX_HISTORY_ENTRIES:]
if 'groups' not in history:
history['groups'] = []
for group_title, checks in results.items():
group_found = next((group for group in history['groups'] if group['title'] == group_title), None)
if group_found is None:
group_found = {'title': group_title, 'checks': {}}
history['groups'].append(group_found)
for check in checks:
if check['name'] not in group_found['checks']:
group_found['checks'][check['name']] = []
group_found['checks'][check['name']].append({'timestamp': current_time, 'status': check['status']})
group_found['checks'][check['name']] = group_found['checks'][check['name']][-MAX_HISTORY_ENTRIES:]
save_history(history)


Expand Down Expand Up @@ -145,11 +150,13 @@ async def monitor_services():

update_history(results)

history = load_history()

html = template.render(groups=results, incidents=incidents, last_updated=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
with open(os.path.join(HTML_OUTPUT_DIRECTORY, 'index.html'), 'w') as f:
f.write(html)

history_html = history_template.render(history=load_history(), last_updated=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
history_html = history_template.render(history=history, last_updated=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
with open(os.path.join(HTML_OUTPUT_DIRECTORY, 'history.html'), 'w') as f:
f.write(history_html)

Expand Down