diff --git a/wagner_racksens2/lib/check_mk/base/plugins/agent_based/wagner_racksens2.py b/wagner_racksens2/agent_based/wagner_racksens2.py similarity index 94% rename from wagner_racksens2/lib/check_mk/base/plugins/agent_based/wagner_racksens2.py rename to wagner_racksens2/agent_based/wagner_racksens2.py index 17251682..4ee03bfd 100644 --- a/wagner_racksens2/lib/check_mk/base/plugins/agent_based/wagner_racksens2.py +++ b/wagner_racksens2/agent_based/wagner_racksens2.py @@ -16,22 +16,26 @@ # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301 USA. -from .agent_based_api.v1 import ( +from cmk.agent_based.v2 import ( check_levels, + CheckPlugin, + CheckResult, contains, - register, - render, + DiscoveryResult, Metric, + render, OIDEnd, Result, Service, + SNMPSection, SNMPTree, State, + StringTable, ) -from .utils import temperature +from cmk.plugins.lib import temperature -def parse_wagner_racksens2(string_table): +def parse_wagner_racksens2(string_table: StringTable): section = { 'info': [ ('Manufacturer', string_table[0][0][0]), @@ -77,7 +81,7 @@ def parse_wagner_racksens2(string_table): int(string_table[0][0][temp + 9])) ) return section -register.snmp_section( +snmp_section_wagner_racksens2 = SNMPSection( name="wagner_racksens2", detect=contains(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.34187.57949"), parse_function=parse_wagner_racksens2, @@ -164,7 +168,7 @@ def check_wagner_racksens2_info(section): yield Result(state=State.OK, summary="%s: %s" % (key, value)) -register.check_plugin( +check_plugin_wagner_racksens2_info = CheckPlugin( name="wagner_racksens2_info", sections=['wagner_racksens2'], service_name="Racksens2 Info", @@ -199,7 +203,7 @@ def check_wagner_racksens2_detector(item, params, section): yield Result(state=State.CRIT, summary="Fire Alarm") yield from check_levels( vals['smoke'], - levels_upper=params.get('smoke_levels'), + levels_upper=("fixed", params.get('smoke_levels')), metric_name="smoke_perc", label="Smoke detected", render_func=render.percent, @@ -207,17 +211,17 @@ def check_wagner_racksens2_detector(item, params, section): levels_lower = params.get('chamber_levels') if isinstance(levels_lower, tuple): warn, crit = levels_lower - levels_lower = (-warn, -crit) + levels_lower = ("fixed", (-warn, -crit)) yield from check_levels( vals['chamber'], - levels_upper=params.get('chamber_levels'), + levels_upper=("fixed", params.get('chamber_levels')), levels_lower=levels_lower, metric_name="chamber_perc", label="Chamber Deviation", render_func=render.percent, ) -register.check_plugin( +check_plugin_wagner_racksens2_detector = CheckPlugin( name="wagner_racksens2_detector", sections=['wagner_racksens2'], service_name="Racksens2 Detector %s", @@ -263,7 +267,7 @@ def check_wagner_racksens2_temp(item, params, section): dev_status_name = 'Alarm', ) -register.check_plugin( +check_plugin_wagner_racksens2_temp = CheckPlugin( name="wagner_racksens2_temp", sections=['wagner_racksens2'], service_name="Racksens2 Temp %s", @@ -298,7 +302,7 @@ def check_wagner_racksens2_alarm(item, section): status = map_status.get(section['alarms'][item], State.UNKNOWN) yield Result(state=status, summary="Status: %d" % section['alarms'][item]) -register.check_plugin( +check_plugin_wagner_racksens2_alarm = CheckPlugin( name="wagner_racksens2_alarm", sections=['wagner_racksens2'], service_name="Racksens2 Alarm %s", @@ -330,14 +334,14 @@ def check_wagner_racksens2_airflow(section): yield Metric('airflow_meter', airflow[1]) yield from check_levels( airflow[2], - levels_upper=(None, airflow[3]), - levels_lower=(None, -airflow[3]), + levels_upper=("fixed", (airflow[3], airflow[3])), + levels_lower=("fixed", (-airflow[3], -airflow[3])), metric_name='deviation_airflow', label='Deviation', render_func=render.percent, ) -register.check_plugin( +check_plugin_wagner_racksens2_airflow = CheckPlugin( name="wagner_racksens2_airflow", sections=['wagner_racksens2'], service_name="Racksens2 Airflow", diff --git a/wagner_racksens2/web/plugins/metrics/wagner_racksens2.py b/wagner_racksens2/graphing/wagner_racksens2.py similarity index 58% rename from wagner_racksens2/web/plugins/metrics/wagner_racksens2.py rename to wagner_racksens2/graphing/wagner_racksens2.py index 2f7d1ba3..983d2f63 100644 --- a/wagner_racksens2/web/plugins/metrics/wagner_racksens2.py +++ b/wagner_racksens2/graphing/wagner_racksens2.py @@ -17,24 +17,29 @@ # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, # Boston, MA 02110-1301 USA. -from cmk.utils.render import physical_precision -from cmk.gui.plugins.metrics.unit import physical_precision_list +from cmk.graphing.v1 import Title +from cmk.graphing.v1.metrics import ( + Color, + DecimalNotation, + IECNotation, + Metric, + StrictPrecision, + Unit, +) -unit_info["m/s"] = { - "title": _("Meters per second"), - "symbol": _("m/s"), - "render": lambda v: physical_precision(v, 3, _("m/s")), - "graph_unit": lambda v: physical_precision_list(v, 3, _("m/s")), -} +UNIT_METERS_PER_SECOND = Unit(IECNotation("m/s")) +UNIT_PERCENT = Unit(DecimalNotation("%"), StrictPrecision(2)) -metric_info["chamber_perc"] = { - "title": _("Chamber Deviation"), - "unit": "%", - "color": "#88f060", -} +metric_chamber_perc = Metric( + name = "chamber_perc", + title = Title("Chamber Deviation"), + unit = UNIT_PERCENT, + color = Color.LIGHT_GREEN, +) -metric_info["airflow_meter"] = { - "title": _("Airflow"), - "unit": "m/s", - "color": "#123456", -} +metric_airflow_meter = Metric( + name = "airflow_meter", + title = Title("Airflow"), + unit = UNIT_METERS_PER_SECOND, + color = Color.PURPLE, +) diff --git a/wagner_racksens2/rulesets/wagner_racksens2.py b/wagner_racksens2/rulesets/wagner_racksens2.py new file mode 100644 index 00000000..082496d4 --- /dev/null +++ b/wagner_racksens2/rulesets/wagner_racksens2.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# -*- encoding: utf-8; py-indent-offset: 4 -*- + +from cmk.rulesets.v1 import Help, Title +from cmk.rulesets.v1.form_specs import ( + DictElement, + Dictionary, + Integer, + InputHint, + LevelDirection, + migrate_to_integer_simple_levels, + SimpleLevels, + String, +) +from cmk.rulesets.v1.rule_specs import CheckParameters, HostAndItemCondition, Topic + +def _parameter_form_wagner_racksens2_detector() -> Dictionary: + return Dictionary( + elements = { + "smoke_levels": DictElement( + parameter_form=SimpleLevels( + title = Title("Smoke Levels"), + level_direction = LevelDirection.UPPER, + form_spec_template = Integer(unit_symbol="%"), + migrate=migrate_to_integer_simple_levels, + prefill_fixed_levels=InputHint(value=(3, 5)), + )), + "chamber_levels": DictElement( + parameter_form=SimpleLevels( + title = Title("Chamber Levels"), + level_direction = LevelDirection.UPPER, + form_spec_template = Integer(unit_symbol="%"), + migrate=migrate_to_integer_simple_levels, + prefill_fixed_levels=InputHint(value=(10, 20)), + )), + }, + ) + +rule_spec_wagner_racksens2_detector = CheckParameters( + name="wagner_racksens2_detector", + topic=Topic.ENVIRONMENTAL, + parameter_form=_parameter_form_wagner_racksens2_detector, + title=Title("Wagner Racksens2 Smoke Detector"), + condition=HostAndItemCondition( + item_title=Title("Sensor ID"), + item_form=String(help_text=Help("The identifier of the smoke detector.")), + ), +) diff --git a/wagner_racksens2/wagner_racksens2-2.2.0.mkp b/wagner_racksens2/wagner_racksens2-2.2.0.mkp deleted file mode 100644 index d8c88717..00000000 Binary files a/wagner_racksens2/wagner_racksens2-2.2.0.mkp and /dev/null differ diff --git a/wagner_racksens2/wagner_racksens2-3.0.0.mkp b/wagner_racksens2/wagner_racksens2-3.0.0.mkp new file mode 100644 index 00000000..e91b7d81 Binary files /dev/null and b/wagner_racksens2/wagner_racksens2-3.0.0.mkp differ diff --git a/wagner_racksens2/web/plugins/wato/wagner_racksens2.py b/wagner_racksens2/web/plugins/wato/wagner_racksens2.py deleted file mode 100644 index 482009e8..00000000 --- a/wagner_racksens2/web/plugins/wato/wagner_racksens2.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python3 -# -*- encoding: utf-8; py-indent-offset: 4 -*- - -from cmk.gui.i18n import _ -from cmk.gui.valuespec import ( - Dictionary, - Tuple, - Integer, - TextInput, -) - -from cmk.gui.plugins.wato.utils import ( - rulespec_registry, - CheckParameterRulespecWithItem, - RulespecGroupCheckParametersEnvironment, -) - -def _parameter_valuespec_wagner_racksens2_detector(): - return Dictionary( - elements = [ - ( 'smoke_levels', - Tuple( - title = _("Smoke Levels"), - elements = [ - Integer(title = _("Warning at"), unit='%', default_value=3), - Integer(title = _("Critical at"), unit='%', default_value=5), - ] - )), - ( 'chamber_levels', - Tuple( - title = _("Chamber Levels"), - elements = [ - Integer(title = _("Warning at"), unit='%', default_value=10), - Integer(title = _("Critical at"), unit='%', default_value=20), - ] - )), - ], - optional_keys = ['smoke_levels', 'chamber_levels'], - ) - -rulespec_registry.register( - CheckParameterRulespecWithItem( - check_group_name="wagner_racksens2_detector", - group=RulespecGroupCheckParametersEnvironment, - match_type="dict", - parameter_valuespec=_parameter_valuespec_wagner_racksens2_detector, - title=lambda: _("Wagner Racksens2 Smoke Detector"), - item_spec=lambda: TextInput( - title=_("Sensor ID"), help=_("The identifier of the smoke detector.") - ), - ))