diff --git a/agent_based/checkpoint_inv_base.py b/agent_based/checkpoint_inv_base.py new file mode 100644 index 0000000000000000000000000000000000000000..b74bd143c2350006f13e58337cbd24c0efd79b31 --- /dev/null +++ b/agent_based/checkpoint_inv_base.py @@ -0,0 +1,138 @@ +#!/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 +# +# 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 ( + StringTable, + InventoryResult, +) +from .agent_based_api.v1 import ( + Attributes, + register, + SNMPTree, + startswith, + all_of, + any_of, + equals, +) + + +def parse_checkpoint_inv_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]) + updateagentversion = string_table[1][0][0] + + 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 inventory_checkpoint_base(section: List) -> InventoryResult: + class invEntry(NamedTuple): + invPath: list + key: str + value: str + + for entry in section: + entry = invEntry(*entry) + yield Attributes( + path=entry.invPath, + inventory_attributes={entry.key: entry.value}) + + +register.snmp_section( + name='checkpoint_inv_base', + parse_function=parse_checkpoint_inv_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='checkpoint_inv_base', + inventory_function=inventory_checkpoint_base, +) \ No newline at end of file diff --git a/inv_checkpoint_base.mkp b/inv_checkpoint_base.mkp index 20dc6690b5c35e7394492bc968a322f68a4438f0..d82c8c554090a0e1d8604bacee9a94afc98f4efe 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 09079b2a3d188b4da7e1bb9974cacb487ae8efa8..99eaf06ac7d4628e98565365bf3ab87bf496084c 100644 --- a/packages/inv_checkpoint_base +++ b/packages/inv_checkpoint_base @@ -6,7 +6,7 @@ '- 2021-02-08: initial release\n' '- 2021-02-22: code cleanup\n', 'download_url': 'https://thl-cmk.hopto.org', - 'files': {'lib': ['python3/cmk/base/plugins/agent_based/checkpoint_inv_base.py'], + 'files': {'agent_based': ['checkpoint_inv_base.py'], 'web': ['plugins/views/checkpoint_base.py']}, 'name': 'inv_checkpoint_base', 'num_files': 2,