Skip to content

Commit 0461420

Browse files
committed
simplify
1 parent e00e447 commit 0461420

2 files changed

Lines changed: 82 additions & 5 deletions

File tree

  • mkp/local/lib/python3

mkp/local/lib/python3/cmk/base/cee/plugins/bakery/yum.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def get_yum_files(conf: Any) -> FileGenerator:
1616
"""
1717

1818
# debugging
19-
# with open('/tmp/debug.txt', 'a') as debug_file:
20-
# debug_file.write(f'config: {conf}\n')
19+
with open('/tmp/debug.txt', 'a') as debug_file:
20+
debug_file.write(f'config: {conf}\n')
2121

2222
if isinstance(conf, dict):
2323
# default to no interval - will be filled if set in config
@@ -41,8 +41,6 @@ def get_yum_files(conf: Any) -> FileGenerator:
4141
elif conf.get('deploy', 'interval')[1] is not None:
4242
interval = conf.get('deploy', 'interval')[1]
4343

44-
45-
4644
# only makes sense on Linux so just create for that OS
4745
yield Plugin(base_os=OS.LINUX,
4846
source=Path('yum'),

mkp/local/lib/python3/cmk_addons/plugins/yum/rulesets/yum_cee.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,47 @@ def _migrate_int_to_float(value: object) -> Mapping[str, object]:
8181
}
8282

8383

84+
def _migrate_int_to_float2(value: object) -> Mapping[str, object]:
85+
"""
86+
migrate from integer interval to float interval
87+
"""
88+
if value is not None:
89+
# backward compatibility - migrate from deploy to deployment
90+
if value.get('deploy'):
91+
if value['deploy'].get('interval'):
92+
return {
93+
'deploy': {
94+
'interval': float(value['deploy']['interval'])
95+
}
96+
}
97+
else:
98+
return {
99+
'deploy': {
100+
'interval': False
101+
}
102+
}
103+
# fix a short time used interval instead of deploy
104+
elif value.get('interval'):
105+
return {
106+
'deploy': {
107+
'interval': float(value['interval'])
108+
}
109+
}
110+
# backward compatibility
111+
elif value.get('nointerval'):
112+
return {
113+
'deploy': {
114+
'interval': False
115+
}
116+
}
117+
else:
118+
return value
119+
else:
120+
return {
121+
'deploy': False
122+
}
123+
124+
84125
def _parameter_form_yum_bakery() -> Dictionary:
85126
"""
86127
definition of the parameter form for the YUM bakery plugin
@@ -138,10 +179,48 @@ def _parameter_form_yum_bakery() -> Dictionary:
138179
)
139180

140181

182+
def _parameter_form_yum_bakery2() -> Dictionary:
183+
"""
184+
definition of the parameter form for the YUM bakery plugin
185+
:return:
186+
"""
187+
return Dictionary(
188+
migrate=_migrate_int_to_float2,
189+
title=Title('YUM Update Check'),
190+
help_text=Help('This will deploy the agent plugin <tt>YUM</tt>. This will activate the '
191+
'check <tt>YUM</tt> on RedHat based hosts and monitor pending normal and security updates.'
192+
),
193+
elements={
194+
'deploy': DictElement(
195+
parameter_form=Dictionary(
196+
title=Title('Deploy plugin'),
197+
help_text=Help(
198+
'Determines how the the <tt>YUM</tt> plugin will run on a deployed agent or disables it on an deployed agent'),
199+
elements={
200+
'interval': DictElement(
201+
parameter_form=TimeSpan(
202+
title=Title('Run asynchronously'),
203+
label=Label('Interval for collecting data'),
204+
help_text=Help(
205+
'Determines how often the plugin will run on a deployed agent.'),
206+
displayed_magnitudes=[TimeMagnitude.SECOND,
207+
TimeMagnitude.MINUTE,
208+
TimeMagnitude.HOUR,
209+
TimeMagnitude.DAY],
210+
prefill=DefaultValue(DEFAULT_INTERVAL),
211+
)
212+
)
213+
}
214+
),
215+
)
216+
}
217+
)
218+
219+
141220
rule_spec_yum_bakery = AgentConfig(
142221
title=Title('YUM Update Check'),
143222
name='yum',
144-
parameter_form=_parameter_form_yum_bakery,
223+
parameter_form=_parameter_form_yum_bakery2,
145224
topic=Topic.OPERATING_SYSTEM,
146225
help_text=Help('This will deploy the agent plugin <tt>YUM</tt> '
147226
'for checking package update status.'),

0 commit comments

Comments
 (0)