diff --git a/CHANGELOG b/CHANGELOG index c7e06298ae4b9e40fd7dba001018ded45f07ad1d..742fc4974abc81142402f25f449795ea381b948a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,4 +5,5 @@ 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 +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_updates.py b/agent_based/inv_checkpoint_updates.py index 213069d72da6de95ae764b4055a6d4fbd30857c7..07638df15a1c0f0ca6e06062575f048aad8cc38b 100644 --- a/agent_based/inv_checkpoint_updates.py +++ b/agent_based/inv_checkpoint_updates.py @@ -1,17 +1,23 @@ #!/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 updates 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 +# 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: transferred license/support info to separate plugin +# 2021-02-22: code cleanup +# 2021-04-23: refactoring # # sample string_table # [ @@ -34,8 +40,7 @@ # ] # -from typing import List, NamedTuple - +from typing import List, NamedTuple, Optional from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( StringTable, InventoryResult, @@ -62,27 +67,31 @@ class CheckpointUpdatesAvailable(NamedTuple): description: str type: str status: str - availablesince: str + available_since: str recommended: str - installedat: str + installed_at: str class CheckpointUpdates(NamedTuple): - updatesrecommended: list - updatesavailable: list + updates_recommended: list + updates_available: list -def parse_checkpoint_updates(string_table: List[StringTable]) -> CheckpointUpdates: - section = CheckpointUpdates - section.updatesrecommended = list(string_table[0]) - section.updatesavailable = list(string_table[1]) +def parse_checkpoint_updates(string_table: List[StringTable]) -> Optional[CheckpointUpdates]: + try: + section = CheckpointUpdates( + updates_recommended=list(string_table[0]), + updates_available=list(string_table[1]) + ) + except IndexError: + return return section def inventory_checkpoint_updates(section: CheckpointUpdates) -> InventoryResult: path = ['software', 'check_point', 'updates'] - for update in section.updatesrecommended: + for update in section.updates_recommended: update = CheckpointUpdatesRecommended(*update) yield TableRow( path=path, @@ -94,13 +103,13 @@ def inventory_checkpoint_updates(section: CheckpointUpdates) -> InventoryResult: }, ) - for update in section.updatesavailable: + for update in section.updates_available: update = CheckpointUpdatesAvailable(*update) - if not 'installed' in update.status.lower(): - installedat = 'N/A' + if 'installed' not in update.status.lower(): + installed_at = 'N/A' else: - installedat = update.installedat.replace('T', ' ').replace('Z', '') + installed_at = update.installed_at.replace('T', ' ').replace('Z', '') yield TableRow( path=path, @@ -110,8 +119,8 @@ def inventory_checkpoint_updates(section: CheckpointUpdates) -> InventoryResult: 'type': update.type, 'status': update.status, 'recommended': update.recommended, - 'available_since': update.availablesince[:10], - 'installed_at': installedat, + 'available_since': update.available_since[:10], + 'installed_at': installed_at, }, ) diff --git a/gui/views/inv_checkpoint_updates.py b/gui/views/inv_checkpoint_updates.py new file mode 100644 index 0000000000000000000000000000000000000000..98adca47d43946cd1d27c99e24f70c51f47fd3c6 --- /dev/null +++ b/gui/views/inv_checkpoint_updates.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.updates:': { + 'title': _('Updates'), + 'keyorder': [ + 'file_name', + 'type', + 'status', + 'recommended', + 'available_since', + 'installed_at', + 'description' + ], + 'view': 'invcheckpointupdates_of_host', + }, +}) + +declare_invtable_view( + 'invcheckpointupdates', + '.software.check_point.updates:', + _('Check Point updates'), + _('Check Point updates'), +) diff --git a/inv_checkpoint_updates.mkp b/inv_checkpoint_updates.mkp index 69aefe6c9f244b9787e006462f4cc1554198e79a..ff2cc34734d6e8ea01719af5cdc03503dde426c9 100644 Binary files a/inv_checkpoint_updates.mkp and b/inv_checkpoint_updates.mkp differ diff --git a/packages/inv_checkpoint_updates b/packages/inv_checkpoint_updates index 484905601db8ec02723346b108b886de45409505..46e0f553a82d99919763b5e52bd54f7866d0fe4d 100644 --- a/packages/inv_checkpoint_updates +++ b/packages/inv_checkpoint_updates @@ -5,11 +5,10 @@ '- 2021-02-08: initial release\n', 'download_url': 'https://thl-cmk.hopto.org', 'files': {'agent_based': ['inv_checkpoint_updates.py'], - 'web': ['plugins/views/inv_checkpoint_updates.py']}, + 'gui': ['views/inv_checkpoint_updates.py']}, 'name': 'inv_checkpoint_updates', - 'num_files': 2, 'title': 'Check Point appliance avilable updates inventory plugin', - 'version': '20210208.v.0.1', - '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