Skip to content

Commit 7909e1a

Browse files
authored
Merge pull request #92 from swampdogmash/patch-13
Update yum_cee.py to new API
2 parents 1de22ec + 3bbc990 commit 7909e1a

1 file changed

Lines changed: 73 additions & 47 deletions

File tree

  • lib/python3/cmk_addons/plugins/yum/rulesets
Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,80 @@
11
#!/usr/bin/env python3
22
# -*- encoding: utf-8; py-indent-offset: 4 -*-
3+
from collections.abc import Mapping
34

4-
try:
5-
from cmk.gui.i18n import _
6-
from cmk.gui.plugins.wato.utils import (
7-
HostRulespec,
8-
rulespec_registry,
9-
)
10-
from cmk.gui.cee.plugins.wato.agent_bakery.rulespecs.utils import RulespecGroupMonitoringAgentsAgentPlugins
11-
from cmk.gui.valuespec import (
12-
Alternative,
13-
Age,
14-
Dictionary,
15-
FixedValue,
16-
)
5+
from cmk.rulesets.v1.form_specs import (
6+
DictElement,
7+
Dictionary,
8+
# DefaultValue,
9+
# SingleChoice,
10+
# SingleChoiceElement,
11+
# Integer,
12+
# InputHint,
13+
CascadingSingleChoice,
14+
CascadingSingleChoiceElement,
15+
FixedValue,
16+
TimeSpan,
17+
TimeMagnitude,
18+
# SimpleLevels,
19+
)
20+
from cmk.rulesets.v1.rule_specs import AgentConfig, Topic, Title, Help
1721

18-
def _valuespec_agent_config_yum():
19-
return Alternative(
20-
title=_("Yum (Community Version) updates (Linux)"),
21-
help=_(
22-
"This will deploy the agent plugin <tt>yum</tt>. This will activate the "
23-
"check <tt>zypper</tt> on redHat based hosts and monitor pending normal and security updates."
24-
),
25-
elements=[
26-
Dictionary(
27-
title=_("Deploy the Yum plugin"),
28-
elements=[
29-
(
30-
"interval",
31-
Age(title="Interval for checking for updates"),
32-
),
33-
],
34-
optional_keys=False,
35-
),
36-
FixedValue(
37-
None,
38-
title=_("Do not deploy the Yum plugin"),
39-
totext=_("(disabled)")
22+
def _migrateInt(value: object) -> Mapping[str, object]:
23+
if value is not None:
24+
if 'interval' in value:
25+
match value["interval"]:
26+
case _ if value["interval"] >= 0:
27+
return {'deploy': ('interval', float(value["interval"]))}
28+
case None:
29+
return {'deploy': ('interval', 77.0)}
30+
else:
31+
return value
32+
else:
33+
return {'deploy': 'nointerval'}
34+
35+
36+
def _parameter_form_yum_bakery() -> Dictionary:
37+
return Dictionary(
38+
migrate=_migrateInt,
39+
title=Title('Deploy the Yum plugin'),
40+
help_text=Help('This will deploy the agent plugin <tt>Yum</tt>. This will activate the '
41+
'check <tt>Yum</tt> on redHat based hosts and monitor pending normal and security updates.'
42+
),
43+
elements={
44+
"deploy": DictElement(
45+
required=True,
46+
parameter_form=CascadingSingleChoice(
47+
title=Title('Deployment options for the Yum plugin.'),
48+
#prefill=DefaultValue("interval"),
49+
help_text=Help('Determines how the the <tt>Yum</tt> plugin will run on a deployed agent or disables it on an deployed agent'),
50+
elements=[
51+
CascadingSingleChoiceElement(
52+
name="interval",
53+
title=Title("Deploy the Yum plugin"),
54+
parameter_form=TimeSpan(
55+
title=Title('Interval that the plugin runs at on the client'),
56+
help_text=Help('Determines how often that the <tt>Yum</tt> plugin will run on a deployed agent.'),
57+
displayed_magnitudes=[TimeMagnitude.SECOND, TimeMagnitude.MINUTE, TimeMagnitude.HOUR, TimeMagnitude.DAY],
58+
#prefill=DefaultValue(129600.0),
59+
),
4060
),
41-
],
42-
default_value={"interval": 129600, },
43-
)
61+
CascadingSingleChoiceElement(
62+
name="nointerval",
63+
title=Title("Do not deploy the Yum plugin"),
64+
parameter_form=FixedValue(value=None),
65+
)
66+
]
67+
),
68+
),
69+
},
70+
)
4471

45-
rulespec_registry.register(
46-
HostRulespec(
47-
group=RulespecGroupMonitoringAgentsAgentPlugins,
48-
name="agent_config:yum",
49-
valuespec=_valuespec_agent_config_yum,
50-
))
5172

52-
except ModuleNotFoundError:
53-
# RAW edition
54-
pass
73+
rule_spec_yum_bakery = AgentConfig(
74+
title=Title('YUM plugin'),
75+
name='yum',
76+
parameter_form=_parameter_form_yum_bakery,
77+
topic=Topic.APPLICATIONS,
78+
help_text=Help('This will deploy the agent plugin <tt>Yum</tt> '
79+
'for checking patch status.'),
80+
)

0 commit comments

Comments
 (0)