mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-05-04 04:31:49 +02:00
Compare commits
3 commits
876ac3cf54
...
5b91c6a482
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5b91c6a482 | ||
![]() |
2e6c2e205f | ||
![]() |
4c378e94ac |
7 changed files with 54 additions and 8 deletions
|
@ -7,10 +7,13 @@
|
|||
- 🔊 — Improve check agent log
|
||||
- 🔒️ — Logging out now invalidate tokens
|
||||
- 📝 — Improve OpenAPI doc
|
||||
- 🤕 — Fix order of tasks sent to agent
|
||||
- 🩹 — Fix order of tasks sent to agent
|
||||
- ✨ — Add application API (fix #86)
|
||||
- ⚡️ — Faster websites configuration reloading (#85)
|
||||
- 💄 — Better mobile display
|
||||
- ✨ — Add waiting tasks count on index page and app API
|
||||
- ✨ — Allow to customize the name of the argos agent
|
||||
- 🩹 — Fix tasks_tmp table truncating
|
||||
|
||||
## 0.9.0
|
||||
|
||||
|
|
|
@ -38,7 +38,13 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
|||
"""The Argos agent is responsible for running the checks and reporting the results."""
|
||||
|
||||
def __init__( # pylint: disable-msg=too-many-positional-arguments
|
||||
self, server: str, auth: str, max_tasks: int, wait_time: int, user_agent: str
|
||||
self,
|
||||
server: str,
|
||||
auth: str,
|
||||
max_tasks: int,
|
||||
wait_time: int,
|
||||
user_agent: str,
|
||||
name: str,
|
||||
):
|
||||
self.server = server
|
||||
self.max_tasks = max_tasks
|
||||
|
@ -53,7 +59,10 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes
|
|||
self._http_client_v6: httpx.AsyncClient | None = None
|
||||
self._res_cache: dict[str, httpx.Response] = {}
|
||||
|
||||
self.agent_id = socket.gethostname()
|
||||
if name == "":
|
||||
self.agent_id = socket.gethostname()
|
||||
else:
|
||||
self.agent_id = name
|
||||
|
||||
@retry(after=log_failure, wait=wait_random(min=1, max=2))
|
||||
async def run(self):
|
||||
|
|
|
@ -92,12 +92,13 @@ def version():
|
|||
default="INFO",
|
||||
type=click.Choice(logging.LOG_LEVELS, case_sensitive=False),
|
||||
)
|
||||
@click.option("--name", default="", help="The name of the agent sent to the server")
|
||||
@click.option(
|
||||
"--user-agent",
|
||||
default="",
|
||||
help="A custom string to append to the User-Agent header",
|
||||
)
|
||||
def agent(server_url, auth, max_tasks, wait_time, log_level, user_agent): # pylint: disable-msg=too-many-positional-arguments
|
||||
def agent(server_url, auth, max_tasks, wait_time, log_level, user_agent, name): # pylint: disable-msg=too-many-positional-arguments
|
||||
"""Get and run tasks for the provided server. Will wait for new tasks.
|
||||
|
||||
Usage: argos agent https://argos.example.org "auth-token-here"
|
||||
|
@ -113,7 +114,14 @@ def agent(server_url, auth, max_tasks, wait_time, log_level, user_agent): # pyl
|
|||
from argos.logging import logger
|
||||
|
||||
logger.setLevel(log_level)
|
||||
agent_ = ArgosAgent(server_url, auth, max_tasks, wait_time, user_agent)
|
||||
agent_ = ArgosAgent(
|
||||
server=server_url,
|
||||
auth=auth,
|
||||
max_tasks=max_tasks,
|
||||
wait_time=wait_time,
|
||||
user_agent=user_agent,
|
||||
name=name,
|
||||
)
|
||||
asyncio.run(agent_.run())
|
||||
|
||||
|
||||
|
|
|
@ -568,9 +568,8 @@ async def update_from_config(db: Session, config: schemas.Config):
|
|||
db.commit()
|
||||
else:
|
||||
logger.debug("Truncating tasks_tmp table")
|
||||
db.execute(
|
||||
sa_text("TRUNCATE TABLE tasks_tmp;").execution_options(autocommit=True)
|
||||
)
|
||||
db.execute(sa_text("TRUNCATE TABLE tasks_tmp RESTART IDENTITY;"))
|
||||
db.commit()
|
||||
|
||||
return {
|
||||
"added": added_tasks,
|
||||
|
@ -594,6 +593,19 @@ async def get_severity_counts(db: Session) -> dict:
|
|||
return counts_dict
|
||||
|
||||
|
||||
async def get_waiting_tasks_count(db: Session) -> int:
|
||||
"""Get the count of tasks waiting to be processed"""
|
||||
waiting_tasks = (
|
||||
db.query(Task.id)
|
||||
.filter(
|
||||
Task.selected_by == None,
|
||||
((Task.next_run <= datetime.now()) | (Task.next_run == None)),
|
||||
)
|
||||
.count()
|
||||
)
|
||||
return waiting_tasks
|
||||
|
||||
|
||||
async def reschedule_all(db: Session):
|
||||
"""Reschedule checks of all non OK tasks ASAP"""
|
||||
db.query(Task).filter(Task.severity != "ok").update(
|
||||
|
|
|
@ -170,6 +170,7 @@ async def logout(
|
|||
class SeverityCounts(BaseModel):
|
||||
severities: Dict[Literal["ok", "warning", "critical", "unknown"], int]
|
||||
agents: int
|
||||
waiting_tasks: int
|
||||
|
||||
model_config = {
|
||||
"json_schema_extra": {
|
||||
|
@ -177,6 +178,7 @@ class SeverityCounts(BaseModel):
|
|||
{
|
||||
"severities": {"ok": 10, "warning": 0, "critical": 2, "unknown": 0},
|
||||
"agents": 1,
|
||||
"waiting_tasks": 3,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -194,9 +196,12 @@ async def get_severity_counts(
|
|||
|
||||
agents = db.query(Result.agent_id).distinct().all()
|
||||
|
||||
waiting_tasks = await queries.get_waiting_tasks_count(db)
|
||||
|
||||
return {
|
||||
"severities": counts_dict,
|
||||
"agents": len(agents),
|
||||
"waiting_tasks": waiting_tasks,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -158,12 +158,15 @@ async def get_severity_counts_view(
|
|||
|
||||
agents = db.query(Result.agent_id).distinct().all()
|
||||
|
||||
waiting_tasks = await queries.get_waiting_tasks_count(db)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"index.html",
|
||||
{
|
||||
"request": request,
|
||||
"counts_dict": counts_dict,
|
||||
"agents": agents,
|
||||
"waiting_tasks": waiting_tasks,
|
||||
"auto_refresh_enabled": auto_refresh_enabled,
|
||||
"auto_refresh_seconds": auto_refresh_seconds,
|
||||
"user": user,
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
{{ agents | length }} agent{{ 's' if agents | length > 1 }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ waiting_tasks }} task{{ 's' if waiting_tasks > 1 }} awaiting to be processed
|
||||
</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>
|
||||
|
@ -51,6 +54,9 @@
|
|||
{{ agents | length }} agent{{ 's' if agents | length > 1 }}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
{{ waiting_tasks }} task{{ 's' if waiting_tasks > 1 }} awaiting to be processed
|
||||
</li>
|
||||
</ul>
|
||||
<div>
|
||||
<ul>
|
||||
|
|
Loading…
Reference in a new issue