Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/cli.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 2019 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 | ||||
import sys | import sys | ||||
import click | import click | ||||
from swh.core.cli import CONTEXT_SETTINGS | from swh.core.cli import CONTEXT_SETTINGS | ||||
from .vault import VaultCheck | from .vault import VaultCheck | ||||
@click.group(name='icinga_plugins', context_settings=CONTEXT_SETTINGS) | @click.group(name='icinga_plugins', context_settings=CONTEXT_SETTINGS) | ||||
@click.option('--swh-storage-url', type=str, | |||||
help='URL to an swh-storage HTTP API') | |||||
@click.option('--swh-web-url', type=str, | |||||
help='URL to an swh-web instance') | |||||
@click.option('-w', '--warning', type=int, | @click.option('-w', '--warning', type=int, | ||||
help='Warning threshold.') | help='Warning threshold.') | ||||
@click.option('-c', '--critical', type=int, | @click.option('-c', '--critical', type=int, | ||||
help='Critical threshold.') | help='Critical threshold.') | ||||
@click.pass_context | @click.pass_context | ||||
def cli(ctx, swh_storage_url, swh_web_url, warning, critical): | def cli(ctx, **kwargs): | ||||
"""Main command for Icinga plugins | """Main command for Icinga plugins | ||||
""" | """ | ||||
ctx.ensure_object(dict) | ctx.ensure_object(dict) | ||||
ctx.obj['swh_storage_url'] = swh_storage_url | ctx.obj.update(kwargs) | ||||
ctx.obj['swh_web_url'] = swh_web_url | |||||
ctx.obj['warning_threshold'] = warning | |||||
ctx.obj['critical_threshold'] = critical | |||||
@cli.group(name='check-vault') | @cli.group(name='check-vault') | ||||
@click.option('--swh-storage-url', type=str, required=True, | |||||
help='URL to an swh-storage HTTP API') | |||||
@click.option('--swh-web-url', type=str, required=True, | |||||
help='URL to an swh-web instance') | |||||
@click.option('--poll-interval', type=int, default=10, | @click.option('--poll-interval', type=int, 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, poll_interval): | def check_vault(ctx, **kwargs): | ||||
ctx.obj['poll_interval'] = poll_interval | ctx.obj.update(kwargs) | ||||
@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.""" | ||||
sys.exit(VaultCheck(ctx.obj).main()) | sys.exit(VaultCheck(ctx.obj).main()) |