Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cli option to set connection timeout #81

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/check_routeros.icinga2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ template CheckCommand "routeros_command" {
required = true
order = -2
}
"--connection-timeout" = {
value = "$routeros_connection_timeout$"
order = -2
}
"--ssl" = {
set_if = "$routeros_ssl$"
order = -2
Expand Down
14 changes: 11 additions & 3 deletions routeros_check/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
required=True,
help="The password of the monitoring user",
)
@click.option(
"--connection-timeout",
default=10,
help="The connection timeout (Default: 10 seconds). Set to 0 to disable timeout, but be careful.",
type=int,
)
@click.option(
"--routeros-version",
default="auto",
Expand Down Expand Up @@ -71,16 +77,18 @@
@click.option("--ssl-verify-hostname/--no-ssl-verify-hostname", default=True)
@click.option("-v", "--verbose", count=True)
@click.pass_context
def cli(ctx, host: str, hostname: Optional[str], port: int, username: str, password: str, routeros_version: str,
use_ssl: bool, ssl_cafile: Optional[str], ssl_capath: Optional[str], ssl_force_no_certificate: bool,
ssl_verify: bool, ssl_verify_hostname: bool, verbose: int):
def cli(ctx, host: str, hostname: Optional[str], port: int, username: str, password: str, connection_timeout: int,
routeros_version: str, use_ssl: bool, ssl_cafile: Optional[str], ssl_capath: Optional[str],
ssl_force_no_certificate: bool, ssl_verify: bool, ssl_verify_hostname: bool, verbose: int):
ctx.ensure_object(dict)
ctx.obj["host"] = host
ctx.obj["hostname"] = hostname
ctx.obj["port"] = port
ctx.obj["username"] = username
ctx.obj["password"] = password
ctx.obj["routeros_version"] = routeros_version
# socket timeout = None will wait forever
ctx.obj["timeout"] = connection_timeout if connection_timeout == 0 else None
ctx.obj["ssl"] = use_ssl
ctx.obj["ssl_cafile"] = ssl_cafile
ctx.obj["ssl_capath"] = ssl_capath
Expand Down
Loading