55 lines
1.7 KiB
Python

#!/usr/bin/env python3
# pylint: disable=missing-module-docstring, missing-class-docstring, missing-function-docstring
from collections.abc import Iterable
from pydantic import BaseModel
from cmk.server_side_calls.v1 import (
HostConfig,
Secret,
SpecialAgentCommand,
SpecialAgentConfig,
)
class NextcloudParams(BaseModel):
hostname: str | None = None
username: str | None = None
password: Secret | None = None
port: int | None = None
folder: str | None = None
no_https: bool = False
no_cert_check: bool = False
def agent_nextcloud_arguments(
params: NextcloudParams, _host_config: HostConfig
) -> Iterable[SpecialAgentCommand]:
# print(f"Params: {params}")
command_arguments: list[str | Secret] = []
if params.hostname is not None:
command_arguments += ["--hostname", params.hostname]
if params.username is not None:
command_arguments += ["--username", params.username]
if params.password is not None:
command_arguments += ["--password", params.password.unsafe()]
if params.port is not None:
command_arguments += ["--port", str(params.port)]
if params.folder is not None:
command_arguments += ["--folder", params.folder]
if params.no_https:
command_arguments.append("--no-https")
if params.no_cert_check:
command_arguments.append("--no-cert-check")
# command_arguments.append(host_config.name)
# print(f"Command Args: {command_arguments}")
yield SpecialAgentCommand(command_arguments=command_arguments)
special_agent_nextcloud = SpecialAgentConfig(
name="nextcloud",
parameter_parser=NextcloudParams.model_validate,
commands_function=agent_nextcloud_arguments,
)