diff --git a/inv_huawei_hw_components.mkp b/inv_huawei_hw_components.mkp new file mode 100644 index 0000000000000000000000000000000000000000..084edc35b50cb44e40f93d34bbbe1d7102e05a33 Binary files /dev/null and b/inv_huawei_hw_components.mkp differ diff --git a/inventory/huawei_hw_components b/inventory/huawei_hw_components new file mode 100644 index 0000000000000000000000000000000000000000..66d3afbd67024bb52cef94698d844ff7f53c832c --- /dev/null +++ b/inventory/huawei_hw_components @@ -0,0 +1,97 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +# License: GNU General Public License v2 +# +# Author: thl-cmk[at]outlook[dot]com +# URL : https://thl-cmk.hopto.org +# Date : 2020-07-14 +# +# extended inventory of Huawei hardware components +# + + +def inv_huawei_hw_components(info, params): + def parse_huawei_hw_components(info): + def get_snmp_date(hwEntityManufacturedDate): + year = (ord(hwEntityManufacturedDate[0]) << 8) + ord(hwEntityManufacturedDate[1]) + month = ord(hwEntityManufacturedDate[2]) + day = ord(hwEntityManufacturedDate[3]) + snmpDate = '%d-%02d-%02d' % (year, month, day) + return snmpDate + + defaultEntities, huaweiEntities = info + entities = {} + + for entry in huaweiEntities: + hwOID_END, hwEntityBomId, hwEntityBomEnDesc, hwEntityManufacturedDate, hwEntityBoardType, hwEntityOpticalVendorSn = entry + + if hwEntityBomEnDesc != '': + entity = {} + entity['hwEntityBomId'] = hwEntityBomId + entity['hwEntityBomEnDesc'] = hwEntityBomEnDesc + entity['hwEntityManufacturedDate'] = get_snmp_date(hwEntityManufacturedDate) + entity['hwEntityBoardType'] = hwEntityBoardType + entity['serial_number'] = hwEntityOpticalVendorSn + + for entry in defaultEntities: + OID_END, entPhysicalDescr, entPhysicalName, entPhysicalHardwareRev, entPhysicalFirmwareRev, entPhysicalSoftwareRev, entPhysicalSerialNum, entPhysicalMfgName = entry + if OID_END == hwOID_END: + entity['entPhysicalDescr'] = entPhysicalDescr + entity['entPhysicalName'] = entPhysicalName + entity['entPhysicalHardwareRev'] = entPhysicalHardwareRev + entity['entPhysicalFirmwareRev'] = entPhysicalFirmwareRev + entity['entPhysicalSoftwareRev'] = entPhysicalSoftwareRev + entity['entPhysicalMfgName'] = entPhysicalMfgName + if entity['serial_number'] == '': + entity['serial_number'] = entPhysicalSerialNum + + entities[hwOID_END] = entity + return entities + + node = inv_tree_list('hardware.components.huawei:') + entities = parse_huawei_hw_components(info) + + for key, value in entities.items(): + node.append({ + 'index': key, + 'bom_id': value['hwEntityBomId'], + 'bom_decription': value['hwEntityBomEnDesc'], + 'manufactured_date': value['hwEntityManufacturedDate'], + 'board_type': value['hwEntityBoardType'], + 'description': value['entPhysicalDescr'], + 'name': value['entPhysicalName'], + 'hardware_revision': value['entPhysicalHardwareRev'], + 'firmware_revision': value['entPhysicalFirmwareRev'], + 'software_revision': value['entPhysicalSoftwareRev'], + 'serial_number': value['serial_number'], + 'vendor': value['entPhysicalMfgName'], + }) + + return node + + +inv_info['inv_huawei_hw_components'] = { + 'inv_function': inv_huawei_hw_components, + 'snmp_info': [ + ('.1.3.6.1.2.1.47.1.1.1.1', [ + OID_END, + '2', # entPhysicalDescr + '7', # entPhysicalName + '8', # entPhysicalHardwareRev + '9', # entPhysicalFirmwareRev + '10', # entPhysicalSoftwareRev + '11', # entPhysicalSerialNum + '12', # entPhysicalMfgName + ]), + ('.1.3.6.1.4.1.2011.5.25.31.1.1', [ + OID_END, + '2.1.1', # hwEntityBomId + '2.1.2', # hwEntityBomEnDesc + '2.1.4', # hwEntityManufacturedDate + '2.1.11', # hwEntityBoardType + '3.1.4' # hwEntityOpticalVendorSn + ]) + ], + 'snmp_scan_function': lambda oid: oid('.1.3.6.1.2.1.1.2.0').startswith('.1.3.6.1.4.1.2011'), +} diff --git a/packages/inv_huawei_hw_components b/packages/inv_huawei_hw_components new file mode 100644 index 0000000000000000000000000000000000000000..cce8645e50154e40fac34326034ae6f67250241c --- /dev/null +++ b/packages/inv_huawei_hw_components @@ -0,0 +1,11 @@ +{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)', + 'description': u'SNMP inventory for Huawei hardware components.', + 'download_url': 'https://thl-cmk.hopto.org', + 'files': {'inventory': ['huawei_hw_components'], + 'web': ['plugins/views/inv_huawei_hw_components.py']}, + 'name': 'inv_huawei_hw_components', + 'num_files': 2, + 'title': u'Inventory for Huawei hardware components', + 'version': '20200714.v0.1c', + 'version.min_required': '1.2.8b8', + 'version.packaged': '1.4.0p38'} \ No newline at end of file diff --git a/web/plugins/views/inv_huawei_hw_components.py b/web/plugins/views/inv_huawei_hw_components.py new file mode 100644 index 0000000000000000000000000000000000000000..6f793b21db24d584eed86976ed89386deecf55e3 --- /dev/null +++ b/web/plugins/views/inv_huawei_hw_components.py @@ -0,0 +1,35 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- + +try: + from cmk.gui.plugins.views.inventory import ( + declare_invtable_view, + render_inv_dicttable, + ) +except: + pass + +inventory_displayhints.update({ + '.hardware.components.huawei:': {'title': _('Huawei'), 'render': render_inv_dicttable, + 'keyorder': ['index', 'name', 'description', 'board_type', 'serial_number', + 'manufactured_date', 'vendor', + ], + 'view': 'invhuawei_components_of_host', + }, + '.hardware.components.huawei:*.index': {'title': _('Index'), }, + '.hardware.components.huawei:*.name': {'title': _('Name')}, + '.hardware.components.huawei:*.description': {'title': _('Description'), }, + '.hardware.components.huawei:*.bom_id': {'title': _('BOM ID'), }, + '.hardware.components.huawei:*.bom_decription': {'title': _('BOM Description')}, + '.hardware.components.huawei:*.manufactured_date': {'title': _('Manufactured Date')}, + '.hardware.components.huawei:*.board_type': {'title': _('Board Type'), }, + '.hardware.components.huawei:*.software_revision': {'title': _('Software Revision'), }, + '.hardware.components.huawei:*.firmware_revision': {'title': _('Firmware Revision'), }, + '.hardware.components.huawei:*.hardware_revision': {'title': _('Hardware Revision'), }, + '.hardware.components.huawei:*.serial_number': {'title': _('Serial Number'), }, + '.hardware.components.huawei:*.vendor': {'title': _('Vendor'), }, + +}) + +declare_invtable_view('invhuawei_components', '.hardware.components.huawei:', _('Huawei hardware components'), + _('Huawei hardware components'))