diff --git a/agent_based/checkpoint_asg_chassis.py b/agent_based/checkpoint_asg_chassis.py new file mode 100644 index 0000000000000000000000000000000000000000..b5f79f863b7e5b8266c14c2b29b2766f4d69eaac --- /dev/null +++ b/agent_based/checkpoint_asg_chassis.py @@ -0,0 +1,215 @@ +#!/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 : 2020-11-08 +# +# Monitor Check Point Maestro SMO Chassis status (asg monitor) +# +# 2021-02-25: rewrite for CMK 2.x +# +# sample snmpwalk +# .1.3.6.1.4.1.2620.1.48.28.1.0 = STRING: "Multi" +# .1.3.6.1.4.1.2620.1.48.28.2.0 = STRING: "Primary Up" +# .1.3.6.1.4.1.2620.1.48.28.3.1.0 = STRING: "Enabled" +# .1.3.6.1.4.1.2620.1.48.28.3.2.0 = STRING: "Enabled" +# .1.3.6.1.4.1.2620.1.48.28.4.1.1.1.0 = Gauge32: 1 +# .1.3.6.1.4.1.2620.1.48.28.4.1.1.2.0 = Gauge32: 2 +# .1.3.6.1.4.1.2620.1.48.28.4.1.2.1.0 = Gauge32: 1 +# .1.3.6.1.4.1.2620.1.48.28.4.1.2.2.0 = Gauge32: 2 +# .1.3.6.1.4.1.2620.1.48.28.4.1.3.1.0 = STRING: "ACTIVE" +# .1.3.6.1.4.1.2620.1.48.28.4.1.3.2.0 = STRING: "STANDBY" +# .1.3.6.1.4.1.2620.1.48.28.4.1.4.1.0 = STRING: "34" +# .1.3.6.1.4.1.2620.1.48.28.4.1.4.2.0 = STRING: "28" +# .1.3.6.1.4.1.2620.1.48.28.4.1.5.1.0 = STRING: "34" +# .1.3.6.1.4.1.2620.1.48.28.4.1.5.2.0 = STRING: "28" +# .1.3.6.1.4.1.2620.1.48.28.4.1.6.1.0 = STRING: "N/A" +# .1.3.6.1.4.1.2620.1.48.28.4.1.6.2.0 = STRING: "N/A" +# .1.3.6.1.4.1.2620.1.48.28.5.1.1.1.0 = Gauge32: 1 +# .1.3.6.1.4.1.2620.1.48.28.5.1.1.2.0 = Gauge32: 2 +# .1.3.6.1.4.1.2620.1.48.28.5.1.1.3.0 = Gauge32: 3 +# .1.3.6.1.4.1.2620.1.48.28.5.1.2.1.0 = STRING: "1_01" +# .1.3.6.1.4.1.2620.1.48.28.5.1.2.2.0 = STRING: "1_02" +# .1.3.6.1.4.1.2620.1.48.28.5.1.2.3.0 = STRING: "2_01" +# .1.3.6.1.4.1.2620.1.48.28.5.1.3.1.0 = STRING: "ACTIVE" +# .1.3.6.1.4.1.2620.1.48.28.5.1.3.2.0 = STRING: "ACTIVE" +# .1.3.6.1.4.1.2620.1.48.28.5.1.3.3.0 = STRING: "ACTIVE" +# .1.3.6.1.4.1.2620.1.48.28.5.1.4.1.0 = STRING: "N/A" +# .1.3.6.1.4.1.2620.1.48.28.5.1.4.2.0 = STRING: "N/A" +# .1.3.6.1.4.1.2620.1.48.28.5.1.4.3.0 = STRING: "N/A" +# .1.3.6.1.4.1.2620.1.48.28.5.1.5.1.0 = STRING: "N/A" +# .1.3.6.1.4.1.2620.1.48.28.5.1.5.2.0 = STRING: "N/A" +# .1.3.6.1.4.1.2620.1.48.28.5.1.5.3.0 = STRING: "N/A" +# +# sample info +# [ +# [ +# [u'Multi', u'Primary Up', u'Enabled', u'Enabled'] +# ], +# [ +# [u'1', u'ACTIVE', u'34', u'34', u'N/A'], +# [u'2', u'STANDBY', u'28', u'28', u'N/A'] +# ], +# [ +# [u'1_01', u'ACTIVE'], +# [u'1_02', u'ACTIVE'], +# [u'2_01', u'ACTIVE'] +# ] +# ] +# +from pprint import pprint + +from typing import Mapping, Dict, List, Tuple, NamedTuple + +from .agent_based_api.v1.type_defs import ( + DiscoveryResult, + CheckResult, + StringTable, +) + +from .agent_based_api.v1 import ( + register, + Service, + equals, + check_levels, + Result, + State, + SNMPTree, + startswith, + all_of, + any_of, +) + + +class CheckPointASGChassisInfo(NamedTuple): + mode: str + hamode: str + synctoactive: str + synctostandby: str + +class CheckPointASGChassisParams(NamedTuple): + id: str + status: str + grade: str + maxgrade: str + uniqueip: str + +class CheckPointASGChassisSgms(NamedTuple): + id: str + status: str + + +class CheckPointASGChassis(NamedTuple): + info: CheckPointASGChassisInfo + chassis: List + sgms: List + + +def parse_checkpoint_asg_chassis(string_table: List[StringTable]): #-> CheckPointASGChassis: + chassis = CheckPointASGChassis + try: + chassis.info = CheckPointASGChassisInfo(*string_table[0][0]) + except TypeError: + return None + chassis.chassis = string_table[1] + chassis.sgms = string_table[2] + + parsed = chassis + return parsed + + +def discovery_checkpoint_asg_chassis(section: CheckPointASGChassis) -> DiscoveryResult: + yield Service(parameters={'inv_chassis_parms': section.chassis}) + + +def check_checkpoint_asg_chassis(params, section: CheckPointASGChassis) -> CheckResult: + + details = '' + details += '\n\nTo verify this output use the "asg monitor" CLI command on the Check Point SMO,\n' + details += '\nChassis Mode: %s' % section.info.mode + details += '\nH/A Mode: %s' % section.info.hamode + details += '\nSync to active: %s' % section.info.synctoactive + details += '\nSync to standby: %s' % section.info.synctostandby + + inv_chassis_parms = params['inv_chassis_parms'] + + for chassis in section.chassis: + chassis = CheckPointASGChassisParams(*chassis) + + if chassis.uniqueip != 'N/A': + details += '\nChassis %s unique IP: %s' % (chassis.id, chassis.uniqueip) + + for inv_chassis in inv_chassis_parms: + inv_chassis = CheckPointASGChassisParams(*inv_chassis) + if chassis.id == inv_chassis.id: + yield_text = 'Chassis %s: %s, grade: %s/%s' % (chassis.id, chassis.status,chassis.grade,chassis.maxgrade) + if not chassis.status.lower() in ['active', 'standby']: + yield Result(state=State.CRIT, summary=yield_text) + elif (chassis.status != inv_chassis.status) or (chassis.grade != inv_chassis.grade) or (chassis.maxgrade != inv_chassis.maxgrade): + yield Result(State.WARNING, notice=yield_text + ' (expected: %s, grade: %s/%s)' % (inv_chassis.status, inv_chassis.grade, inv_chassis.maxgrade)) + else: + yield Result(state=State.OK, summary=yield_text) + + active_sgms = 0 + for asgSgm in section.sgms: + asgSgm = CheckPointASGChassisSgms(*asgSgm) + if asgSgm.status.lower() == 'active': + active_sgms += 1 + else: + yield Result(state=State.CRIT, notice='SGM %s state: %s' % (asgSgm.id, asgSgm.status)) + + yield Result(state=State.OK, + summary='%d/%d SGMs active' % (active_sgms, len(section.sgms)), + details=details) + +register.snmp_section( + name='checkpoint_asg_chassis', + parse_function=parse_checkpoint_asg_chassis, + fetch=[ + SNMPTree( + base='.1.3.6.1.4.1.2620.1.48.28', # CHECKPOINT-MIB::asgChassisInfo + oids=[ + '1', # asgChassisMode + '2', # asgChassisHAMode + '3.1', # asgSyncToActive + '3.2', # asgSyncToStandby + ] + ), + SNMPTree( + base='.1.3.6.1.4.1.2620.1.48.28.4.1', # CHECKPOINT-MIB::asgChassisParamsEntry + oids=[ + '2', # asgChassisParamsID + '3', # asgChassisParamsStatus + '4', # asgChassisParamsGrade + '5', # asgChassisParamsMaxGrade + '6', # asgChassisParamsUniqueIP + ] + ), + SNMPTree( + base='.1.3.6.1.4.1.2620.1.48.28.5.1', # CHECKPOINT-MIB::asgSGMEntry + oids=[ + '2', # asgSGMID + '3', # asgSGMStatus + ] + ), + ], + detect=any_of( + startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.2620'), + all_of( + equals('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.8072.3.2.10'), + equals('.1.3.6.1.4.1.2620.1.6.1.0', 'SVN Foundation'), + ) + ) +) + +register.check_plugin( + name='checkpoint_asg_chassis', + service_name='ASG Chassis', + discovery_function=discovery_checkpoint_asg_chassis, + check_function=check_checkpoint_asg_chassis, + check_default_parameters={}, + check_ruleset_name='checkpoint_asg_chassis', +) diff --git a/checkpoint_asg_chassis.mkp b/checkpoint_asg_chassis.mkp index 14565ef2dc0ed28272a091ec4348e12e15683031..66011fb9cde3dd8299317411a28dd3a8248346c7 100644 Binary files a/checkpoint_asg_chassis.mkp and b/checkpoint_asg_chassis.mkp differ diff --git a/checks/checkpoint_asg_chassis b/checks/checkpoint_asg_chassis deleted file mode 100644 index dc3aad88d7610150be5968f5e347c332dd3b2081..0000000000000000000000000000000000000000 --- a/checks/checkpoint_asg_chassis +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/python -# -*- encoding: utf-8; py-indent-offset: 4 -*- -# -# License: GNU General Public License v2 -# -# Author: thl-cmk[at]outlook[dot]com -# URL : https://thl-cmk.hopto.org -# Date : 2020-11-08 -# -# Monitor Check Point Maestro SMO Chassis status (asg monitor) -# -# sample snmpwalk -# .1.3.6.1.4.1.2620.1.48.28.1.0 = STRING: "Multi" -# .1.3.6.1.4.1.2620.1.48.28.2.0 = STRING: "Primary Up" -# .1.3.6.1.4.1.2620.1.48.28.3.1.0 = STRING: "Enabled" -# .1.3.6.1.4.1.2620.1.48.28.3.2.0 = STRING: "Enabled" -# .1.3.6.1.4.1.2620.1.48.28.4.1.1.1.0 = Gauge32: 1 -# .1.3.6.1.4.1.2620.1.48.28.4.1.1.2.0 = Gauge32: 2 -# .1.3.6.1.4.1.2620.1.48.28.4.1.2.1.0 = Gauge32: 1 -# .1.3.6.1.4.1.2620.1.48.28.4.1.2.2.0 = Gauge32: 2 -# .1.3.6.1.4.1.2620.1.48.28.4.1.3.1.0 = STRING: "ACTIVE" -# .1.3.6.1.4.1.2620.1.48.28.4.1.3.2.0 = STRING: "STANDBY" -# .1.3.6.1.4.1.2620.1.48.28.4.1.4.1.0 = STRING: "34" -# .1.3.6.1.4.1.2620.1.48.28.4.1.4.2.0 = STRING: "28" -# .1.3.6.1.4.1.2620.1.48.28.4.1.5.1.0 = STRING: "34" -# .1.3.6.1.4.1.2620.1.48.28.4.1.5.2.0 = STRING: "28" -# .1.3.6.1.4.1.2620.1.48.28.4.1.6.1.0 = STRING: "N/A" -# .1.3.6.1.4.1.2620.1.48.28.4.1.6.2.0 = STRING: "N/A" -# .1.3.6.1.4.1.2620.1.48.28.5.1.1.1.0 = Gauge32: 1 -# .1.3.6.1.4.1.2620.1.48.28.5.1.1.2.0 = Gauge32: 2 -# .1.3.6.1.4.1.2620.1.48.28.5.1.1.3.0 = Gauge32: 3 -# .1.3.6.1.4.1.2620.1.48.28.5.1.2.1.0 = STRING: "1_01" -# .1.3.6.1.4.1.2620.1.48.28.5.1.2.2.0 = STRING: "1_02" -# .1.3.6.1.4.1.2620.1.48.28.5.1.2.3.0 = STRING: "2_01" -# .1.3.6.1.4.1.2620.1.48.28.5.1.3.1.0 = STRING: "ACTIVE" -# .1.3.6.1.4.1.2620.1.48.28.5.1.3.2.0 = STRING: "ACTIVE" -# .1.3.6.1.4.1.2620.1.48.28.5.1.3.3.0 = STRING: "ACTIVE" -# .1.3.6.1.4.1.2620.1.48.28.5.1.4.1.0 = STRING: "N/A" -# .1.3.6.1.4.1.2620.1.48.28.5.1.4.2.0 = STRING: "N/A" -# .1.3.6.1.4.1.2620.1.48.28.5.1.4.3.0 = STRING: "N/A" -# .1.3.6.1.4.1.2620.1.48.28.5.1.5.1.0 = STRING: "N/A" -# .1.3.6.1.4.1.2620.1.48.28.5.1.5.2.0 = STRING: "N/A" -# .1.3.6.1.4.1.2620.1.48.28.5.1.5.3.0 = STRING: "N/A" -# -# sample info -# [ -# [ -# [u'Multi', u'Primary Up', u'Enabled', u'Enabled'] -# ], -# [ -# [u'1', u'ACTIVE', u'34', u'34', u'N/A'], -# [u'2', u'STANDBY', u'28', u'28', u'N/A'] -# ], -# [ -# [u'1_01', u'ACTIVE'], -# [u'1_02', u'ACTIVE'], -# [u'2_01', u'ACTIVE'] -# ] -# ] -# - -def inventory_checkpoint_asg_chassis(info): - - chassis_info, chassis_params, asgsgms = info - try: - asgChassisMode, asgChassisHAMode, asgSyncToActive, asgSyncToStandby = chassis_info[0] - yield None, {'inv_state': info} - except IndexError: - pass - - -def check_checkpoint_asg_chassis(_no_item, params, info): - chassis_info, chassis_params, asgsgms = info - - asgChassisMode, asgChassisHAMode, asgSyncToActive, asgSyncToStandby = chassis_info[0] - - if params: - inv_chassis_info, inv_chassis_params, inv_asgsgms = params.get('inv_state') - - infotext = '' - longoutput = '' - state = 0 - - longoutput += '\n\nTo verify this output use the "asg monitor" CLI command on the Check Point SMO,\n' - longoutput += '\nChassis Mode: %s' % asgChassisMode - longoutput += '\nH/A Mode: %s' % asgChassisHAMode - longoutput += '\nSync to active: %s' % asgSyncToActive - longoutput += '\nSync to standby: %s' % asgSyncToStandby - - for chassis in chassis_params: - asgChassisParamsID, asgChassisParamsStatus, asgChassisParamsGrade, asgChassisParamsMaxGrade, asgChassisParamsUniqueIP = chassis - - if asgChassisParamsUniqueIP != 'N/A': - longoutput += '\nChassis %s unique IP: %s' % (asgChassisParamsID, asgChassisParamsUniqueIP) - - for inv_chassis in inv_chassis_params: - inv_asgChassisParamsID, inv_asgChassisParamsStatus, inv_asgChassisParamsGrade, inv_asgChassisParamsMaxGrade, inv_asgChassisParamsUniqueIP = inv_chassis - if asgChassisParamsID == inv_asgChassisParamsID: - yield_text = 'Chassis %s: %s, grade: %s/%s' % (asgChassisParamsID, asgChassisParamsStatus, asgChassisParamsGrade, asgChassisParamsMaxGrade) - if not asgChassisParamsStatus.lower() in ['active', 'standby']: - yield 2, yield_text - elif (asgChassisParamsStatus != inv_asgChassisParamsStatus) or (asgChassisParamsGrade != inv_asgChassisParamsGrade) or (asgChassisParamsMaxGrade != inv_asgChassisParamsMaxGrade): - yield 1, yield_text + ' (expected: %s, grade: %s/%s)' % (inv_asgChassisParamsStatus, asgChassisParamsGrade, asgChassisParamsMaxGrade) - else: - yield 0, yield_text - - active_sgms = 0 - for asgSgm in asgsgms: - asgSGMID, asgSGMStatus = asgSgm - if asgSGMStatus == 'ACTIVE': - active_sgms += 1 - else: - yield 2, 'SGM %s state: %s' % (asgSGMID, asgSGMStatus) - - yield 0, '%d/%d SGMs active' % (active_sgms, len(asgsgms)) - - yield state, infotext + longoutput + '\n' - - -check_info['checkpoint_asg_chassis'] = { - 'check_function': check_checkpoint_asg_chassis, - 'inventory_function': inventory_checkpoint_asg_chassis, - 'service_description': "ASG Chassis", - 'snmp_scan_function': scan_checkpoint, - 'group': 'checkpoint_asg_chassis', - 'snmp_info': [( - '.1.3.6.1.4.1.2620.1.48.28', # CHECKPOINT-MIB::asgChassisInfo - [ - '1', # asgChassisMode - '2', # asgChassisHAMode - '3.1', # asgSyncToActive - '3.2', # asgSyncToStandby - ]), - ('.1.3.6.1.4.1.2620.1.48.28.4.1', # CHECKPOINT-MIB::asgChassisParamsEntry - [ - '2', # asgChassisParamsID - '3', # asgChassisParamsStatus - '4', # asgChassisParamsGrade - '5', # asgChassisParamsMaxGrade - '6', # asgChassisParamsUniqueIP - ]), - ('.1.3.6.1.4.1.2620.1.48.28.5.1', # CHECKPOINT-MIB::asgSGMEntry - [ - '2', # asgSGMID - '3', # asgSGMStatus - ] - ) - ], - 'includes': ['checkpoint.include'], -} \ No newline at end of file diff --git a/packages/checkpoint_asg_chassis b/packages/checkpoint_asg_chassis index 06d8f23af7cdbf56c05633af4c65299253808238..789bde6a5540447e87f6d3ff748298718e560388 100644 --- a/packages/checkpoint_asg_chassis +++ b/packages/checkpoint_asg_chassis @@ -1,11 +1,12 @@ -{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)', - 'description': u'Monitor Check Point Maestro SMO Chassis status (asg monitor)', +{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', + 'description': 'Monitor Check Point Maestro SMO Chassis status (asg ' + 'monitor)\n', 'download_url': 'http://thl-cmk.hopto.org/', - 'files': {'checks': ['checkpoint_asg_chassis']}, + 'files': {'agent_based': ['checkpoint_asg_chassis.py']}, 'name': 'checkpoint_asg_chassis', 'num_files': 1, - 'title': u'Check Point Maestro SMO ASG Chassis', - 'version': '20201107.v0.1', - 'version.min_required': '1.4.0p38', - 'version.packaged': '1.6.0p15', + 'title': 'Check Point Maestro SMO ASG Chassis', + 'version': '20210225.v0.2', + 'version.min_required': '2.0.0i1', + 'version.packaged': '2020.11.27', 'version.usable_until': None} \ No newline at end of file