mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
✨ — Add command to test gotify configuration
This commit is contained in:
parent
255fa77ac3
commit
8072a485a1
3 changed files with 92 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
- 💄 — Improve email and gotify notifications
|
- 💄 — Improve email and gotify notifications
|
||||||
|
- ✨ — Add command to test gotify configuration
|
||||||
|
|
||||||
## 0.3.1
|
## 0.3.1
|
||||||
|
|
||||||
|
|
|
@ -607,12 +607,76 @@ async def test_mail(config, domain, severity):
|
||||||
notify_by_mail(
|
notify_by_mail(
|
||||||
result,
|
result,
|
||||||
task,
|
task,
|
||||||
severity="SEVERITY",
|
severity=severity,
|
||||||
old_severity="OLD SEVERITY",
|
old_severity="OLD SEVERITY",
|
||||||
config=conf.general.mail,
|
config=conf.general.mail,
|
||||||
request=_FalseRequest(),
|
request=_FalseRequest(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@server.command()
|
||||||
|
@click.option(
|
||||||
|
"--config",
|
||||||
|
default="argos-config.yaml",
|
||||||
|
help="Path of the configuration file. "
|
||||||
|
"If ARGOS_YAML_FILE environment variable is set, its value will be used instead.",
|
||||||
|
envvar="ARGOS_YAML_FILE",
|
||||||
|
callback=validate_config_access,
|
||||||
|
)
|
||||||
|
@click.option("--domain", help="Domain for the notification", default="example.org")
|
||||||
|
@click.option("--severity", help="Severity", default="CRITICAL")
|
||||||
|
@coroutine
|
||||||
|
async def test_gotify(config, domain, severity):
|
||||||
|
"""Send a test gotify notification"""
|
||||||
|
os.environ["ARGOS_YAML_FILE"] = config
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from argos.logging import set_log_level
|
||||||
|
from argos.server.alerting import notify_with_gotify
|
||||||
|
from argos.server.main import read_config
|
||||||
|
from argos.server.models import Result, Task
|
||||||
|
|
||||||
|
conf = read_config(config)
|
||||||
|
|
||||||
|
if not conf.general.gotify:
|
||||||
|
click.echo("Gotify notifications are not configured, cannot test", err=True)
|
||||||
|
sysexit(1)
|
||||||
|
else:
|
||||||
|
now = datetime.now()
|
||||||
|
task = Task(
|
||||||
|
url=f"https://{domain}",
|
||||||
|
domain=domain,
|
||||||
|
check="body-contains",
|
||||||
|
expected="foo",
|
||||||
|
frequency=1,
|
||||||
|
selected_by="test",
|
||||||
|
selected_at=now,
|
||||||
|
)
|
||||||
|
|
||||||
|
result = Result(
|
||||||
|
submitted_at=now,
|
||||||
|
status="success",
|
||||||
|
context={"foo": "bar"},
|
||||||
|
task=task,
|
||||||
|
agent_id="test",
|
||||||
|
severity="ok",
|
||||||
|
)
|
||||||
|
|
||||||
|
class _FalseRequest:
|
||||||
|
def url_for(*args, **kwargs):
|
||||||
|
return "/url"
|
||||||
|
|
||||||
|
set_log_level("debug")
|
||||||
|
notify_with_gotify(
|
||||||
|
result,
|
||||||
|
task,
|
||||||
|
severity=severity,
|
||||||
|
old_severity="OLD SEVERITY",
|
||||||
|
config=conf.general.gotify,
|
||||||
|
request=_FalseRequest(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cli()
|
cli()
|
||||||
|
|
26
docs/cli.md
26
docs/cli.md
|
@ -85,6 +85,7 @@ Commands:
|
||||||
migrate Run database migrations
|
migrate Run database migrations
|
||||||
reload-config Load or reload tasks’ configuration
|
reload-config Load or reload tasks’ configuration
|
||||||
start Starts the server (use only for testing or development!)
|
start Starts the server (use only for testing or development!)
|
||||||
|
test-gotify Send a test gotify notification
|
||||||
test-mail Send a test email
|
test-mail Send a test email
|
||||||
user User management
|
user User management
|
||||||
watch-agents Watch agents (to run routinely)
|
watch-agents Watch agents (to run routinely)
|
||||||
|
@ -491,3 +492,28 @@ Options:
|
||||||
|
|
||||||
<!--[[[end]]]
|
<!--[[[end]]]
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
#### Test the Gotify settings
|
||||||
|
|
||||||
|
You can verify that your Gotify settings are ok by sending a test notification
|
||||||
|
|
||||||
|
<!--
|
||||||
|
.. [[[cog
|
||||||
|
help(["server", "test-gotify", "--help"])
|
||||||
|
.. ]]] -->
|
||||||
|
|
||||||
|
```man
|
||||||
|
Usage: argos server test-gotify [OPTIONS]
|
||||||
|
|
||||||
|
Send a test gotify notification
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--config TEXT Path of the configuration file. If ARGOS_YAML_FILE
|
||||||
|
environment variable is set, its value will be used instead.
|
||||||
|
--domain TEXT Domain for the notification
|
||||||
|
--severity TEXT Severity
|
||||||
|
--help Show this message and exit.
|
||||||
|
```
|
||||||
|
|
||||||
|
<!--[[[end]]]
|
||||||
|
-->
|
||||||
|
|
Loading…
Reference in a new issue