From d2a12aea30e802d34cb5c16a1cd691e32d73f095 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 21 Nov 2023 15:42:32 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=84=20=E2=80=94=20Quick=20supervis?= =?UTF-8?q?ion=20overview=20on=20homepage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +-- argos/server/routes/views.py | 22 ++++++++++++- argos/server/static/styles.css | 14 ++++++++- argos/server/templates/details.html | 35 +++++++++++++++++++++ argos/server/templates/index.html | 49 +++++++++++++---------------- 5 files changed, 92 insertions(+), 32 deletions(-) create mode 100644 argos/server/templates/details.html diff --git a/README.md b/README.md index 2df9b98..23b8dca 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Internally, a HTTP API is exposed, and a job queue is used to distribute the che ## Todo: - [ ] Do not return empty list on / when no results from agents. -- [ ] donner un aperçu rapide de l’état de la supervision. +- [X] donner un aperçu rapide de l’état de la supervision. - [ ] Allow passing a dict to check - [ ] Rename error in unexpected error - [ ] Use background tasks for alerting @@ -29,4 +29,4 @@ Internally, a HTTP API is exposed, and a job queue is used to distribute the che - [ ] Un flag de configuration permet d’ajouter automatiquement un job de vérification de redirection 301 de la version HTTP vers HTTPS - [ ] add an "unknown" severity for check errors - [ ] Add a way to specify the severity of the alerts in the config -- [ ] Add a command to generate new authentication token \ No newline at end of file +- [ ] Add a command to generate new authentication token diff --git a/argos/server/routes/views.py b/argos/server/routes/views.py index cc1cc5e..6880d16 100644 --- a/argos/server/routes/views.py +++ b/argos/server/routes/views.py @@ -7,6 +7,7 @@ from sqlalchemy import desc from sqlalchemy.orm import Session, aliased from argos.schemas import Config +from argos.server import queries from argos.server.models import Result, Task from argos.server.routes.dependencies import get_config, get_db @@ -16,6 +17,25 @@ templates = Jinja2Templates(directory="argos/server/templates") @route.get("/") +async def get_severity_counts(request: Request, db: Session = Depends(get_db)): + """Returns the number of results per severity""" + counts = await queries.get_severity_counts(db) + counts_dict = dict(counts) + for key in ("ok", "warning", "critical"): + counts_dict.setdefault(key, 0) + + agents = db.query(Result.agent_id).distinct().all() + + return templates.TemplateResponse( + "index.html", + { + "request": request, + "counts_dict": counts_dict, + "agents": agents, + }, + ) + +@route.get("/details") async def read_tasks(request: Request, db: Session = Depends(get_db)): tasks = db.query(Task).order_by(Task.domain).all() @@ -46,7 +66,7 @@ async def read_tasks(request: Request, db: Session = Depends(get_db)): agents = db.query(Result.agent_id).distinct().all() return templates.TemplateResponse( - "index.html", + "details.html", { "request": request, "domains": domains, diff --git a/argos/server/static/styles.css b/argos/server/static/styles.css index 5ca62cb..f1d80a8 100644 --- a/argos/server/static/styles.css +++ b/argos/server/static/styles.css @@ -2,4 +2,16 @@ code { white-space: pre-wrap; -} \ No newline at end of file +} + +.grid-index { + font-size: 2rem; +} +.text-center, +.grid-index { + text-align: center; +} +.grid-index article { + margin-top: 0; + margin-bottom: 1rem; +} diff --git a/argos/server/templates/details.html b/argos/server/templates/details.html new file mode 100644 index 0000000..64a2d36 --- /dev/null +++ b/argos/server/templates/details.html @@ -0,0 +1,35 @@ +{% extends "base.html" %} +{% block content %} +
+

+ {{domains | length}} domains, + {{ total_task_count }} tasks, + {{ agents |length }} agent{% if agents|length > 1 %}s{% endif %} + +

+ + + + + + + + + + + {% for (domain, status) in domains %} + + + + + + + {% endfor %} + + +
DomainCurrent statusLast check
+ + {{ domain }} + {% if status == "ok" %}✅ OK {% elif statuts == "warning"%}⚠ Warning{% elif status == "critical"%}❌ Critical{% elif status == "to-process" %}⏱︎ Waiting for the jobs{% endif %}{{ last_checks.get(domain) }}
+
+{% endblock %} \ No newline at end of file diff --git a/argos/server/templates/index.html b/argos/server/templates/index.html index 64a2d36..9d347ef 100644 --- a/argos/server/templates/index.html +++ b/argos/server/templates/index.html @@ -2,34 +2,27 @@ {% block content %}

- {{domains | length}} domains, - {{ total_task_count }} tasks, - {{ agents |length }} agent{% if agents|length > 1 %}s{% endif %} + {{ agents | length }} agent{% if agents| length > 1 %}s{% endif %} +

+
+
+
+
✅ OK
+ {{ counts_dict['ok'] }} +
+
+
⚠️ Warning
+ {{ counts_dict['warning'] }} +
+
+
❌ Critical
+ {{ counts_dict['critical'] }} +
+
+

+ Details

- - - - - - - - - - - {% for (domain, status) in domains %} - - - - - - - {% endfor %} - - -
DomainCurrent statusLast check
- - {{ domain }} - {% if status == "ok" %}✅ OK {% elif statuts == "warning"%}⚠ Warning{% elif status == "critical"%}❌ Critical{% elif status == "to-process" %}⏱︎ Waiting for the jobs{% endif %}{{ last_checks.get(domain) }}
+
-{% endblock %} \ No newline at end of file +{% endblock %} From 1f33110e689accafdc4b9baadab2e2c64879c517 Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Tue, 21 Nov 2023 15:52:06 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=9A=A8=20=E2=80=94=20HTML=20linting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- argos/server/templates/agents.html | 15 ++++++----- argos/server/templates/base.html | 39 ++++++++++++++++------------- argos/server/templates/details.html | 28 ++++++++++----------- argos/server/templates/domain.html | 11 ++++---- argos/server/templates/result.html | 15 ++++++----- 5 files changed, 54 insertions(+), 54 deletions(-) diff --git a/argos/server/templates/agents.html b/argos/server/templates/agents.html index 9cd6b1a..aa5d58f 100644 --- a/argos/server/templates/agents.html +++ b/argos/server/templates/agents.html @@ -9,13 +9,12 @@ - - {% for result in last_seen %} - - {{ result.agent_id }} - {{ result.submitted_at }} - - {% endfor %} + {% for result in last_seen %} + + {{ result.agent_id }} + {{ result.submitted_at }} + + {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/argos/server/templates/base.html b/argos/server/templates/base.html index 14e48be..d8dc26b 100644 --- a/argos/server/templates/base.html +++ b/argos/server/templates/base.html @@ -1,20 +1,23 @@ - - - Argos - - - -
- - -
- {% block content %} - {% endblock %} -
-
- - \ No newline at end of file + + + Argos + + + + + +
+ +
+ {% block content %} + {% endblock %} +
+
+ + diff --git a/argos/server/templates/details.html b/argos/server/templates/details.html index 64a2d36..7994606 100644 --- a/argos/server/templates/details.html +++ b/argos/server/templates/details.html @@ -2,34 +2,32 @@ {% block content %}

- {{domains | length}} domains, + {{ domains | length}} domains, {{ total_task_count }} tasks, - {{ agents |length }} agent{% if agents|length > 1 %}s{% endif %} - -

- + {{ agents | length }} agent{% if agents | length > 1 %}s{% endif %} +

- - - + + + + {% for (domain, status) in domains %} + - - {% endfor %} - -
DomainCurrent statusLast checkDomainCurrent statusLast check
- - {{ domain }} + {{ domain }} + + {% if status == "ok" %}✅ OK {% elif statuts == "warning"%}⚠ Warning{% elif status == "critical"%}❌ Critical{% elif status == "to-process" %}⏱︎ Waiting for the jobs{% endif %} {% if status == "ok" %}✅ OK {% elif statuts == "warning"%}⚠ Warning{% elif status == "critical"%}❌ Critical{% elif status == "to-process" %}⏱︎ Waiting for the jobs{% endif %} {{ last_checks.get(domain) }}
+
-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/argos/server/templates/domain.html b/argos/server/templates/domain.html index 5d1d4b0..36b669d 100644 --- a/argos/server/templates/domain.html +++ b/argos/server/templates/domain.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block title %}

{{domain}}

{% endblock %} +{% block title %}

{{ domain }}

{% endblock %} {% block content %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/argos/server/templates/result.html b/argos/server/templates/result.html index a6b3eb6..3154eaa 100644 --- a/argos/server/templates/result.html +++ b/argos/server/templates/result.html @@ -1,17 +1,16 @@ {% extends "base.html" %} -{% block title %}

{{result}}

{% endblock %} +{% block title %}

{{ result }}

{% endblock %} {% block content %}
Task
-
{{result.task}}
+
{{ result.task }}
Submitted at
-
{{result.submitted_at}}
+
{{ result.submitted_at }}
Status
-
{{result.status}}
+
{{ result.status }}
Severity
-
{{result.severity}}
+
{{ result.severity }}
Context
-
{{result.context}}
+
{{ result.context }}
- -{% endblock %} \ No newline at end of file +{% endblock %} From 27857c182ab97055b01cb2385b6d6df1fc55d99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Wed, 22 Nov 2023 13:23:44 +0100 Subject: [PATCH 3/3] Make queries.get_severity_counts() return a dict --- argos/server/queries.py | 6 +++++- argos/server/routes/api.py | 6 +----- argos/server/routes/views.py | 6 ++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/argos/server/queries.py b/argos/server/queries.py index b6cc453..eb42b4f 100644 --- a/argos/server/queries.py +++ b/argos/server/queries.py @@ -105,7 +105,7 @@ async def update_from_config(db: Session, config: schemas.Config): db.commit() -async def get_severity_counts(db: Session): +async def get_severity_counts(db: Session) -> dict: # Get the last result of each task subquery = ( db.query(Result.task_id, func.max(Result.id).label("max_result_id")) @@ -122,6 +122,10 @@ async def get_severity_counts(db: Session): # Execute the query and fetch the results task_counts_by_severity = query.all() + + counts_dict = dict(task_counts_by_severity) + for key in ("ok", "warning", "critical"): + counts_dict.setdefault(key, 0) return task_counts_by_severity diff --git a/argos/server/routes/api.py b/argos/server/routes/api.py index 1410c00..18e7b9b 100644 --- a/argos/server/routes/api.py +++ b/argos/server/routes/api.py @@ -73,8 +73,4 @@ async def get_stats(db: Session = Depends(get_db)): @route.get("/severities") async def get_severity_counts(db: Session = Depends(get_db)): """Returns the number of results per severity""" - counts = await queries.get_severity_counts(db) - counts_dict = dict(counts) - for key in ("ok", "warning", "critical"): - counts_dict.setdefault(key, 0) - return counts_dict + return await queries.get_severity_counts(db) diff --git a/argos/server/routes/views.py b/argos/server/routes/views.py index 6880d16..174f0c6 100644 --- a/argos/server/routes/views.py +++ b/argos/server/routes/views.py @@ -19,10 +19,7 @@ templates = Jinja2Templates(directory="argos/server/templates") @route.get("/") async def get_severity_counts(request: Request, db: Session = Depends(get_db)): """Returns the number of results per severity""" - counts = await queries.get_severity_counts(db) - counts_dict = dict(counts) - for key in ("ok", "warning", "critical"): - counts_dict.setdefault(key, 0) + counts_dict = await queries.get_severity_counts(db) agents = db.query(Result.agent_id).distinct().all() @@ -35,6 +32,7 @@ async def get_severity_counts(request: Request, db: Session = Depends(get_db)): }, ) + @route.get("/details") async def read_tasks(request: Request, db: Session = Depends(get_db)): tasks = db.query(Task).order_by(Task.domain).all()