|
| 1 | +# Server-side WATO settings for bakery for plugin for monitoring Kubernetes namespaces, |
| 2 | +# resides at share/check_mk/web/plugins/wato/kubernetes_namespaces_bakery.py |
| 3 | +# ©2024 henri.wahl@ukdd.de |
| 4 | + |
| 5 | +from cmk.gui.i18n import _ |
| 6 | +from cmk.gui.plugins.wato import ( |
| 7 | + HostRulespec, |
| 8 | + rulespec_registry, |
| 9 | +) |
| 10 | +from cmk.gui.valuespec import ( |
| 11 | + Age, |
| 12 | + Dictionary, |
| 13 | + TextAscii, |
| 14 | +) |
| 15 | + |
| 16 | +# Flag to check if the bakery WATO settings should be used |
| 17 | +USE_BAKERY_WATO = True |
| 18 | + |
| 19 | +try: |
| 20 | + # Import the necessary module for Checkmk CEE |
| 21 | + from cmk.gui.cee.plugins.wato.agent_bakery.rulespecs.utils import RulespecGroupMonitoringAgentsAgentPlugins |
| 22 | +except ModuleNotFoundError: |
| 23 | + # If the module is not found, it is not a Checkmk CEE instance |
| 24 | + print("This is not a Checkmk CEE instance and so kubernetes_namespaces bakery WATO can't be loaded.") |
| 25 | + USE_BAKERY_WATO = False |
| 26 | + |
| 27 | + |
| 28 | +def _valuespec_kubernetes_namespaces(): |
| 29 | + """ |
| 30 | + Define the GUI specification for Kubernetes namespaces. |
| 31 | +
|
| 32 | + :return: Dictionary object containing the GUI specification. |
| 33 | + """ |
| 34 | + return Dictionary( |
| 35 | + title=_('Kubernetes namespaces'), |
| 36 | + help=_('Deploys the agent plugin for Kubernetes namespaces'), |
| 37 | + elements=[ |
| 38 | + # Define the interval for collecting data asynchronously |
| 39 | + ('interval', |
| 40 | + Age( |
| 41 | + title=_('Run asynchronously'), |
| 42 | + label=_('Interval for collecting data'), |
| 43 | + default_value=60, # default: 1 minute |
| 44 | + ) |
| 45 | + ), |
| 46 | + ('kubeconfig_path', |
| 47 | + TextAscii( |
| 48 | + title=_('Path for Kubernetes configuration file in environment variable KUBECONFIG'), |
| 49 | + label=_('Full path like /etc/kubernetes/admin.conf'), |
| 50 | + default_value='', |
| 51 | + size=50 |
| 52 | + ) |
| 53 | + ), |
| 54 | + ], |
| 55 | + # keys named here get an option checkbox in the WATO UI |
| 56 | + optional_keys=['interval', 'kubeconfig_path'], |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +if USE_BAKERY_WATO: |
| 61 | + # Register the rulespec for Kubernetes namespaces in the agent bakery |
| 62 | + # Only if the Checkmk CEE module is available aka it is a CEE instance |
| 63 | + rulespec_registry.register( |
| 64 | + HostRulespec( |
| 65 | + group=RulespecGroupMonitoringAgentsAgentPlugins, |
| 66 | + name='agent_config:kubernetes_namespaces', |
| 67 | + valuespec=_valuespec_kubernetes_namespaces, |
| 68 | + )) |
0 commit comments