Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit 66e7062a authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

update project

parent 836f16b4
Branches master
No related tags found
No related merge requests found
#!/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
#
# 2023-06-02: rewritten for cmk 2.1
from typing import Dict, List
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
register,
SNMPTree,
startswith,
TableRow,
OIDEnd,
)
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import (
InventoryResult,
StringTable,
)
def _get_snmp_date(manufactured_date):
year = (ord(manufactured_date[0]) << 8) + ord(manufactured_date[1])
month = ord(manufactured_date[2])
day = ord(manufactured_date[3])
return f'{year}-{month:02d}-{day:02d}'
def parse_inv_huawei_hw_components(string_table: List[StringTable]) -> Dict:
phys_entities, huawei_entities = string_table
section = {}
phys_dict = {}
for entry in phys_entities:
oid_end, description, name, hardware_rev, firmware_rev, software_rev, serial_num, mfg_name = entry
phys_dict[oid_end] = {}
phys_dict[oid_end]['description'] = description
phys_dict[oid_end]['name'] = name
phys_dict[oid_end]['hardware_revision'] = hardware_rev
phys_dict[oid_end]['firmware_revision'] = firmware_rev
phys_dict[oid_end]['software_revision'] = software_rev
phys_dict[oid_end]['vendor'] = mfg_name
phys_dict[oid_end]['serial_number'] = serial_num
for entry in huawei_entities:
oid_end, bom_id, bom_en_desc, manufactured_date, board_type, optical_vendor_sn = entry
if bom_en_desc != '':
section[oid_end] = {}
section[oid_end]['bom_id'] = bom_id
section[oid_end]['bom_description'] = bom_en_desc
section[oid_end]['manufactured_date'] = _get_snmp_date(manufactured_date)
section[oid_end]['board_type'] = board_type
section[oid_end].update(phys_dict[oid_end])
section[oid_end]['serial_number'] = optical_vendor_sn
return section
def inventory_huawei_hw_components(section: Dict) -> InventoryResult:
path = ['hardware', 'components', 'huawei']
for key, value in section.items():
yield TableRow(
path=path,
key_columns={
'index': key
},
inventory_columns=value
)
register.snmp_section(
name='inv_huawei_hw_components',
parse_function=parse_inv_huawei_hw_components,
fetch=[
SNMPTree(
base='.1.3.6.1.2.1.47.1.1.1.1',
oids=[
OIDEnd(),
'2', # entPhysicalDescr
'7', # entPhysicalName
'8', # entPhysicalHardwareRev
'9', # entPhysicalFirmwareRev
'10', # entPhysicalSoftwareRev
'11', # entPhysicalSerialNum
'12', # entPhysicalMfgName
]
),
SNMPTree(
base='.1.3.6.1.4.1.2011.5.25.31.1.1',
oids=[
OIDEnd(),
'2.1.1', # hwEntityBomId
'2.1.2', # hwEntityBomEnDesc
'2.1.4', # hwEntityManufacturedDate
'2.1.11', # hwEntityBoardType
'3.1.4' # hwEntityOpticalVendorSn
]
)
],
detect=startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.2011')
)
register.inventory_plugin(
name='inv_huawei_hw_components',
inventory_function=inventory_huawei_hw_components,
)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-; py-indent-offset: 4 -*-
from cmk.gui.plugins.views.utils import (
inventory_displayhints,
)
from cmk.gui.plugins.views.inventory import (
declare_invtable_view,
)
from cmk.gui.i18n import _
inventory_displayhints.update({
'.hardware.components.huawei:': {'title': _('Huawei'),
'keyorder': ['index', 'name', 'description', 'board_type', 'serial_number',
'manufactured_date', 'vendor',
],
'view': 'invhuaweicomponents_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_description': {'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('invhuaweicomponents', '.hardware.components.huawei:', _('Huawei hardware components'),
_('Huawei hardware components'))
File added
No preview for this file type
{'author': u'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': u'SNMP inventory for Huawei hardware components.',
{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)',
'description': 'SNMP inventory for Huawei hardware components.\n',
'download_url': 'https://thl-cmk.hopto.org',
'files': {'inventory': ['huawei_hw_components'],
'web': ['plugins/views/inv_huawei_hw_components.py']},
'files': {'agent_based': ['inv_huawei_hw_components.py'],
'gui': ['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
'title': 'Inventory for Huawei hardware components',
'version': '0.2.0-20230602',
'version.min_required': '2.1.0b1',
'version.packaged': '2.1.0p21',
'version.usable_until': '2.2.0b1'}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment