Traefik-CheckMK/rulesets/rs_traefik_params.py

145 lines
5.2 KiB
Python

#!/usr/bin/env python3
# pylint: disable=line-too-long
"""defines the form for typing in all needed Traefik parameters"""
from cmk.rulesets.v1 import Help, Title, Label
from cmk.rulesets.v1.form_specs import (
DictElement,
Dictionary,
String,
validators,
BooleanChoice,
Integer,
Password,
migrate_to_password,
InputHint,
DefaultValue,
SingleChoice,
SingleChoiceElement,
)
from cmk.rulesets.v1.rule_specs import SpecialAgent, Topic
def _form_spec_special_agent_traefik() -> Dictionary:
return Dictionary(
title=Title("Traefik Server Information"),
help_text=Help("Checking Traefik systems via API"),
elements={
"hostname": DictElement(
required=True,
parameter_form=String(
title=Title("Hostname"),
help_text=Help(
"Hostname of Traefik server (bare FQDN or IP), mandatory, eg. traefik.yourdomain.tld"
),
custom_validate=(validators.LengthInRange(min_value=1),),
prefill=InputHint("traefik.yourdomain.tld"),
),
),
"username": DictElement(
required=True,
parameter_form=String(
title=Title("Username"),
help_text=Help("Username for authentification, mandatory"),
custom_validate=(validators.LengthInRange(min_value=1),),
prefill=InputHint("traefikadmin"),
),
),
"password": DictElement(
required=True,
parameter_form=Password(
title=Title("Password"),
help_text=Help("Specify password, mandatory"),
custom_validate=(validators.LengthInRange(min_value=1),),
migrate=migrate_to_password,
),
),
"auth_type": DictElement(
required=True,
parameter_form=SingleChoice(
title=Title("Authentification type"),
help_text=Help("Type of authentification to use"),
elements=[
SingleChoiceElement(
name="basic",
title=Title("Basic"),
),
SingleChoiceElement(
name="digest",
title=Title("Digest"),
),
],
),
),
"no_http_check": DictElement(
required=False,
parameter_form=BooleanChoice(
title=Title("Disable HTTP components"),
help_text=Help(
"Activate to disable check of HTTP components, optional"
),
label=Label("Disable HTTP components"),
),
),
"no_tcp_check": DictElement(
required=False,
parameter_form=BooleanChoice(
title=Title("Disable TCP components"),
help_text=Help(
"Activate to disable check of TCP components, optional"
),
label=Label("Disable TCP components"),
),
),
"no_udp_check": DictElement(
required=False,
parameter_form=BooleanChoice(
title=Title("Disable UDP components"),
help_text=Help(
"Activate to disable check of UDP components, optional"
),
label=Label("Disable UDP components"),
),
),
"no_https": DictElement(
required=False,
parameter_form=BooleanChoice(
title=Title("Disable HTTPS"),
help_text=Help(
"Activate to disable encryption (not recommended), optional"
),
label=Label("Disable HTTPS"),
),
),
"no_cert_check": DictElement(
required=False,
parameter_form=BooleanChoice(
title=Title("Disable certificate validation"),
help_text=Help(
"Activate to disable certificate validation (not recommended), optional"
),
label=Label("Disable certificate validation"),
),
),
"port": DictElement(
required=False,
parameter_form=Integer(
title=Title("Port"),
help_text=Help(
"Specify port the Traefik system ist listening on (if not 80/443), optional"
),
prefill=DefaultValue(443),
custom_validate=(validators.NetworkPort(),),
),
),
},
)
rule_spec_traefik = SpecialAgent(
name="traefik",
title=Title("Traefik connection parameters"),
topic=Topic.APPLICATIONS,
parameter_form=_form_spec_special_agent_traefik,
)