From 115e6153d5ab5ea695c09e94948c55e294ad7765 Mon Sep 17 00:00:00 2001 From: "th.l" <thl-cmk@outlook.com> Date: Tue, 7 Jun 2022 20:27:15 +0200 Subject: [PATCH] update project --- agent_based/juniper_craft_alarm.py | 157 +++++++++++++++++++++++++++++ juniper_craft_alarm.mkp | Bin 0 -> 1924 bytes packages/juniper_craft_alarm | 17 ++++ 3 files changed, 174 insertions(+) create mode 100644 agent_based/juniper_craft_alarm.py create mode 100644 juniper_craft_alarm.mkp create mode 100644 packages/juniper_craft_alarm diff --git a/agent_based/juniper_craft_alarm.py b/agent_based/juniper_craft_alarm.py new file mode 100644 index 0000000..e54504e --- /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 GIT binary patch literal 1924 zcmV-~2YdJ*iwFpSn4e+-|7vw^X>et7Ut@A%W^`X+Y+-V3Eiy1NGB7qUHeYryE-)@J zE^TXY0PR^(Z`(Ey&a;07>paLFY(<hCrxV~}Sy}|?lC<zr41;S3icQ;UWXcn%WJZwx zz9T8wlq@+(x2D^`53OTScgNH5_}z&P$TZsf#;^drZdd#T6#v@Jp}l8!o$k>QeDZM{ z#+*H5?Y#gJ%KR8y`6nJyeYpP!?hQX-^C&i4WUzVI9xrZ&J{v^|3!~^}IEmP394(Ai z4H*+m$8oS^K}5LpMMMG?#pr!Pf+dd8C1!U~d_&R6+^004$PfK^@tGJkRDe-Bcs0jp zJjdf31iIHg#S;_}#9;LOr^~aC?*{GT^W(uq`{L~9ryKq4cyQ^WV2bupG({^MhS423 zhGRz28)TL0oD9ycHaao*@rc5D67j^K5&A2%h$a}3h@mA!14TR#B8br)2_t{vC2`23 zIA?50-GhTP_U1fVvdE0$nUJ0aA*LV(t2D!ec_J)uJ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_fsTX~G`g{ti$BZ3#7*pLB%ZD`0h5|WN|U}T&yc(Iwn$itRR5e&4;p47~23BzEf z25SZ{KQYB#NyVoPb#uESVTa0Ujhd+aW}VQ(Tr@}J;cTVk3%=%vLkX~0$(D$x_zI#@ zXK0OTX{cEelOj`O=Wbh3h6QXC2f-HnYqr)})m)N0*h}+H*i2Q#fMRK#jjE6sC<x_p zR25c+n`;e4xq`PU9p&=7y<7+TQ5U&nxqmhJDRXL)?fi<ol60TnDpaIXfiq+ptpXfQ zGHPpNlZexU@(CcP{RM5I9TO=$Bqs@`nYdX@7xb!+9ORP;l7@%IogWjAM9kwG)r%HJ zn(!NMrRn^t$Tbm6Z1NL{e6(q@Sora(KQ)dEhZHWluVfK(hFPP^@#cde7Y2vWnmyCQ z55K&Of5qsld(o5}@Max&aqUTw%Ajw>nV<4N>VWINXD3Je3DT-@Up?~^;#UZn5~i=1 zs~C&*UatrQKTm&36!__w5`}>{9xHRJFyY^N{%6fnt7VOh$=h)+6_x4956t>yKU~nX zs>vcYO^8tHSJyNtKE-T2?+@1xlyyY;&A@w{zERN*LmvzLxOG<Px?jkj;<!$7P0nBx zOsF#J`lljW8UszCG~oN=0=7p^a#U6ezOUo^{Fj`K^D^Isx=4rZ2X(UP^U^0g3CgW^ z%H+?X0-cBgRHoEXT!Iwb<xfZPCljr7rlUBM30HVBD%8c1T(Jpekk$Q7$KBX05`Syt zpW+2+d+GR1+h~dodA(6&1(Z$t6E_N#Mbwjm*{S?-_JbaGa$URE+i7<>muk|NwMuny zR>k8a#1u2{QMaWyRDB;P#}ga~v5aZ|ejVw2X@FPRR`Hhn@lhS$D&sD?ij(xk=mBD_ zkAgKcG&D3cG&D3cG&D3cG&D3cG&D3cG&D3cG&D3cG&D3cG&D3cG&D3cG&D5+#rO+= K0+(d~PyhhMc&QWs literal 0 HcmV?d00001 diff --git a/packages/juniper_craft_alarm b/packages/juniper_craft_alarm new file mode 100644 index 0000000..5598c7d --- /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 -- GitLab