Skip to content

Commit

Permalink
change to modern rulespec_registry
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianClemens committed Sep 24, 2021
1 parent 0bd72b5 commit eeafcf0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 29 deletions.
18 changes: 6 additions & 12 deletions checks/fritzbox_smarthome
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ factory_settings['fritzbox_smarthome_default_levels'] = {
'powermeter': {},
'temperature': {},
'humidity': {
'humidity_crit': {
'humidity_high': 70,
'humidity_low': 30
},
'humidity_warn': {
'humidity_high': 60,
'humidity_low': 40
}
'humidity_crit': [70, 30],
'humidity_warn': [60, 40]
}
}

Expand Down Expand Up @@ -192,16 +186,16 @@ def smarthome_helper_humidity(data, params):

humidity = int(data['humidity']['rel_humidity'])

if int(params['humidity_crit']['humidity_high']) < humidity: # High crit
if int(params['humidity_crit'][0]) < humidity: # High crit
check_status = 2 if check_status < 2 else check_status
msg_data.append('Humidity is {}% (to high!)'.format(humidity))
elif int(params['humidity_crit']['humidity_low']) > humidity: # Low crit
elif int(params['humidity_crit'][1]) > humidity: # Low crit
check_status = 2 if check_status < 2 else check_status
msg_data.append('Humidity is {}% (to low!)'.format(humidity))
elif int(params['humidity_warn']['humidity_high']) < humidity: # High warn
elif int(params['humidity_warn'][0]) < humidity: # High warn
check_status = 1 if check_status < 1 else check_status
msg_data.append('Humidity is {}% (to high!)'.format(humidity))
elif int(params['humidity_warn']['humidity_low']) > humidity: # Low warn
elif int(params['humidity_warn'][1]) > humidity: # Low warn
check_status = 1 if check_status < 1 else check_status
msg_data.append('Humidity is {}% (to low!)'.format(humidity))
else:
Expand Down
57 changes: 40 additions & 17 deletions web/plugins/wato/parameters_check_fritzbox_smarthome.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
#!/usr/bin/python
#!/usr/bin/env python3
# -*- encoding: utf-8; py-indent-offset: 4 -*-

register_check_parameters(
subgroup_applications,
'fritzbox_smarthome',
_('Settings for Fritz!Box Smarthome Devices'),
Dictionary(
from typing import Type, Optional, List
from cmk.gui.i18n import _
from cmk.gui.valuespec import (
Alternative,
Dictionary,
Integer,
Tuple,
FixedValue,
TextAscii,
)
from cmk.gui.plugins.wato import (
RulespecGroupCheckParametersApplications,
CheckParameterRulespecWithItem,
rulespec_registry,
)


def _parameter_valuespec_fritzbox_smarthome():
return Dictionary(
title = _('Parameter'),
optional_keys = None,
elements = [
Expand Down Expand Up @@ -76,28 +90,37 @@
title = _('Humidity'),

elements = [
('humidity_warn', Dictionary(
('humidity_warn', Tuple(
title = _('Thresholds for WARN'),
optional_keys = [ ],
elements = [
('humidity_high', Integer(label = _('higher than'), title = _('Humidity'), unit = u'%', default_value = 60)),
('humidity_low', Integer(label = _('lesser than'), title = _('Humidity'), unit = u'%', default_value = 40)),
Integer(label = _('higher than'), unit = u'%', default_value = 60),
Integer(label = _('lesser than'), unit = u'%', default_value = 40),
]
)),
('humidity_crit', Dictionary(
('humidity_crit', Tuple(
title = _('Thresholds for CRIT'),
optional_keys = [ ],
elements = [
('humidity_high', Integer(label = _('higher than'), title = _('Humidity'), unit = u'%', default_value = 70)),
('humidity_low', Integer(label = _('lesser than'), title = _('Humidity'), unit = u'%', default_value = 30)),
Integer(label = _('higher than'), unit = u'%', default_value = 70),
Integer(label = _('lesser than'), unit = u'%', default_value = 30),
]
)),
])
),

# temperature
]
),
TextAscii(title = _('Device-ID')),
match_type = 'dict',
)

def _item_spec_fritzbox_smarthome_devices():
return TextAscii(title=_("Device-ID"))

rulespec_registry.register(
CheckParameterRulespecWithItem(
check_group_name="fritzbox_smarthome",
group=RulespecGroupCheckParametersApplications,
item_spec=_item_spec_fritzbox_smarthome_devices,
match_type="dict",
parameter_valuespec=_parameter_valuespec_fritzbox_smarthome,
title=lambda: _('Settings for Fritz!Box Smarthome Devices')
)
)

0 comments on commit eeafcf0

Please sign in to comment.