mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
✨ — Add nagios command to use as a Nagios probe
This commit is contained in:
parent
8072a485a1
commit
3917eb2498
3 changed files with 81 additions and 2 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
- 💄 — Improve email and gotify notifications
|
||||
- ✨ — Add command to test gotify configuration
|
||||
- ✨ — Add nagios command to use as a Nagios probe
|
||||
|
||||
## 0.3.1
|
||||
|
||||
|
|
|
@ -678,5 +678,58 @@ async def test_gotify(config, domain, severity):
|
|||
)
|
||||
|
||||
|
||||
@server.command(short_help="Nagios compatible severities report")
|
||||
@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,
|
||||
)
|
||||
@coroutine
|
||||
async def nagios(config):
|
||||
"""Output a report of current severities suitable for Nagios
|
||||
with a Nagios compatible exit code"""
|
||||
os.environ["ARGOS_YAML_FILE"] = config
|
||||
|
||||
# The imports are made here otherwise the agent will need server configuration files.
|
||||
from argos.server import queries
|
||||
|
||||
exit_nb = 0
|
||||
db = await get_db()
|
||||
severities = await queries.get_severity_counts(db)
|
||||
|
||||
if severities["warning"] != 0:
|
||||
exit_nb = 1
|
||||
if severities["critical"] != 0:
|
||||
exit_nb = 2
|
||||
if severities["unknown"] != 0:
|
||||
exit_nb = 2
|
||||
|
||||
stats = (
|
||||
f"ok={severities['ok']}; warning={severities['warning']}; "
|
||||
f"critical={severities['critical']}; unknown={severities['unknown']};"
|
||||
)
|
||||
|
||||
if exit_nb == 0:
|
||||
print("OK — All sites are ok|{stats}")
|
||||
elif exit_nb == 1:
|
||||
print(f"WARNING — {severities['warning']} sites are in warning state|{stats}")
|
||||
elif severities["critical"] == 0:
|
||||
print(f"UNKNOWN — {severities['unknown']} sites are in unknown state|{stats}")
|
||||
elif severities["unknown"] == 0:
|
||||
print(
|
||||
f"CRITICAL — {severities['critical']} sites are in critical state|{stats}"
|
||||
)
|
||||
else:
|
||||
print(
|
||||
f"CRITICAL/UNKNOWN — {severities['critical']} sites are in critical state "
|
||||
f"and {severities['unknown']} sites are in unknown state|{stats}"
|
||||
)
|
||||
|
||||
sysexit(exit_nb)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
|
|
29
docs/cli.md
29
docs/cli.md
|
@ -83,6 +83,7 @@ Commands:
|
|||
generate-config Output a self-documented example config file.
|
||||
generate-token Generate a token for agents
|
||||
migrate Run database migrations
|
||||
nagios Nagios compatible severities report
|
||||
reload-config Load or reload tasks’ configuration
|
||||
start Starts the server (use only for testing or development!)
|
||||
test-gotify Send a test gotify notification
|
||||
|
@ -468,9 +469,33 @@ Options:
|
|||
<!--[[[end]]]
|
||||
-->
|
||||
|
||||
#### Use as a nagios probe
|
||||
|
||||
You can directly use Argos to get an output and an exit code usable with Nagios.
|
||||
|
||||
<!--
|
||||
.. [[[cog
|
||||
help(["server", "nagios", "--help"])
|
||||
.. ]]] -->
|
||||
|
||||
```man
|
||||
Usage: argos server nagios [OPTIONS]
|
||||
|
||||
Output a report of current severities suitable for Nagios with a Nagios
|
||||
compatible exit code
|
||||
|
||||
Options:
|
||||
--config TEXT Path of the configuration file. If ARGOS_YAML_FILE environment
|
||||
variable is set, its value will be used instead.
|
||||
--help Show this message and exit.
|
||||
```
|
||||
|
||||
<!--[[[end]]]
|
||||
-->
|
||||
|
||||
#### Test the email settings
|
||||
|
||||
You can verify that your mail settings are ok by sending a test email
|
||||
You can verify that your mail settings are ok by sending a test email.
|
||||
|
||||
<!--
|
||||
.. [[[cog
|
||||
|
@ -495,7 +520,7 @@ Options:
|
|||
|
||||
#### Test the Gotify settings
|
||||
|
||||
You can verify that your Gotify settings are ok by sending a test notification
|
||||
You can verify that your Gotify settings are ok by sending a test notification.
|
||||
|
||||
<!--
|
||||
.. [[[cog
|
||||
|
|
Loading…
Reference in a new issue