mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 09:52:38 +02:00
Add the number of agents in the index template
This commit is contained in:
parent
5bca4fa261
commit
b105004f3b
5 changed files with 62 additions and 10 deletions
|
@ -19,7 +19,6 @@ 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.
|
||||
- [ ] Last seen agents
|
||||
- [ ] donner un aperçu rapide de l’état de la supervision.
|
||||
- [ ] Allow passing a dict to check
|
||||
- [ ] Rename error in unexpected error
|
||||
|
|
|
@ -52,13 +52,18 @@ def parse_checks(value):
|
|||
|
||||
available_names = get_registered_checks().keys()
|
||||
|
||||
for name, expected in value.items():
|
||||
if name not in available_names:
|
||||
msg = f"Check should be one of f{available_names}. ({name} given)"
|
||||
raise ValueError(msg)
|
||||
if isinstance(expected, int):
|
||||
expected = str(expected)
|
||||
return (name, expected)
|
||||
try:
|
||||
for name, expected in value.items():
|
||||
if name not in available_names:
|
||||
msg = f"Check should be one of f{available_names}. ({name} given)"
|
||||
raise ValueError(msg)
|
||||
if isinstance(expected, int):
|
||||
expected = str(expected)
|
||||
return (name, expected)
|
||||
except:
|
||||
from ipdb import set_trace
|
||||
|
||||
set_trace() # noqa
|
||||
|
||||
|
||||
class WebsitePath(BaseModel):
|
||||
|
|
|
@ -4,7 +4,7 @@ from urllib.parse import urlparse
|
|||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.orm import Session, aliased
|
||||
|
||||
from argos.schemas import Config
|
||||
from argos.server.models import Result, Task
|
||||
|
@ -43,6 +43,8 @@ async def read_tasks(request: Request, db: Session = Depends(get_db)):
|
|||
last_checks = {key: max(value) for key, value in domains_last_checks.items()}
|
||||
domains.sort(key=lambda x: x[1])
|
||||
|
||||
agents = db.query(Result.agent_id).distinct().all()
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"index.html",
|
||||
{
|
||||
|
@ -50,6 +52,7 @@ async def read_tasks(request: Request, db: Session = Depends(get_db)):
|
|||
"domains": domains,
|
||||
"last_checks": last_checks,
|
||||
"total_task_count": len(tasks),
|
||||
"agents": agents,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -96,3 +99,22 @@ async def get_task_results(
|
|||
"description": description,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@route.get("/agents")
|
||||
async def get_agents(request: Request, db: Session = Depends(get_db)):
|
||||
t1 = aliased(Result, name="t1")
|
||||
t2 = aliased(Result, name="t2")
|
||||
|
||||
last_seen = (
|
||||
db.query(t1)
|
||||
.outerjoin(
|
||||
t2, (t1.agent_id == t2.agent_id) & (t1.submitted_at < t2.submitted_at)
|
||||
)
|
||||
.filter(t2.agent_id.is_(None))
|
||||
.all()
|
||||
)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"agents.html", {"request": request, "last_seen": last_seen}
|
||||
)
|
||||
|
|
21
argos/server/templates/agents.html
Normal file
21
argos/server/templates/agents.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}<h2>Agents</h2>{% endblock %}
|
||||
{% block content %}
|
||||
<table role="grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Agent</th>
|
||||
<th>Last seen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
{% for result in last_seen %}
|
||||
<tr>
|
||||
<td>{{ result.agent_id }}</td>
|
||||
<td>{{ result.submitted_at }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
|
@ -1,7 +1,12 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div id="domains" class="frame">
|
||||
<p>{{domains | length}} domains, {{ total_task_count }} tasks</p>
|
||||
<p>
|
||||
{{domains | length}} domains,
|
||||
{{ total_task_count }} tasks,
|
||||
<a href="/agents">{{ agents |length }} agent{% if agents|length > 1 %}s{% endif %}</a>
|
||||
|
||||
</p>
|
||||
|
||||
<table id="domains-list" role="grid">
|
||||
<thead>
|
||||
|
|
Loading…
Reference in a new issue