special_agent_edirectory_monitor.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. # -*- encoding: utf-8; py-indent-offset: 4 -*-
  3. # (c) Michael Honkoop <mhonkoop@comsolve.nl>
  4. # License: GNU General Public License v2
  5. from collections.abc import Iterator, Mapping, Sequence
  6. from pydantic import BaseModel
  7. from cmk.server_side_calls.v1 import HostConfig, SpecialAgentCommand, SpecialAgentConfig
  8. from cmk.server_side_calls.v1._utils import Secret
  9. class Params(BaseModel):
  10. check_tls: bool | None = None
  11. exclude_sections: str | None = None
  12. user: str
  13. password: Secret
  14. def commands_function(params: Params, host_config: HostConfig) -> Iterator[SpecialAgentCommand]:
  15. """Always use LDAPS for querying LDAP Server"""
  16. command_arguments: list[str | Secret] = [
  17. "-s " + "ldaps://" + host_config.name + ":636",
  18. "-u " + params.user,
  19. "-p",
  20. params.password.unsafe(),
  21. ]
  22. if params.check_tls is not None and params.check_tls is True:
  23. command_arguments += ["--verify-tls"]
  24. if params.exclude_sections:
  25. command_arguments += ["--exclude=" + params.exclude_sections]
  26. yield SpecialAgentCommand(command_arguments=command_arguments)
  27. special_agent_edirectory_monitor = SpecialAgentConfig(
  28. name="edirectory_monitor",
  29. parameter_parser=Params.model_validate,
  30. commands_function=commands_function,
  31. )