diff --git a/agent_based/checkpoint_asg_interface.py b/agent_based/checkpoint_asg_interface.py new file mode 100644 index 0000000000000000000000000000000000000000..608fa25b7adf7e9ac54e6e9eb5e6e815758a1a7c --- /dev/null +++ b/agent_based/checkpoint_asg_interface.py @@ -0,0 +1,229 @@ +#!/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-09 +# +# Monitor Check Point Maestro SMO interfaces +# +# 2021-03-03: rewrite for CMK 2.0 +# +# sample snmpwalk (for one interface) +# .1.3.6.1.4.1.2620.1.48.26.1.1.1.4.0 = Gauge32: 4 +# .1.3.6.1.4.1.2620.1.48.26.1.1.2.4.0 = STRING: "bond2.602" +# .1.3.6.1.4.1.2620.1.48.26.1.1.3.4.0 = STRING: "10.9.9.1/25" +# .1.3.6.1.4.1.2620.1.48.26.1.1.4.4.0 = STRING: "-" +# .1.3.6.1.4.1.2620.1.48.26.1.1.5.4.0 = STRING: "00:1c:7f:81:05:09" +# .1.3.6.1.4.1.2620.1.48.26.1.1.6.4.0 = STRING: "Vlan" +# .1.3.6.1.4.1.2620.1.48.26.1.1.7.4.0 = STRING: "(up)/(up)" +# .1.3.6.1.4.1.2620.1.48.26.1.1.8.4.0 = STRING: "NA" +# .1.3.6.1.4.1.2620.1.48.26.1.1.9.4.0 = STRING: "1500" +# .1.3.6.1.4.1.2620.1.48.26.1.1.10.4.0 = STRING: "Full" +# .1.3.6.1.4.1.2620.1.48.26.1.1.11.4.0 = STRING: "355320533" +# .1.3.6.1.4.1.2620.1.48.26.1.1.12.4.0 = STRING: "4673143507" +# +# sample section +# [ +# [u'bond2', u'-', u'-', u'00:1c:7f:81:05:09', u'Bond Master', u'(up)/(up)', u'20G', u'NA', u'Full', u'3373103274', u'5007776301'], +# [u'eth1-05', u'-', u'-', u'00:1c:7f:81:05:09', u'Bond slave', u'(up)/(up)', u'10G', u'1500', u'Full', u'1014183605', u'3291515315'], +# [u'eth2-05', u'-', u'-', u'00:1c:7f:81:05:09', u'Bond slave', u'(up)/(up)', u'10G', u'1500', u'Full', u'2358951560', u'1716293763'], +# [u'bond2.602', u'10.9.9.1/25', u'-', u'00:1c:7f:81:05:09', u'Vlan', u'(up)/(up)', u'NA', u'1500', u'Full', u'355320533', u'4673143507'], +# [u'bond2.3001', u'10.0.100.49/27', u'-', u'00:1c:7f:81:05:09', u'Vlan', u'(up)/(up)', u'NA', u'1500', u'Full', u'2910413426', u'229216384'], +# [u'bond3', u'-', u'-', u'00:1c:7f:81:06:09', u'Bond Master', u'(up)/(up)', u'20G', u'NA', u'Full', u'1479928728', u'133617791'], +# [u'eth1-06', u'-', u'-', u'00:1c:7f:81:06:09', u'Bond slave', u'(up)/(up)', u'10G', u'1500', u'Full', u'214459394', u'131774843'], +# [u'eth2-06', u'-', u'-', u'00:1c:7f:81:06:09', u'Bond slave', u'(up)/(up)', u'10G', u'1500', u'Full', u'1265469477', u'1843158'], +# [u'magg1', u'10.0.100.9/27', u'-', u'00:1c:7f:6e:9b:dc', u'Bond Master', u'(up)/(up)', u'20G', u'NA', u'Full', u'200631796', u'384654797'], +# [u'eth1-Mgmt1', u'-', u'-', u'00:1c:7f:6e:9b:dc', u'Bond slave', u'(Up)/(Up)', u'10G', u'1500', u'Full', u'61520991', u'44776128'], +# [u'eth2-Mgmt1', u'-', u'-', u'00:1c:7f:6e:9b:dc', u'Bond slave', u'(Up)/(Up)', u'10G', u'1500', u'Full', u'139110651', u'339878254'], +# [u'Sync', u'192.0.2.1/24', u'-', u'00:1c:7f:01:04:fe', u'Bond Master', u'(up)/(up)', u'20G', u'NA', u'Full', u'24549684703', u'14214325659'], +# [u'eth1-Sync', u'-', u'-', u'00:1c:7f:01:04:fe', u'Bond slave', u'(down)/(down)', u'10G', u'1500', u'Full', u'1228171', u'1511513'], +# [u'eth2-Sync', u'-', u'-', u'00:1c:7f:01:04:fe', u'Bond slave', u'(up)/(up)', u'10G', u'1500', u'Full', u'24548432877', u'14212801896'] +# ] +# + +import time + +from typing import Mapping, Dict, List, Tuple, NamedTuple + +from .agent_based_api.v1.type_defs import ( + DiscoveryResult, + StringTable, + CheckResult, +) + +from .agent_based_api.v1 import ( + register, + Service, + equals, + Result, + check_levels, + State, + SNMPTree, + startswith, + all_of, + any_of, + + GetRateError, + get_rate, + get_value_store, + IgnoreResults, + render, +) + + +class CheckPointASGInterface(NamedTuple): + asgNetIfIPv4Addr: str + asgNetIfIPv6Addr: str + asgNetIfMACAddr: str + asgNetIfInfo: str + asgNetIfState: str + asgNetIfSpeed: str + asgNetIfMTU: str + asgNetIfDuplex: str + asgNetIfRx: int + asgNetIfTx: int + + +def parse_checkpoint_asg_interface(string_table: List[StringTable]) -> Dict: + parsed = {} + for entry in string_table[0]: + asgNetIfName, asgNetIfIPv4Addr, asgNetIfIPv6Addr, asgNetIfMACAddr, asgNetIfInfo, asgNetIfState, asgNetIfSpeed, asgNetIfMTU, asgNetIfDuplex, asgNetIfRx, asgNetIfTx = entry + # if not asgNetIfIPv4Addr == asgNetIfIPv6Addr == '-': # do not add interfaces without ip address + item = '%s' % (asgNetIfName) + parsed.update({item: CheckPointASGInterface( + asgNetIfIPv4Addr, + asgNetIfIPv6Addr, + asgNetIfMACAddr, + asgNetIfInfo, + asgNetIfState, + asgNetIfSpeed, + asgNetIfMTU, + asgNetIfDuplex, + int(asgNetIfRx), + int(asgNetIfTx) + )}) + + return parsed + + +def discovery_checkpoint_asg_interface(section: Dict) -> DiscoveryResult: + # sample section + # + # { + # 'bond2': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:05:09', asgNetIfInfo='Bond Master', asgNetIfState='(up)/(up)', asgNetIfSpeed='20G', asgNetIfMTU='NA', asgNetIfDuplex='Full', asgNetIfRx=3373103274, asgNetIfTx=5007776301), + # 'eth1-05': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:05:09', asgNetIfInfo='Bond slave', asgNetIfState='(up)/(up)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=1014183605, asgNetIfTx=3291515315), + # 'eth2-05': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:05:09', asgNetIfInfo='Bond slave', asgNetIfState='(up)/(up)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=2358951560, asgNetIfTx=1716293763), + # 'bond2.602': CheckPointASGInterface(asgNetIfIPv4Addr='10.9.9.1/25', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:05:09', asgNetIfInfo='Vlan', asgNetIfState='(up)/(up)', asgNetIfSpeed='NA', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=355320533, asgNetIfTx=4673143507), + # 'bond2.3001': CheckPointASGInterface(asgNetIfIPv4Addr='10.0.100.49/27', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:05:09', asgNetIfInfo='Vlan', asgNetIfState='(up)/(up)', asgNetIfSpeed='NA', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=2910413426, asgNetIfTx=229216384), + # 'bond3': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:06:09', asgNetIfInfo='Bond Master', asgNetIfState='(up)/(up)', asgNetIfSpeed='20G', asgNetIfMTU='NA', asgNetIfDuplex='Full', asgNetIfRx=1479928728, asgNetIfTx=133617791), + # 'eth1-06': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:06:09', asgNetIfInfo='Bond slave', asgNetIfState='(up)/(up)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=214459394, asgNetIfTx=131774843), + # 'eth2-06': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:06:09', asgNetIfInfo='Bond slave', asgNetIfState='(up)/(up)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=1265469477, asgNetIfTx=1843158), + # 'bond3.998': CheckPointASGInterface(asgNetIfIPv4Addr='xx.yy.zz.129/28', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:81:06:09', asgNetIfInfo='Vlan', asgNetIfState='(up)/(up)', asgNetIfSpeed='NA', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=1470381718, asgNetIfTx=124676073), + # 'magg1': CheckPointASGInterface(asgNetIfIPv4Addr='10.0.100.9/27', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:6e:9b:dc', asgNetIfInfo='Bond Master', asgNetIfState='(up)/(up)', asgNetIfSpeed='20G', asgNetIfMTU='NA', asgNetIfDuplex='Full', asgNetIfRx=200631796, asgNetIfTx=384654797), + # 'eth1-Mgmt1': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:6e:9b:dc', asgNetIfInfo='Bond slave', asgNetIfState='(Up)/(Up)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=61520991, asgNetIfTx=44776128), + # 'eth2-Mgmt1': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:6e:9b:dc', asgNetIfInfo='Bond slave', asgNetIfState='(Up)/(Up)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=139110651, asgNetIfTx=339878254), + # 'Sync': CheckPointASGInterface(asgNetIfIPv4Addr='192.0.2.1/24', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:01:04:fe', asgNetIfInfo='Bond Master', asgNetIfState='(up)/(up)', asgNetIfSpeed='20G', asgNetIfMTU='NA', asgNetIfDuplex='Full', asgNetIfRx=24549684703, asgNetIfTx=14214325659), + # 'eth1-Sync': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:01:04:fe', asgNetIfInfo='Bond slave', asgNetIfState='(down)/(down)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=1228171, asgNetIfTx=1511513), + # 'eth2-Sync': CheckPointASGInterface(asgNetIfIPv4Addr='-', asgNetIfIPv6Addr='-', asgNetIfMACAddr='00:1c:7f:01:04:fe', asgNetIfInfo='Bond slave', asgNetIfState='(up)/(up)', asgNetIfSpeed='10G', asgNetIfMTU='1500', asgNetIfDuplex='Full', asgNetIfRx=24548432877, asgNetIfTx=14212801896) + # } + # + for item in section.keys(): + yield Service(item=item, parameters={'asgNetIfSpeed': section[item].asgNetIfSpeed}) + + +def check_checkpoint_asg_interface(item, params, section: Dict) -> CheckResult: + try: + asg_interface = section[item] + + inv_asgNetIfSpeed = params['asgNetIfSpeed'] + + now = time.time() + value_store = get_value_store() + + try: + in_rate = get_rate(value_store, 'in', now, asg_interface.asgNetIfRx, raise_overflow=True, ) + except GetRateError as exc: + yield IgnoreResults(str(exc)) + else: + yield from check_levels(in_rate, metric_name='if_in_octets', render_func=render.iobandwidth, label='In', ) + + out_rate = get_rate(value_store, 'out', now, asg_interface.asgNetIfTx, raise_overflow=True, ) + yield from check_levels(out_rate, metric_name='if_out_octets', render_func=render.iobandwidth, label='Out', ) + + details = '' + details += '\nIPv4 Address: %s' % asg_interface.asgNetIfIPv4Addr + details += '\nIPv6 Address: %s' % asg_interface.asgNetIfIPv6Addr + details += '\nMAC Address: %s' % asg_interface.asgNetIfMACAddr + details += '\nType: %s' % asg_interface.asgNetIfInfo + details += '\nMTU: %s' % asg_interface.asgNetIfMTU + details += '\nDuplex: %s' % asg_interface.asgNetIfDuplex + + if not asg_interface.asgNetIfIPv4Addr == '-': + summary = 'IPv4: %s' % asg_interface.asgNetIfIPv4Addr + else: + summary = 'IPv4: N/A' + + yield Result(state=State.OK, summary=summary, details=details) + + yield_text = 'State: %s' % asg_interface.asgNetIfState + if not asg_interface.asgNetIfState.lower() == '(up)/(up)': + yield Result(state=State.CRIT, summary=yield_text) + else: + yield Result(state=State.OK, summary=yield_text) + + if not asg_interface.asgNetIfSpeed == inv_asgNetIfSpeed: + yield Result(state=State.WARN, + summary='Speed: %s (%s expected)' % (asg_interface.asgNetIfSpeed, inv_asgNetIfSpeed)) + elif not asg_interface.asgNetIfSpeed == 'NA': + yield Result(state=State.OK, summary='Speed %s' % asg_interface.asgNetIfSpeed) + + if not asg_interface.asgNetIfDuplex.lower(): + yield Result(state=State.CRIT, summary='Duplex: %s (Full expected)' % asg_interface.asgNetIfDuplex) + else: + yield Result(state=State.OK, summary='Duplex: %s' % asg_interface.asgNetIfDuplex) + + except KeyError: + pass + + +register.snmp_section( + name='checkpoint_asg_interface', + parse_function=parse_checkpoint_asg_interface, + fetch=[ + SNMPTree( + base='.1.3.6.1.4.1.2620.1.48.26.1.1', # CHECKPOINT-MIB::asgResourceEntry + oids=[ + '2', # asgNetIfName + '3', # asgNetIfIPv4Addr + '4', # asgNetIfIPv6Addr + '5', # asgNetIfMACAddr + '6', # asgNetIfInfo + '7', # asgNetIfState + '8', # asgNetIfSpeed + '9', # asgNetIfMTU + '10', # asgNetIfDuplex + '11', # asgNetIfRx + '12', # asgNetIfTx + ] + ), + ], + 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_interface', + service_name='ASG Interface %s', + discovery_function=discovery_checkpoint_asg_interface, + check_function=check_checkpoint_asg_interface, + check_default_parameters={}, + check_ruleset_name='checkpoint_asg_interface', +) \ No newline at end of file diff --git a/checkpoint_asg_interface.mkp b/checkpoint_asg_interface.mkp index fc044c52edd2f72996f24411e33c5e2fc1e587c9..de8c1f9e220cab6e66723cc490fc2364ae0359bf 100644 Binary files a/checkpoint_asg_interface.mkp and b/checkpoint_asg_interface.mkp differ diff --git a/packages/checkpoint_asg_interface b/packages/checkpoint_asg_interface index 798bd81a462b07345f846a49fa41b62bf3c1ebd1..4319d094378903cbf603b71f5534b2b0c74384b8 100644 --- a/packages/checkpoint_asg_interface +++ b/packages/checkpoint_asg_interface @@ -1,11 +1,13 @@ -{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)', - 'description': u'Monitor Check Point Maestro SMO interfaces', +{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', + 'description': 'Monitor Check Point Maestro SMO interfaces\n' + '\n' + ' - 2021-03-03: rewrite for CMK 2.x\n', 'download_url': 'http://thl-cmk.hopto.org/', - 'files': {'checks': ['checkpoint_asg_interface']}, + 'files': {'agent_based': ['checkpoint_asg_interface.py']}, 'name': 'checkpoint_asg_interface', 'num_files': 1, - 'title': u'Check Point Maestro SMO interfaces', + 'title': 'Check Point Maestro SMO interfaces', 'version': '20201109.v0.1', - 'version.min_required': '1.4.0p38', - 'version.packaged': '1.6.0p15', + 'version.min_required': '2.0.0i1', + 'version.packaged': '2.0.0b7', 'version.usable_until': None} \ No newline at end of file