Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/cli.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
# WARNING: do not import unnecessary things here to keep cli startup time under | # WARNING: do not import unnecessary things here to keep cli startup time under | ||||
# control | # control | ||||
import sys | import sys | ||||
import click | import click | ||||
from swh.core.cli import CONTEXT_SETTINGS | from swh.core.cli import CONTEXT_SETTINGS | ||||
from swh.core.cli import swh as swh_cli_group | from swh.core.cli import swh as swh_cli_group | ||||
@swh_cli_group.group(name="icinga_plugins", context_settings=CONTEXT_SETTINGS) | @swh_cli_group.group(name="icinga_plugins", context_settings=CONTEXT_SETTINGS) | ||||
@click.option("-w", "--warning", type=int, help="Warning threshold.") | @click.option("-w", "--warning", type=int, help="Warning threshold.") | ||||
@click.option("-c", "--critical", type=int, help="Critical threshold.") | @click.option("-c", "--critical", type=int, help="Critical threshold.") | ||||
@click.option("--prometheus-exporter/--no-prometheus-exporter", default=False) | |||||
@click.option( | |||||
"--prometheus-exporter-directory", | |||||
type=str, | |||||
default="/var/lib/prometheus/node-exporter", | |||||
) | |||||
@click.option("--environment", type=str, help="The tested environment") | |||||
@click.pass_context | @click.pass_context | ||||
def icinga_cli_group(ctx, warning, critical): | def icinga_cli_group( | ||||
ctx, | |||||
warning, | |||||
critical, | |||||
prometheus_exporter: bool, | |||||
prometheus_exporter_directory: str, | |||||
environment: str, | |||||
): | |||||
"""Main command for Icinga plugins | """Main command for Icinga plugins | ||||
""" | """ | ||||
ctx.ensure_object(dict) | ctx.ensure_object(dict) | ||||
if warning: | if warning: | ||||
ctx.obj["warning_threshold"] = int(warning) | ctx.obj["warning_threshold"] = int(warning) | ||||
if critical: | if critical: | ||||
ctx.obj["critical_threshold"] = int(critical) | ctx.obj["critical_threshold"] = int(critical) | ||||
ctx.obj["prometheus_enabled"] = prometheus_exporter | |||||
ctx.obj["prometheus_exporter_directory"] = prometheus_exporter_directory | |||||
ctx.obj["environment"] = environment | |||||
@icinga_cli_group.group(name="check-vault") | @icinga_cli_group.group(name="check-vault") | ||||
@click.option( | @click.option( | ||||
"--swh-storage-url", type=str, required=True, help="URL to an swh-storage HTTP API" | "--swh-storage-url", type=str, required=True, help="URL to an swh-storage HTTP API" | ||||
) | ) | ||||
@click.option( | @click.option( | ||||
"--swh-web-url", type=str, required=True, help="URL to an swh-web instance" | "--swh-web-url", type=str, required=True, help="URL to an swh-web instance" | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |