diff --git a/agent_based/juniper_craft_alarm.py b/agent_based/juniper_craft_alarm.py new file mode 100644 index 0000000000000000000000000000000000000000..e54504e4af1dda44c883e06fb799991d0c8579ed --- /dev/null +++ b/agent_based/juniper_craft_alarm.py @@ -0,0 +1,157 @@ +#!/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-08-01 +# +# monitor Juniper Networks craft alarms +# +# sample snmpwalk +# .1.3.6.1.4.1.2636.3.4.2.1.0 = INTEGER: 2 +# .1.3.6.1.4.1.2636.3.4.2.2.1.0 = INTEGER: 2 +# .1.3.6.1.4.1.2636.3.4.2.2.2.0 = Gauge32: 0 +# .1.3.6.1.4.1.2636.3.4.2.2.3.0 = 0 +# .1.3.6.1.4.1.2636.3.4.2.3.1.0 = INTEGER: 2 +# .1.3.6.1.4.1.2636.3.4.2.3.2.0 = Gauge32: 0 +# .1.3.6.1.4.1.2636.3.4.2.3.3.0 = 0 +# +# sample string_table +# [[['2']], [['2', '0', '0', '2', '0', '0']]] +# +# sample section +# JuniperAlarms( +# alarm_relay_mode=2, +# yellow_alarm=JuniperAlarm(state=2, count=0, last_change=0), +# red_alarm=JuniperAlarm(state=2, count=0, last_change=0) +# ) +# + +from dataclasses import dataclass +from typing import Optional, List + +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( + register, + Service, + Result, + State, + SNMPTree, + startswith, +) +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( + DiscoveryResult, + CheckResult, + StringTable, +) + + +@dataclass +class JuniperAlarm: + # state: int + count: int + # last_change: int + + +@dataclass +class JuniperAlarms: + alarm_relay_mode: int + yellow_alarm: JuniperAlarm + red_alarm: JuniperAlarm + + +_juniper_alarm_relay_mode= { + 1: 'other', + 2: 'pass on', + 3: 'cut off', +} + +_juniper_alarm_state = { + 1: 'other', + 2: 'off', + 3: 'on', +} + + +def parse_juniper_craft_alarms(string_table: List[StringTable]) -> Optional[JuniperAlarms]: + alarm_relay_mode, alarms = string_table + yellow_count, red_count = alarms[0] + + return JuniperAlarms( + alarm_relay_mode=int(alarm_relay_mode[0][0]), + yellow_alarm=JuniperAlarm( + # state=int(yellow_state), + count=int(yellow_count), + # last_change=int(yellow_last_change) + ), + red_alarm=JuniperAlarm( + # state=int(red_state), + count=int(red_count), + # last_change=int(red_last_change) + ) + ) + + +def discovery_juniper_craft_alarms(section: JuniperAlarms) -> DiscoveryResult: + yield Service() + + +def check_juniper_craft_alarms(params, section: JuniperAlarms) -> CheckResult: + if section.alarm_relay_mode != 2 and params['warn_not_pass_om']: + yield Result( + state=State.WARN, + summary=f'Alarm relay mode: {_juniper_alarm_relay_mode.get(section.alarm_relay_mode)}') + else: + yield Result( + state=State.OK, + summary=f'Alarm relay mode: {_juniper_alarm_relay_mode.get(section.alarm_relay_mode)}') + + if section.yellow_alarm.count > params['count_yellow']: + yield Result(state=State.WARN, notice=f'Yellow alarm count: {section.yellow_alarm.count}') + else: + yield Result(state=State.OK, summary=f'Yellow alarm count: {section.yellow_alarm.count}') + + if section.red_alarm.count > params['count_red']: + yield Result(state=State.CRIT, notice=f'Red alarm count: {section.red_alarm.count}') + else: + yield Result(state=State.OK, summary=f'Red alarm count: {section.red_alarm.count}') + + +register.snmp_section( + name='juniper_craft_alarms', + parse_function=parse_juniper_craft_alarms, + fetch=[ + SNMPTree( + base='.1.3.6.1.4.1.2636.3.4.2', # JUNIPER-ALARM-MIB::jnxCraftAlarms + oids=[ + '1', # jnxAlarmRelayMode + ] + ), + SNMPTree( + base='.1.3.6.1.4.1.2636.3.4.2', # JUNIPER-ALARM-MIB::jnxCraftAlarms + oids=[ + # '2.1', # jnxYellowAlarmState + '2.2', # jnxYellowAlarmCount + # '2.3', # jnxYellowAlarmLastChange + # '3.1', # jnxRedAlarmState + '3.2', # jnxRedAlarmCount + # '3.3', # jnxRedAlarmLastChange + ] + ) + ], + detect=startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.2636.1.1.1'), +) + +register.check_plugin( + name='juniper_craft_alarms', + service_name='Chassis Alarm', + discovery_function=discovery_juniper_craft_alarms, + check_function=check_juniper_craft_alarms, + check_ruleset_name='juniper_craft_alarms', + check_default_parameters={ + 'count_yellow': 0, + 'count_red': 0, + 'warn_not_pass_om': True, + } +) diff --git a/juniper_craft_alarm.mkp b/juniper_craft_alarm.mkp new file mode 100644 index 0000000000000000000000000000000000000000..e30c667735b09bb55df4b51d5cc1a60842822f44 Binary files /dev/null and b/juniper_craft_alarm.mkp differ diff --git a/packages/juniper_craft_alarm b/packages/juniper_craft_alarm new file mode 100644 index 0000000000000000000000000000000000000000..5598c7d0e7d295363462ec4cdb1e96de6b3e4864 --- /dev/null +++ b/packages/juniper_craft_alarm @@ -0,0 +1,17 @@ +{'author': 'thl-cmk[at]outlook[dot]com', + 'description': 'Monitor Juniper Networks Chassis alarm\n' + '\n' + 'The check is based on the JUNIPER-ALARM-MIB\n' + '\n' + 'WARN: if # of yellow alerts > 0\n' + 'CRIT: if # of red alerts > 0\n' + 'WARN: if alarm relay mode not pass om\n', + 'download_url': 'https://thl-cmk.hopto.org', + 'files': {'agent_based': ['juniper_craft_alarm.py']}, + 'name': 'juniper_craft_alarm', + 'num_files': 1, + 'title': 'Juniper (Craft) alarm', + 'version': '20220606_v0.0.1', + 'version.min_required': '2.0.0', + 'version.packaged': '2021.09.20', + 'version.usable_until': None} \ No newline at end of file