diff --git a/agent_based/inv_checkpoint_base.py b/agent_based/inv_checkpoint_base.py new file mode 100644 index 0000000000000000000000000000000000000000..9f65fb4f7bee28f4a7005e5b28a054fcb3474f63 --- /dev/null +++ b/agent_based/inv_checkpoint_base.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Author: thl-cmk[at]outlook[dot]com / thl-cmk.hopto.org +# +# Check Point base inventory +# +# 2016-06-29 : inventory Check Point Appliance +# 2018-03-05 : added Patches, Deployment Agent Build +# 2018-03-07 : added Licenses +# 2020-06-01 : cleanup, prepared for cmk1.7x, rename from inv_checkpoint_svn to checkpoint_inv_base +# 2020-11-27 : rewrite for CMK check API 1.0 (CMK 2.0) +# 2020-11-28 : added available updates +# 2021-02-08 : transfered license/support info to seperate plugin +# 2021-02-22 : code cleanup +# 2021-03-05 : added hostlabel section +# 2021-03-18 : fixed missing update agent snmp section.. +# +# sample string_table +# [ +# [ +# ['5M7C043', 'Smart-1 5150', 'CheckPoint', 'Smart-1', 'R80.40', '994000022', 'Gaia', '3', '10'] +# ], +# [ +# ['1959'] +# ], +# ] +# + +from typing import List, NamedTuple + +from .agent_based_api.v1.type_defs import ( + HostLabelGenerator, + StringTable, + InventoryResult, +) +from .agent_based_api.v1 import ( + Attributes, + HostLabel, + register, + SNMPTree, + startswith, + all_of, + any_of, + equals, +) + + +def parse_inv_checkpoint_base(string_table: List[StringTable]) -> List: + class CheckpointInvBaseInfo(NamedTuple): + serialnumber: str + productname: str + manufacturer: str + series: str + version: str + build: str + osname: str + osmajorver: str + osminorver: str + + section = [] + baseinfo = CheckpointInvBaseInfo(*string_table[0][0]) + + try: + updateagentversion = string_table[1][0][0] + except IndexError: + updateagentversion = '' + + invPath = ['hardware', 'system'] + + if not baseinfo.serialnumber == '': + section.append((invPath, 'serial', baseinfo.serialnumber)) + if not baseinfo.series == '': + section.append((invPath, 'appliance_series', baseinfo.series)) + if not baseinfo.manufacturer == '': + section.append((invPath, 'manufacturer', baseinfo.manufacturer)) + if not baseinfo.productname == '': + section.append((invPath, 'product_name', baseinfo.productname)) + + invPath = ['software', 'check_point', 'os_info'] + + if not baseinfo.version == '': + section.append((invPath, 'svn_version', baseinfo.version)) + if not baseinfo.build == '': + section.append((invPath, 'svn_build', baseinfo.build)) + if not baseinfo.osname == '': + section.append((invPath, 'os_name', baseinfo.osname)) + if not baseinfo.osmajorver == '' and not baseinfo.osminorver == '': + section.append((invPath, 'os_version', baseinfo.osmajorver + '.' + baseinfo.osminorver)) + if not updateagentversion == '': + section.append((invPath, 'deployment_agent_build', updateagentversion)) + + return section + + +def host_label_inv_checkpoint_base(section: List) -> HostLabelGenerator: + for invPath, key, value in section: + if key == 'appliance_series' and value.lower() == 'maestro': + yield HostLabel('checkpoint/device_type', 'maestro') + + +def inventory_checkpoint_base(section: List) -> InventoryResult: + for invPath, key, value in section: + yield Attributes( + path=invPath, + inventory_attributes={key: value}) + + +register.snmp_section( + name='inv_checkpoint_base', + parse_function=parse_inv_checkpoint_base, + host_label_function=host_label_inv_checkpoint_base, + fetch=[ + SNMPTree( + base='.1.3.6.1.4.1.2620.1.6', # CHECKPOINT-MIB::svn + oids=[ + '16.3', # svnApplianceSerialNumber + '16.7', # svnApplianceProductName + '16.9', # svnApplianceManufacturer + '16.10', # svnApplianceSeries + '4.1', # svnVersion + '4.2', # svnBuild + '5.1', # osName + '5.2', # osMajorVer + '5.3', # osMinorVer + ] + ), + SNMPTree( + base='.1.3.6.1.4.1.2620.1.6.20', # CHECKPOINT-MIB::svnUpdatesInfo + oids=[ + '1', # svnUpdatesInfoBuild + ] + ), + ], + detect=any_of( + startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.2620'), # sysObjectID == CheckPoint + all_of( + equals('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.8072.3.2.10'), # sysObjectID == Linux + equals('.1.3.6.1.4.1.2620.1.6.1.0', 'SVN Foundation'), # CheckPoint software installed + ) + ) +) + +register.inventory_plugin( + name='inv_checkpoint_base', + inventory_function=inventory_checkpoint_base, +) diff --git a/inv_checkpoint_base.mkp b/inv_checkpoint_base.mkp index 25c2a98c2cac6e136fdc883909577201f19d1cc9..944c89ad80805677dd9f14db7ca37830322887a5 100644 Binary files a/inv_checkpoint_base.mkp and b/inv_checkpoint_base.mkp differ diff --git a/packages/inv_checkpoint_base b/packages/inv_checkpoint_base index ad628da826bce0dcc6bef642d1d56c9d26146a60..aee6760c0d68e96404fbd01b0ca38a4b149db5d4 100644 --- a/packages/inv_checkpoint_base +++ b/packages/inv_checkpoint_base @@ -6,12 +6,12 @@ '- 2021-02-08: initial release\n' '- 2021-02-22: code cleanup\n', 'download_url': 'https://thl-cmk.hopto.org', - 'files': {'agent_based': ['checkpoint_inv_base.py'], - 'web': ['plugins/views/checkpoint_base.py']}, + 'files': {'agent_based': ['inv_checkpoint_base.py'], + 'web': ['plugins/views/inv_checkpoint_base.py']}, 'name': 'inv_checkpoint_base', 'num_files': 2, 'title': 'Check Point appliance base inventory plugin', - 'version': '20210222.v.0.1', + 'version': '20210318.v.0.1a', 'version.min_required': '2.0.0b8', 'version.packaged': '2.0.0', 'version.usable_until': None} \ No newline at end of file diff --git a/web/plugins/views/inv_checkpoint_base.py b/web/plugins/views/inv_checkpoint_base.py new file mode 100644 index 0000000000000000000000000000000000000000..0507d2134d8ac9a1d80fc108e72e7eb359853543 --- /dev/null +++ b/web/plugins/views/inv_checkpoint_base.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import cmk.gui.utils +from cmk.gui.plugins.views import ( + inventory_displayhints,) +from cmk.gui.i18n import _ + +inventory_displayhints.update({ + '.software.check_point.os_info:': { + 'title': _('OS info'), + }, + })