From 89116fec817efa299b0e7b13e5c4d436d7069ef1 Mon Sep 17 00:00:00 2001
From: thl-cmk <thl-cmk@outlook.com>
Date: Mon, 22 Feb 2021 21:12:48 +0100
Subject: [PATCH] update project

---
 agent_based/checkpoint_inv_support.py   | 123 ++++++++++++++++++++++++
 inv_checkpoint_support.mkp              | Bin 0 -> 2368 bytes
 packages/inv_checkpoint_support         |  13 +++
 web/plugins/views/checkpoint_support.py |  32 ++++++
 4 files changed, 168 insertions(+)
 create mode 100644 agent_based/checkpoint_inv_support.py
 create mode 100644 inv_checkpoint_support.mkp
 create mode 100644 packages/inv_checkpoint_support
 create mode 100644 web/plugins/views/checkpoint_support.py

diff --git a/agent_based/checkpoint_inv_support.py b/agent_based/checkpoint_inv_support.py
new file mode 100644
index 0000000..6d702f2
--- /dev/null
+++ b/agent_based/checkpoint_inv_support.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Author: thl-cmk[at]outlook[dot]com / thl-cmk.hopto.org
+#
+# 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']
+#  ]
+# ]
+#
+
+import time
+
+from typing import List, NamedTuple
+
+from .agent_based_api.v1.type_defs import (
+    StringTable,
+    InventoryResult,
+)
+from .agent_based_api.v1 import (
+    register,
+    SNMPTree,
+    TableRow,
+    startswith,
+    all_of,
+    any_of,
+    equals,
+)
+
+
+class CheckpointLicensing(NamedTuple):
+    accountid: str
+    packagedescription: str
+    containerck: str
+    signaturekey: str
+    containersku: str
+    supportlevel: str
+    supportexpiration: str
+    activationstatus: str
+
+
+def parse_checkpoint_inv_licensing(string_table: List[StringTable]) -> List:
+    section = []
+    for license in string_table[0]:
+        license = CheckpointLicensing(*license)
+        if not license.containerck == '':
+            section.append(license)
+    return section
+
+
+def inventory_checkpoint_licensing(section: List) -> InventoryResult:
+    path = ['software', 'check_point', 'support']
+
+    lic_state = {
+        '1': 'trial period',
+        '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)))
+
+        yield TableRow(
+            path=path,
+            key_columns={'certificate_key': license.containerck},
+            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)
+            },
+        )
+
+
+register.snmp_section(
+    name='checkpoint_inv_licensing',
+    parse_function=parse_checkpoint_inv_licensing,
+    fetch=[
+        SNMPTree(
+            base='.1.3.6.1.4.1.2620.1.6.18.2',  # CHECKPOINT-MIB::licensingAssetInfo
+            oids=[
+                '1',  # licensingAssetAccountId
+                '2',  # licensingAssetPackageDescription
+                '3',  # licensingAssetContainerCK
+                '4',  # Signature key
+                '5',  # licensingAssetContainerSKU
+                '6',  # licensingAssetSupportLevel
+                '7',  # licensingAssetSupportExpiration
+                '8',  # licensingAssetActivationStatus
+            ]
+        ),
+    ],
+    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_licensing',
+    inventory_function=inventory_checkpoint_licensing,
+)
diff --git a/inv_checkpoint_support.mkp b/inv_checkpoint_support.mkp
new file mode 100644
index 0000000000000000000000000000000000000000..db378c455e10e320efa90ecc28c865a8ac9627cf
GIT binary patch
literal 2368
zcmZ{gc{~#g1INqFqmUO-NG7+}l_PTW=*gWNV}!|=YolfE<#DSK#@s`06KaUelC8t$
zj2uffLas-SHFNB>_xbaA|9HRu{663RexI)*T1e=+xFMK_8w!u{4-5$k43CNog-828
zKt@GHBBHhRb@lah^>s~jVsvzM^mJh1QKz<ixRLX{Qsd(%n!OiA=z=~4|N21Xi?b@<
zpQ#DeF@f^KL6_9d$#)j0IMr7s+~l&aV=zv1#Ai4uqK7255V@R~_cw~J=SC+(U$QSy
zPUmF)&Jv#EMB_d#R+&YAQ9jtXsJJzlwW;t^0=g~hf{>72pt0BL>8}{V7N7w2U{Ju}
z+rBEgjM4gIkbd?LG2^GbqxJ<5I>o8-(Y#s(``N=RFTIsJgNQ+bdzh0B!&jnMCq#pA
z&yJvOTJdo$<!+Fc)Ux5Yq;#Xi3Zz^L5Fp`XdVL|N3Yu{Vm=*CRbyr-4>w}-CDNF%=
zTdL7IN1t=dt~?eL#OCd54c`ogz9V6(2<Zs%H0Q5rW`n*%p`rtk&usgO9P)Ugt~QtV
zFdLBb#=g%L)^V;wg?m*E9Pr?pvZd}Pr|EIRN5e|D_3|#Fb`!^bINs&>2bE{grnYFr
zB?H-PE006Ecbn1XQl<MvNUL$}OQx#(<d}%rXWgq>XGD(J7%2^&V!?A~!)eO_zfPq*
z)^r1tyGcu#wp0o+T_8xKG>02hJUO12&6U?(NIvErpX36##0t*#wOh)|T<9VfHOf7<
zpmX)P+idD<Yp&}$qn2B~iS<p}XjsI#|2spfBK2Rr1H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PN7$93J3n&l8wVe*Ie?koAeaA*-6Du%@qh
z4_R4vn8PqfPnw6kKyrdQ6OcBLI<omQ!kvb3ScEkE;%WMwwlS>XX3l`AHv)oB)@oNx
zYO8Qc1HI39>W5<;eAzVDo7lWHz?yhxXb-kpruZSdwDS>r0Fc8A=R9DR#;w<eWN(qo
kPv&|f6%-;-x*DMT&m#ZZ=l|G=+0N~&6+@b*;!d6VFTSU@g#Z8m

literal 0
HcmV?d00001

diff --git a/packages/inv_checkpoint_support b/packages/inv_checkpoint_support
new file mode 100644
index 0000000..4262962
--- /dev/null
+++ b/packages/inv_checkpoint_support
@@ -0,0 +1,13 @@
+{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)',
+ 'description': 'SNMP inventory of Check Point Appliances for license/support '
+                'status\n',
+ 'download_url': 'https://thl-cmk.hopto.org',
+ 'files': {'agent_based': ['checkpoint_inv_support.py'],
+           'web': ['plugins/views/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.0i1',
+ 'version.packaged': '2020.11.27',
+ 'version.usable_until': None}
\ No newline at end of file
diff --git a/web/plugins/views/checkpoint_support.py b/web/plugins/views/checkpoint_support.py
new file mode 100644
index 0000000..f97348e
--- /dev/null
+++ b/web/plugins/views/checkpoint_support.py
@@ -0,0 +1,32 @@
+#!/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.support:': {
+        'title': _('Support'),
+        'keyorder': [
+            'account_id',
+            'certificate_key',
+            'container',
+            'description',
+            'state',
+            'support_renewal',
+            'support_type',
+            ],
+        'view': 'invcheckpointsupport_of_host',
+        },
+    })
+
+from cmk.gui.plugins.views.inventory import declare_invtable_view
+
+declare_invtable_view(
+    'invcheckpointsupport',
+    '.software.check_point.support:',
+    _('Check Point support'),
+    _('Check Point support'),
+)
-- 
GitLab