Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/cli.py
Show All 10 Lines | |||||
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" | ||||
) | ) | ||||
@click.option( | @click.option( | ||||
"--poll-interval", | "--poll-interval", | ||||
type=int, | type=int, | ||||
default=10, | default=10, | ||||
help="Interval (in seconds) between two polls to the API, " | help="Interval (in seconds) between two polls to the API, " | ||||
"to check for cooking status.", | "to check for cooking status.", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def check_vault(ctx, **kwargs): | def check_vault(ctx, **kwargs): | ||||
ctx.obj.update(kwargs) | ctx.obj.update(kwargs) | ||||
ctx.obj["application"] = "vault" | |||||
@check_vault.command(name="directory") | @check_vault.command(name="directory") | ||||
@click.pass_context | @click.pass_context | ||||
def check_vault_directory(ctx): | def check_vault_directory(ctx): | ||||
"""Picks a random directory, requests its cooking via swh-web, | """Picks a random directory, requests its cooking via swh-web, | ||||
and waits for completion.""" | and waits for completion.""" | ||||
from .vault import VaultCheck | from .vault import VaultCheck | ||||
Show All 10 Lines | @click.option( | ||||
type=int, | type=int, | ||||
default=10, | default=10, | ||||
help="Interval (in seconds) between two polls to the API, " | help="Interval (in seconds) between two polls to the API, " | ||||
"to check for save code now status.", | "to check for save code now status.", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def check_scn(ctx, **kwargs): | def check_scn(ctx, **kwargs): | ||||
ctx.obj.update(kwargs) | ctx.obj.update(kwargs) | ||||
ctx.obj["application"] = "scn" | |||||
@check_scn.command(name="origin") | @check_scn.command(name="origin") | ||||
@click.argument("origin", type=str) | @click.argument("origin", type=str) | ||||
@click.option("--visit-type", type=str, required=True, help="Visit type for origin") | @click.option("--visit-type", type=str, required=True, help="Visit type for origin") | ||||
@click.pass_context | @click.pass_context | ||||
def check_scn_origin(ctx, origin, visit_type): | def check_scn_origin(ctx, origin, visit_type): | ||||
"""Requests a save code now via the api for a given origin with type visit_type, waits | """Requests a save code now via the api for a given origin with type visit_type, waits | ||||
Show All 28 Lines | @click.option( | ||||
type=int, | type=int, | ||||
default=10, | default=10, | ||||
help="Interval (in seconds) between two polls to the API, " | help="Interval (in seconds) between two polls to the API, " | ||||
"to check for ingestion status.", | "to check for ingestion status.", | ||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def check_deposit(ctx, **kwargs): | def check_deposit(ctx, **kwargs): | ||||
ctx.obj.update(kwargs) | ctx.obj.update(kwargs) | ||||
ctx.obj["application"] = "deposit" | |||||
@check_deposit.command(name="single") | @check_deposit.command(name="single") | ||||
@click.option( | @click.option( | ||||
"--archive", type=click.Path(), required=True, help="Software artefact to upload" | "--archive", type=click.Path(), required=True, help="Software artefact to upload" | ||||
) | ) | ||||
@click.option( | @click.option( | ||||
"--metadata", | "--metadata", | ||||
Show All 11 Lines |