diff --git a/CHANGELOG b/CHANGELOG index 7a57d2d83a8b374991432eb6dab618a7773c55ba..da63ee0c515c6523aacbf38fc285df531c72be72 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,3 +13,4 @@ 2021-03-18: fixed missing update agent snmp section. 2021-07-24: fixed parse function for empty string_table 2021-08-10: added display hints +2023-04-23: refactoring, moved views file to ~/local/lib/check_mk/gui/plugins/views diff --git a/agent_based/inv_checkpoint_base.py b/agent_based/inv_checkpoint_base.py index 54e1713ba36bd9e40ee5218b512274427bea4d22..809623f7b834c600c25270eba78d69e61b095908 100644 --- a/agent_based/inv_checkpoint_base.py +++ b/agent_based/inv_checkpoint_base.py @@ -1,7 +1,11 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# -# Author: thl-cmk[at]outlook[dot]com / thl-cmk.hopto.org + +# License: GNU General Public License v2 + +# Author: thl-cmk[at]outlook[dot]com +# URL : https://thl-cmk.hopto.org +# Date : 2016-06-29 # # Check Point base inventory # @@ -11,25 +15,15 @@ # 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-08: transferred license/support info to separate plugin # 2021-02-22: code cleanup # 2021-03-05: added hostlabel section # 2021-03-18: fixed missing update agent snmp section. # 2021-07-24: fixed parse function for empty string_table -# -# sample string_table -# [ -# [ -# ['5M7C043', 'Smart-1 5150', 'CheckPoint', 'Smart-1', 'R80.40', '994000022', 'Gaia', '3', '10'] -# ], -# [ -# ['1959'] -# ], -# ] +# 2023-04-23: refactoring # from typing import List, NamedTuple, Optional - from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( HostLabelGenerator, StringTable, @@ -47,51 +41,69 @@ from cmk.base.plugins.agent_based.agent_based_api.v1 import ( ) +class CheckpointInvBaseInfo(NamedTuple): + serial_number: str + product_name: str + manufacturer: str + series: str + version: str + build: str + osname: str + os_major_ver: str + os_minor_ver: str + + def parse_inv_checkpoint_base(string_table: List[StringTable]) -> Optional[List]: - class CheckpointInvBaseInfo(NamedTuple): - serialnumber: str - productname: str - manufacturer: str - series: str - version: str - build: str - osname: str - osmajorver: str - osminorver: str - - if string_table == [[], []]: + """ + >>> from pprint import pp + >>> string_table = [[['5M7C043','Smart-1 5150','CheckPoint','Smart-1','R80.40','994000022','Gaia','3','10']]] + >>> string_table.append([['1959']]) + >>> print(string_table) + [[['5M7C043', 'Smart-1 5150', 'CheckPoint', 'Smart-1', 'R80.40', '994000022', 'Gaia', '3', '10']], [['1959']]] + >>> pp(parse_inv_checkpoint_base(string_table)) + [(['hardware', 'system'], 'serial', '5M7C043'), + (['hardware', 'system'], 'appliance_series', 'Smart-1'), + (['hardware', 'system'], 'manufacturer', 'CheckPoint'), + (['hardware', 'system'], 'product_name', 'Smart-1 5150'), + (['software', 'check_point', 'os_info'], 'svn_version', 'R80.40'), + (['software', 'check_point', 'os_info'], 'svn_build', '994000022'), + (['software', 'check_point', 'os_info'], 'os_name', 'Gaia'), + (['software', 'check_point', 'os_info'], 'deployment_agent_build', '1959'), + (['software', 'check_point', 'os_info'], 'os_version', '3.10')] + """ + try: + base_info = CheckpointInvBaseInfo(*string_table[0][0]) + except IndexError: return - section = [] - baseinfo = CheckpointInvBaseInfo(*string_table[0][0]) - try: - updateagentversion = string_table[1][0][0] + update_agent_version = string_table[1][0][0] except IndexError: - updateagentversion = '' + update_agent_version = '' - invPath = ['hardware', 'system'] + section = [] + path = ['hardware', 'system'] for key, value in [ - ('serial', baseinfo.serialnumber), - ('appliance_series', baseinfo.series), - ('manufacturer', baseinfo.manufacturer), - ('product_name', baseinfo.productname), + ('serial', base_info.serial_number), + ('appliance_series', base_info.series), + ('manufacturer', base_info.manufacturer), + ('product_name', base_info.product_name), ]: if not value == '': - section.append((invPath, key, value)) + section.append((path, key, value)) - invPath = ['software', 'check_point', 'os_info'] + path = ['software', 'check_point', 'os_info'] for key, value in [ - ('svn_version', baseinfo.version), - ('svn_build', baseinfo.build), - ('os_name', baseinfo.osname), - ('deployment_agent_build', updateagentversion), - ('os_version', baseinfo.osmajorver + '.' + baseinfo.osminorver), + ('svn_version', base_info.version), + ('svn_build', base_info.build), + ('os_name', base_info.osname), + ('deployment_agent_build', update_agent_version), + ('os_version', base_info.os_major_ver + '.' + base_info.os_minor_ver), ]: if not value == '': - section.append((invPath, key, value)) + section.append((path, key, value)) return section diff --git a/gui/views/inv_checkpoint_base.py b/gui/views/inv_checkpoint_base.py new file mode 100644 index 0000000000000000000000000000000000000000..a6317c534ff2956eae6fa05bafe7a24b78e4ba91 --- /dev/null +++ b/gui/views/inv_checkpoint_base.py @@ -0,0 +1,26 @@ +#!/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-06-29 + +# 2023-04-23: moved views file to ~/local/lib/check_mk/gui/plugins/views + +from cmk.gui.i18n import _ +from cmk.gui.plugins.views.utils import ( + inventory_displayhints, +) + +inventory_displayhints.update({ + '.software.check_point.os_info:': { + 'title': _('OS Info'), + }, + '.software.check_point.os_info.deployment_agent_build': {'title': _('Deployment Agent Build'), }, + '.software.check_point.os_info.os_name': {'title': _('OS Name'), }, + '.software.check_point.os_info.os_version': {'title': _('OS Version'), }, + '.software.check_point.os_info.svn_build': {'title': _('SVN Build'), }, + '.software.check_point.os_info.svn_version': {'title': _('SVN Version'), }, +}) diff --git a/inv_checkpoint_base.mkp b/inv_checkpoint_base.mkp index 6fcf74af6671d74f5ae77c9767d9621a516517a0..8a80466998d9771df5a1a99f5acc136ac7eead80 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 d6a6e36b34ab6d2b8af21f535ade5c6f7a1fe448..0e46e76fbe14c571ecb63ea6f5e56ee8cb83f5c8 100644 --- a/packages/inv_checkpoint_base +++ b/packages/inv_checkpoint_base @@ -1,17 +1,16 @@ {'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', 'description': 'SNMP inventory of Check Point Appliances for:\n' - 'Serial Number, Product Name, Manufacturer, OS/SVN/Deployment ' + 'Serial number, Product name, Manufacturer, OS/SVN/Deployment ' 'agent version\n' '\n' '- 2021-02-08: initial release\n' '- 2021-02-22: code cleanup\n', 'download_url': 'https://thl-cmk.hopto.org', 'files': {'agent_based': ['inv_checkpoint_base.py'], - 'web': ['plugins/views/inv_checkpoint_base.py']}, + 'gui': ['views/inv_checkpoint_base.py']}, 'name': 'inv_checkpoint_base', - 'num_files': 2, 'title': 'Check Point appliance base inventory plugin', - 'version': '20210724.v.0.1a', - 'version.min_required': '2.0.0', - 'version.packaged': '2021.09.20', + 'version': '0.2.1-20230423', + 'version.min_required': '2.1.0b1', + 'version.packaged': '2.1.0p21', 'version.usable_until': None} \ No newline at end of file