Skip to content

Commit

Permalink
wagner_racksens2 for CMK 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gurubert committed Aug 8, 2024
1 parent 54ce6d4 commit a9e2585
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -199,25 +203,25 @@ 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,
)
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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
48 changes: 48 additions & 0 deletions wagner_racksens2/rulesets/wagner_racksens2.py
Original file line number Diff line number Diff line change
@@ -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.")),
),
)
Binary file removed wagner_racksens2/wagner_racksens2-2.2.0.mkp
Binary file not shown.
Binary file added wagner_racksens2/wagner_racksens2-3.0.0.mkp
Binary file not shown.
51 changes: 0 additions & 51 deletions wagner_racksens2/web/plugins/wato/wagner_racksens2.py

This file was deleted.

0 comments on commit a9e2585

Please sign in to comment.