diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de5e69..1ee74b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - 🩹 — Fix release documentation - ✅ — Add mypy test +- ✨ — Add new check type: status-in ## 0.2.2 diff --git a/argos/agent.py b/argos/agent.py index 2f8dcc2..e0a4608 100644 --- a/argos/agent.py +++ b/argos/agent.py @@ -54,7 +54,7 @@ class ArgosAgent: while "forever": retry_now = await self._get_and_complete_tasks() if not retry_now: - logger.error("Waiting %i seconds before next retry", self.wait_time) + logger.info("Waiting %i seconds before next retry", self.wait_time) await asyncio.sleep(self.wait_time) async def _complete_task(self, _task: dict) -> AgentResult: @@ -94,7 +94,7 @@ class ArgosAgent: await self._post_results(results) return True - logger.error("Got no tasks from the server.") + logger.info("Got no tasks from the server.") return False logger.error("Failed to fetch tasks: %s", response.read()) @@ -110,7 +110,7 @@ class ArgosAgent: ) if response.status_code == httpx.codes.CREATED: - logger.error( + logger.info( "Successfully posted results %s", json.dumps(response.json()) ) else: diff --git a/argos/checks/checks.py b/argos/checks/checks.py index 42a6848..a1e9c69 100644 --- a/argos/checks/checks.py +++ b/argos/checks/checks.py @@ -1,5 +1,6 @@ """Define the available checks""" +import json from datetime import datetime from argos.checks.base import ( @@ -31,6 +32,26 @@ class HTTPStatus(BaseCheck): ) +class HTTPStatusIn(BaseCheck): + """Checks that the HTTP status code is in the list of expected values.""" + + config = "status-in" + expected_cls = ExpectedStringValue + + async def run(self) -> dict: + # XXX Get the method from the task + task = self.task + response = await self.http_client.request( + method="get", url=task.url, timeout=60 + ) + + return self.response( + status=response.status_code in json.loads(self.expected), + expected=self.expected, + retrieved=response.status_code, + ) + + class HTTPBodyContains(BaseCheck): """Checks that the HTTP body contains the expected string.""" diff --git a/argos/config-example.yaml b/argos/config-example.yaml index 41f00d6..00a9eac 100644 --- a/argos/config-example.yaml +++ b/argos/config-example.yaml @@ -71,12 +71,19 @@ websites: paths: - path: "/mypads/" checks: + # Check that the returned HTTP status is 200 - status-is: 200 + # Check that the response contains this string - body-contains: '
' + # Check that the SSL certificate is no older than ssl.thresholds - ssl-certificate-expiration: "on-check" - path: "/admin/" checks: - - status-is: 401 + # Check that the return HTTP status is one of those + # Similar to status-is, verify that you don’t mistyped it! + - status-in: + - 401 + - 301 - domain: "https://munin.example.org" frequency: "20m" paths: diff --git a/argos/schemas/config.py b/argos/schemas/config.py index be90f7b..7022740 100644 --- a/argos/schemas/config.py +++ b/argos/schemas/config.py @@ -2,6 +2,9 @@ For database models, see argos.server.models. """ + +import json + from typing import Dict, List, Literal, Optional, Tuple from pydantic import ( @@ -78,6 +81,8 @@ def parse_checks(value): raise ValueError(msg) if isinstance(expected, int): expected = str(expected) + if isinstance(expected, list): + expected = json.dumps(expected) return (name, expected) diff --git a/docs/checks.md b/docs/checks.md index fcc4d2c..d3cb02d 100644 --- a/docs/checks.md +++ b/docs/checks.md @@ -9,6 +9,7 @@ These checks are the most basic ones. They simply check that the response from t | Check | Description | Configuration | | --- | --- | --- | | `status-is` | Check that the returned status code matches what you expect. | `status-is: "200"` | +| `status-in` | Check that the returned status code is in the list of codes you expect. |status-in:
- 200
- 302
|
| `body-contains` | Check that the returned body contains a given string. | `body-contains: "Hello world"` |
```{code-block} yaml
@@ -21,6 +22,11 @@ caption: argos-config.yaml
checks:
- status-is: 200
- body-contains: "Hello world"
+ - path: "/foobar"
+ checks:
+ - status-in:
+ - 200
+ - 302
```
## SSL certificate expiration
diff --git a/docs/configuration.md b/docs/configuration.md
index 576c55c..50a342e 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -2,6 +2,8 @@
Argos uses a simple YAML configuration file to define the server’s configuration, the websites to monitor and the checks to run on these websites.
+See [here](checks.md) for more informations about the checks you can use.
+
Here is a simple self-documented configuration file, which you can get with [`argos server generate-config`](cli.md#server-generate-config):
```{literalinclude} ../conf/config-example.yaml