diff --git a/CHANGELOG b/CHANGELOG index 1c5b72955519a41e15bd58c5a7ad7783bd89d4ae..742fc4974abc81142402f25f449795ea381b948a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,9 @@ -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 \ No newline at end of file +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 +2023-04-23: refactoring, moved views file to ~/local/lib/check_mk/gui/plugins/views diff --git a/agent_based/inv_checkpoint_support.py b/agent_based/inv_checkpoint_support.py index c6ba091a0b19349fc192fff0dec920d80d06df1d..99ed728eeb004fdd8b8ed089101d3b443da1d7f8 100644 --- a/agent_based/inv_checkpoint_support.py +++ b/agent_based/inv_checkpoint_support.py @@ -1,31 +1,27 @@ #!/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 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 -# [ -# [ -# ['0008262230', 'Smart-1 5150 NGSM', 'E4:43:4B:AA:BB:CC', 'a5rYfxLngVSZtHjK2sfghhp6noVfzuTvSEbt', 'CPAP-NGSM5150', 'Collaborative Enterprise Support - StandardPro Add-on for Products', '1751500800', '2'] -# ] -# ] -# +# 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 cp_license/support info to seperate plugin +# 2021-02-22: code cleanup +# 2023-04-23: refactoring -import time +import time from typing import List, NamedTuple - from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( StringTable, InventoryResult, @@ -42,22 +38,44 @@ from cmk.base.plugins.agent_based.agent_based_api.v1 import ( class CheckpointLicensing(NamedTuple): - accountid: str - packagedescription: str - containerck: str - signaturekey: str - containersku: str - supportlevel: str - supportexpiration: str - activationstatus: str + account_id: str + package_description: str + container_ck: str + signature_key: str + container_sku: str + support_level: str + support_expiration: str + activation_status: str def parse_inv_checkpoint_support(string_table: StringTable) -> List: + # pprint will not format named tuples nicely :-( + """ + >>> from pprint import pp + >>> string_table = ['0008262230', 'Smart-1 5150 NGSM', 'E4:43:4B:AA:BB:CC', 'a5rYfxLngVSZtHjK2sfghhp6noVfzuTvSEbt'] + >>> string_table += ['CPAP-NGSM5150', 'Collaborative Enterprise Support - StandardPro Add-on for Products'] + >>> string_table += ['1751500800', '2'] + >>> string_table = [string_table] + >>> pp(string_table) + [['0008262230', + 'Smart-1 5150 NGSM', + 'E4:43:4B:AA:BB:CC', + 'a5rYfxLngVSZtHjK2sfghhp6noVfzuTvSEbt', + 'CPAP-NGSM5150', + 'Collaborative Enterprise Support - StandardPro Add-on for Products', + '1751500800', + '2']] + >>> pp(parse_inv_checkpoint_support(string_table)) + [CheckpointLicensing(account_id='0008262230', package_description='Smart-1 5150 NGSM', container_ck='E4:43:4B:AA:BB:CC', signature_key='a5rYfxLngVSZtHjK2sfghhp6noVfzuTvSEbt', container_sku='CPAP-NGSM5150', support_level='Collaborative Enterprise Support - StandardPro Add-on for Products', support_expiration='1751500800', activation_status='2')] + """ section = [] - for license in string_table: - license = CheckpointLicensing(*license) - if not license.containerck == '': - section.append(license) + for cp_license in string_table: + try: + cp_license = CheckpointLicensing(*cp_license) + except TypeError: + continue + if not cp_license.container_ck == '': + section.append(cp_license) return section @@ -69,23 +87,23 @@ def inventory_checkpoint_support(section: List) -> InventoryResult: '2': 'activated' } - for license in section: - license = CheckpointLicensing(*license) - supportexpiration = 'N/A' - if not license.supportexpiration == '': - supportexpiration = time.strftime("%Y-%m-%d %H:%M", time.localtime(int(license.supportexpiration))) + for cp_license in section: + cp_license = CheckpointLicensing(*cp_license) + support_expiration = 'N/A' + if not cp_license.support_expiration == '': + support_expiration = time.strftime("%Y-%m-%d %H:%M", time.localtime(int(cp_license.support_expiration))) yield TableRow( path=path, - key_columns={'certificate_key': license.containerck}, + key_columns={'certificate_key': cp_license.container_ck}, inventory_columns={ - 'account_id': license.accountid, - 'description': license.packagedescription, - 'signatur_key': license.signaturekey, - 'container': license.containersku, - 'support_type': license.supportlevel, - 'support_renewal': supportexpiration, - 'state': lic_state.get(license.activationstatus, license.activationstatus) + 'account_id': cp_license.account_id, + 'description': cp_license.package_description, + 'signatur_key': cp_license.signature_key, + 'container': cp_license.container_sku, + 'support_type': cp_license.support_level, + 'support_renewal': support_expiration, + 'state': lic_state.get(cp_license.activation_status, cp_license.activation_status) }, ) diff --git a/gui/views/inv_checkpoint_support.py b/gui/views/inv_checkpoint_support.py new file mode 100644 index 0000000000000000000000000000000000000000..63fe21a086e6c9f68e5751493f5ffa8c2bbea76d --- /dev/null +++ b/gui/views/inv_checkpoint_support.py @@ -0,0 +1,39 @@ +#!/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.inventory import declare_invtable_view +from cmk.gui.plugins.views.utils import ( + inventory_displayhints, +) + +inventory_displayhints.update({ + '.software.check_point.support:': { + 'title': _('Support'), + 'keyorder': [ + 'account_id', + 'certificate_key', + 'container', + 'description', + 'state', + 'support_renewal', + 'support_type', + ], + 'view': 'invcheckpointsupport_of_host', + }, +}) + +declare_invtable_view( + 'invcheckpointsupport', + '.software.check_point.support:', + _('Check Point support'), + _('Check Point support'), +) diff --git a/inv_checkpoint_support.mkp b/inv_checkpoint_support.mkp index 35d4a3b5aa759bf389254c294b8b0e53e1ef4e8a..9fce4910d3a3d750c1feead7b617f41988b16995 100644 Binary files a/inv_checkpoint_support.mkp and b/inv_checkpoint_support.mkp differ diff --git a/packages/inv_checkpoint_support b/packages/inv_checkpoint_support index ed08c2ca26e6cdf6ea7a60fd877db505b412cdf0..7b1a03b2e39f0d830ed50feba4f78a6f590ef68a 100644 --- a/packages/inv_checkpoint_support +++ b/packages/inv_checkpoint_support @@ -3,11 +3,10 @@ 'status\n', 'download_url': 'https://thl-cmk.hopto.org', 'files': {'agent_based': ['inv_checkpoint_support.py'], - 'web': ['plugins/views/inv_checkpoint_support.py']}, + 'gui': ['views/inv_checkpoint_support.py']}, 'name': 'inv_checkpoint_support', - 'num_files': 2, 'title': 'Check Point appliance support inventory plugin', - 'version': '20210208.v.0.1', - 'version.min_required': '2.0.0', - 'version.packaged': '2021.09.20', + 'version': '0.2.1-20230422', + 'version.min_required': '2.1.0b1', + 'version.packaged': '2.1.0p21', 'version.usable_until': None} \ No newline at end of file