diff --git a/agent_based/cisco_wlc_temp.py b/agent_based/cisco_wlc_temp.py new file mode 100644 index 0000000000000000000000000000000000000000..37ae9deb2db61eeb4f4f52d8326ff6dc1e5a7334 --- /dev/null +++ b/agent_based/cisco_wlc_temp.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# License: GNU General Public License v2 +# +# Author: thl-cmk[at]outlook[dot]com +# URL : https://thl-cmk.hopto.org +# Date : 2016-03-31 +# +# Monitors Cisco WLC temperature sensor +# +# tested with WLC2504, WLC5520 +# +# 2016-07-02: fixed crit/warn to >= +# 2018-09-14: workaround for wrong data from Mobility Express Controller --> removed +# 2021-07-15: rewritten for CMK 2.0 +# +# sample snmpwalk +# +# .1.3.6.1.4.1.14179.2.3.1.12.0 = STRING: "1" +# .1.3.6.1.4.1.14179.2.3.1.13.0 = STRING: "18" +# .1.3.6.1.4.1.14179.2.3.1.14.0 = STRING: "10" +# .1.3.6.1.4.1.14179.2.3.1.15.0 = STRING: "38" +# +# sample string_table +# +# [['1', '18', '10', '38']] +# + +from dataclasses import dataclass +from typing import Optional +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( + DiscoveryResult, + CheckResult, + StringTable, +) + +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( + register, + Service, + Result, + SNMPTree, + contains, + State, + check_levels, +) + + +@dataclass +class CiscoWlcTemp: + environment: str + current: int + lowlimit: float + highlimit: float + + +_wlc_temp_environment = { + '0': 'unknown', + '1': 'commercial', + '2': 'industrial', +} + + +def parse_cisco_wlc_temp(string_table: StringTable) -> Optional[CiscoWlcTemp]: + try: + environment, temperature, lowlimit, highlimit = string_table[0] + except IndexError: + return + + temperature = int(temperature) + highlimit = int(highlimit) + lowlimit = int(lowlimit) + environment = _wlc_temp_environment.get(environment) + return CiscoWlcTemp( + environment=environment, + current=temperature, + lowlimit=lowlimit, + highlimit=highlimit, + ) + + +def discovery_cisco_wlc_temp(section: CiscoWlcTemp) -> DiscoveryResult: + yield Service() + + +def check_cisco_wlc_temp(params, section: CiscoWlcTemp) -> CheckResult: + yield from check_levels( + value=section.current, + label='Temperature', + levels_upper=params['levels_upper'], + levels_lower=params['levels_lower'], + render_func=lambda v: f'{v}°C', + metric_name='temp', + boundaries=(0, 100), + ) + + yield Result(state=State.OK, + notice=f'Lower/upper levels reported by the device: {section.lowlimit}°C/{section.highlimit}°C') + yield Result(state=State.OK, notice=f'Environment type reported by the device: {section.environment}') + + +register.snmp_section( + name='cisco_wlc_temp', + parse_function=parse_cisco_wlc_temp, + fetch=SNMPTree( + base='.1.3.6.1.4.1.14179.2.3.1', # AIRESPACE-WIRELESS-MIB::bsnGlobalDot11Config + oids=[ + '12', # bsnOperatingTemperatureEnvironment + '13', # bsnSensorTemperature (Current Internal Temperature of the unit in Centigrade) + '14', # bsnTemperatureAlarmLowLimit + '15', # bsnTemperatureAlarmHighLimit + ] + ), + detect=contains('.1.3.6.1.2.1.1.1.0', 'Cisco Controller'), # sysDescr +) + +register.check_plugin( + name='cisco_wlc_temp', + service_name='Temperature', + discovery_function=discovery_cisco_wlc_temp, + check_function=check_cisco_wlc_temp, + check_default_parameters={'levels_upper': (36, 38), 'levels_lower': (12, 10)}, + check_ruleset_name='cisco_wlc_temp', +) diff --git a/checkman/cisco_wlc_temp b/checkman/cisco_wlc_temp index cb4b0347bb1dd23884cad0b4ff22d04bc200b255..2329c010350c3518d90e5e243ec299ccc714cf49 100644 --- a/checkman/cisco_wlc_temp +++ b/checkman/cisco_wlc_temp @@ -1,30 +1,31 @@ -title: Cisco WLC: temperatur sensors +title: Cisco WLC: temperature sensor agents: snmp author: Th.L. catalog: hw/network/cisco license: GPLv3 distribution: unkown description: - The Cisco "Wireless LAN Controller" (WLC) has some temperatur sensors. - This check allows to monitor this sensors. Default levels are 60°/70° celsius - for warning/critical. + The Cisco "Wireless LAN Controller" (WLC) has some temperature sensors. + This check allows to monitor this sensors. The check uses the bsnSensorTemperature from the AIRESPACE-WIRELESS-MIB (1.3.6.1.4.1.14179). - The check is tested against WLC2504 devices. + The check is tested against WLC2504 and WLC5520 devices. perfdata: - Temperatur + temp item: - One item per temperatur sensor is generated. + There is no item. inventory: - The check detects WLC temperatur sensors and saves them. + The check detects WLC temperature sensors and saves them. parameters: - Warning/Critical levels. Default is 60°/70° celsius. + lower_levels, default is 12°C/10°C + upper_levels, default is 36°C/38°C + diff --git a/cisco_wlc_temp.mkp b/cisco_wlc_temp.mkp index 4d4807e2bea9c71f8777ecff0b4dc3ad19429912..71b877e41331ed5e39b76fc356b087c056f8e8cb 100644 Binary files a/cisco_wlc_temp.mkp and b/cisco_wlc_temp.mkp differ diff --git a/packages/cisco_wlc_temp b/packages/cisco_wlc_temp index 6e34fe6063884737b4e968e8dcd3ab7585275329..b864ecba95c6e2eb235d10abdde72a99341273fe 100644 --- a/packages/cisco_wlc_temp +++ b/packages/cisco_wlc_temp @@ -1,14 +1,15 @@ -{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)', - 'description': u'monitor Cisco WLC temperatur sensor\n\ntested with WLC2504\n', +{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', + 'description': 'monitor Cisco WLC temperature sensor\n' + '\n' + 'tested with WLC2504 and WLC5520\n', 'download_url': 'https://thl-cmk.hopto.org', - 'files': {'checkman': ['cisco_wlc_temp'], - 'checks': ['cisco_wlc_temp'], - 'web': ['plugins/wato/cisco_wlc_temp.py', - 'plugins/metrics/cisco_wlc_temp.py']}, + 'files': {'agent_based': ['cisco_wlc_temp.py'], + 'checkman': ['cisco_wlc_temp'], + 'web': ['plugins/wato/cisco_wlc_temp.py']}, 'name': 'cisco_wlc_temp', - 'num_files': 4, - 'title': u'monitor Cisco WLC temperatur sensor', - 'version': '20180805.v.0.0.1', - 'version.min_required': '1.2.8b8', - 'version.packaged': '1.6.0p12', + 'num_files': 3, + 'title': 'monitor Cisco WLC temperature sensor', + 'version': '20210715.v.0.2', + 'version.min_required': '2.0.0', + 'version.packaged': '2021.07.14', 'version.usable_until': None} \ No newline at end of file diff --git a/web/plugins/wato/cisco_wlc_temp.py b/web/plugins/wato/cisco_wlc_temp.py index ef71059dd0113546608ccab8454cd07ce9f32b5a..e0ecbb4bd8ea9fe62109fd3229f6f673941fe4eb 100644 --- a/web/plugins/wato/cisco_wlc_temp.py +++ b/web/plugins/wato/cisco_wlc_temp.py @@ -1,22 +1,64 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- # -# Author : Th.L. -# Content: wato plugin for snmp check 'cisco_wlc_temp' -# to configure waring/critical levels +# License: GNU General Public License v2 # +# Author: thl-cmk[at]outlook[dot]com +# URL : https://thl-cmk.hopto.org +# Date : 2016-03-31 # -register_check_parameters( - subgroup_environment, - 'cisco_wlc_temp', - _('Cisco WLC temperatur sensor'), - Tuple( - title=_('Cisco WLC temperatur sensor thresholds'), - elements=[ - Integer(title=_('warning at'), unit=_(u'° celsius'), default_value=50), - Integer(title=_('critical at'), unit=_(u'° celsius'), default_value=60), - ] - ), - None, - None +# WATO for plugin cisco_wlc_temp +# +# + +from cmk.gui.i18n import _ +from cmk.gui.valuespec import ( + Dictionary, + Tuple, + Integer, +) + +from cmk.gui.plugins.wato import ( + CheckParameterRulespecWithItem, + rulespec_registry, + RulespecGroupCheckParametersNetworking, ) + + +def _parameter_valuespec_cisco_wlc_temp(): + return Dictionary(elements=[ + ('levels_upper', + Tuple( + title=_('Temperature upper levels'), + help=_('Set the upper levels for temperature in °C. From the MID description: ' + 'Operating Environment of the Airespace Switch. commercial is Commercial (0 to 40 C) ' + 'and industrial is Industrial (-10 to 70 C)'), + elements=[ + Integer(title=_('Warning at'), unit=u'°C', default_value=36, minvalue=-20, maxvalue=100), + Integer(title=_('Critical at'), unit=u'°C', default_value=38, minvalue=-20, maxvalue=100) + ], + ), + ), + ('levels_lower', + Tuple( + title=_('Temperature lower levels'), + help=_('Set the lower levels for temperature in °C From the MID description: ' + 'Operating Environment of the Airespace Switch. commercial is Commercial (0 to 40 C) ' + 'and industrial is Industrial (-10 to 70 C)'), + elements=[ + Integer(title=_('Warning below'), unit=u'°C', default_value=12, minvalue=-20, maxvalue=100), + Integer(title=_('Critical below'), unit=u'°C', default_value=10, minvalue=-20, maxvalue=100) + ], + ), + ), + ]) + + +rulespec_registry.register( + CheckParameterRulespecWithItem( + check_group_name='cisco_wlc_temp', + group=RulespecGroupCheckParametersNetworking, + match_type='dict', + parameter_valuespec=_parameter_valuespec_cisco_wlc_temp, + title=lambda: _('Cisco WLC Temperature'), + ))