mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +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:
|
## Todo:
|
||||||
|
|
||||||
- [ ] Do not return empty list on / when no results from agents.
|
- [ ] 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.
|
- [ ] donner un aperçu rapide de l’état de la supervision.
|
||||||
- [ ] Allow passing a dict to check
|
- [ ] Allow passing a dict to check
|
||||||
- [ ] Rename error in unexpected error
|
- [ ] Rename error in unexpected error
|
||||||
|
|
|
@ -52,6 +52,7 @@ def parse_checks(value):
|
||||||
|
|
||||||
available_names = get_registered_checks().keys()
|
available_names = get_registered_checks().keys()
|
||||||
|
|
||||||
|
try:
|
||||||
for name, expected in value.items():
|
for name, expected in value.items():
|
||||||
if name not in available_names:
|
if name not in available_names:
|
||||||
msg = f"Check should be one of f{available_names}. ({name} given)"
|
msg = f"Check should be one of f{available_names}. ({name} given)"
|
||||||
|
@ -59,6 +60,10 @@ def parse_checks(value):
|
||||||
if isinstance(expected, int):
|
if isinstance(expected, int):
|
||||||
expected = str(expected)
|
expected = str(expected)
|
||||||
return (name, expected)
|
return (name, expected)
|
||||||
|
except:
|
||||||
|
from ipdb import set_trace
|
||||||
|
|
||||||
|
set_trace() # noqa
|
||||||
|
|
||||||
|
|
||||||
class WebsitePath(BaseModel):
|
class WebsitePath(BaseModel):
|
||||||
|
|
|
@ -4,7 +4,7 @@ from urllib.parse import urlparse
|
||||||
from fastapi import APIRouter, Depends, Request
|
from fastapi import APIRouter, Depends, Request
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session, aliased
|
||||||
|
|
||||||
from argos.schemas import Config
|
from argos.schemas import Config
|
||||||
from argos.server.models import Result, Task
|
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()}
|
last_checks = {key: max(value) for key, value in domains_last_checks.items()}
|
||||||
domains.sort(key=lambda x: x[1])
|
domains.sort(key=lambda x: x[1])
|
||||||
|
|
||||||
|
agents = db.query(Result.agent_id).distinct().all()
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"index.html",
|
"index.html",
|
||||||
{
|
{
|
||||||
|
@ -50,6 +52,7 @@ async def read_tasks(request: Request, db: Session = Depends(get_db)):
|
||||||
"domains": domains,
|
"domains": domains,
|
||||||
"last_checks": last_checks,
|
"last_checks": last_checks,
|
||||||
"total_task_count": len(tasks),
|
"total_task_count": len(tasks),
|
||||||
|
"agents": agents,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -96,3 +99,22 @@ async def get_task_results(
|
||||||
"description": description,
|
"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" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="domains" class="frame">
|
<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">
|
<table id="domains-list" role="grid">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
Loading…
Reference in a new issue