43 lines
1.3 KiB
Python

"""HAL9002 parameter handling for the special agent"""
from collections.abc import Iterable
from pydantic import BaseModel
from cmk.server_side_calls.v1 import (
HostConfig,
Secret,
SpecialAgentCommand,
SpecialAgentConfig,
)
class Hal9002Params(BaseModel):
"""defines all needed parameters for the special agent"""
hostname: str | None = None
username: str | None = None
password: Secret | None = None
def agent_hal9002_arguments(
params: Hal9002Params, _host_config: HostConfig
) -> Iterable[SpecialAgentCommand]:
"""replaces the argument_thingy from the old API"""
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()]
yield SpecialAgentCommand(command_arguments=command_arguments)
special_agent_hal9002 = SpecialAgentConfig(
# name must be the filename of the executable for the special agent (without prefix)
name="hal9002",
parameter_parser=Hal9002Params.model_validate,
commands_function=agent_hal9002_arguments,
)