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