From 85735add0151aa52bcd83bbb11c5f11ee55d066e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Thu, 19 Oct 2023 18:10:41 +0200 Subject: [PATCH] Updates while reading the code with Luc. --- README.md | 12 ++++++++++-- argos/checks/base.py | 2 +- argos/checks/checks.py | 2 +- argos/commands.py | 5 +++-- argos/server/models.py | 3 ++- argos/server/routes/api.py | 3 +-- argos/server/static/images/error.svg | 1 - argos/server/static/images/success.svg | 1 - argos/server/static/styles.css | 4 +--- 9 files changed, 19 insertions(+), 14 deletions(-) delete mode 100644 argos/server/static/images/error.svg delete mode 100644 argos/server/static/images/success.svg diff --git a/README.md b/README.md index ed5229e..eea33f2 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,20 @@ Argos is an HTTP monitoring service. It allows you to define a list of websites Todo: +- [ ] Retrying: attempt 1413 ended with: Cannot reopen a client instance, once it has been closed. +- [ ] Cleandb should keep max number of results by task +- [ ] 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. +- [ ] Rename error in unexpected error - [ ] Use background tasks for alerting -- [ ] Add a command to generate new authentication tokens +- [ ] Delete outdated tasks from config +- [ ] Implement alerting tasks - [ ] Handles multiple alerting backends (email, sms, gotify) +- [ ] 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 -- [ ] Do not send "expected" and "got" values in case check-status and body-contains suceeded +- [ ] Add a command to generate new authentication token Features : diff --git a/argos/checks/base.py b/argos/checks/base.py index 97d96da..6676ec6 100644 --- a/argos/checks/base.py +++ b/argos/checks/base.py @@ -30,7 +30,7 @@ class Response: @classmethod def new(cls, status, **kwargs): - if type(status) == bool: + if isinstance(status, bool): status = Status.SUCCESS if status else Status.FAILURE return cls(status=status, context=kwargs) diff --git a/argos/checks/checks.py b/argos/checks/checks.py index 39ce03a..e6b3d55 100644 --- a/argos/checks/checks.py +++ b/argos/checks/checks.py @@ -46,7 +46,7 @@ class SSLCertificateExpiration(BaseCheck): async def run(self): """Returns the number of days in which the certificate will expire.""" - response = await self.http_client.get(self.task.url) + response = await self.http_client.head(self.task.url) if response.is_error: raise diff --git a/argos/commands.py b/argos/commands.py index 7f8c25e..a3acf3a 100644 --- a/argos/commands.py +++ b/argos/commands.py @@ -5,8 +5,6 @@ import click from argos import logging from argos.agent import ArgosAgent -from argos.server import queries -from argos.server.main import connect_to_db, get_application, setup_database @click.group() @@ -78,6 +76,9 @@ def clean(max_results, max_lock_seconds): - Removes old results from the database. - Removes locks from tasks that have been locked for too long. """ + # The imports are made here otherwise the agent will need server configuration files. + from argos.server import queries + from argos.server.main import connect_to_db, get_application, setup_database async def clean_old_results(): app = get_application() diff --git a/argos/server/models.py b/argos/server/models.py index 61f5cea..a894ab6 100644 --- a/argos/server/models.py +++ b/argos/server/models.py @@ -6,7 +6,7 @@ from sqlalchemy import ( Enum, ForeignKey, ) -from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column, relationship +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship from argos.checks import BaseCheck, get_registered_check from argos.schemas import WebsiteCheck @@ -83,6 +83,7 @@ class Result(Base): agent_id: Mapped[str] = mapped_column(nullable=True) submitted_at: Mapped[datetime] = mapped_column() + # XXX change "on-check" to something better. status: Mapped[Literal["success", "failure", "error", "on-check"]] = mapped_column( Enum("success", "failure", "error", "on-check", name="status") ) diff --git a/argos/server/routes/api.py b/argos/server/routes/api.py index b1e5a36..e0408a0 100644 --- a/argos/server/routes/api.py +++ b/argos/server/routes/api.py @@ -12,12 +12,11 @@ from argos.server.routes.dependencies import get_config, get_db, verify_token route = APIRouter() -# XXX Get the default limit from the config @route.get("/tasks", response_model=list[Task], dependencies=[Depends(verify_token)]) async def read_tasks( request: Request, db: Session = Depends(get_db), - limit: int = 20, + limit: int = 10, agent_id: str = None, ): agent_id = agent_id or request.client.host diff --git a/argos/server/static/images/error.svg b/argos/server/static/images/error.svg deleted file mode 100644 index 78b526a..0000000 --- a/argos/server/static/images/error.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/argos/server/static/images/success.svg b/argos/server/static/images/success.svg deleted file mode 100644 index 856c2a5..0000000 --- a/argos/server/static/images/success.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/argos/server/static/styles.css b/argos/server/static/styles.css index e1333c1..5ca62cb 100644 --- a/argos/server/static/styles.css +++ b/argos/server/static/styles.css @@ -2,6 +2,4 @@ code { white-space: pre-wrap; - -} - \ No newline at end of file +} \ No newline at end of file