diff --git a/agent_based/inv_epsm.py b/agent_based/inv_epsm.py new file mode 100644 index 0000000000000000000000000000000000000000..6d877ce48b457ec29c7f2b4a46db5783490e535e --- /dev/null +++ b/agent_based/inv_epsm.py @@ -0,0 +1,174 @@ +#!/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 : 2021-11-27 +# +# inventory of ePowerSwitch +# https://www.neol.com/en/products/epowerswitch/ + +# sample snmpwalk +# eps8XM-private::version.0 = STRING: "v 3.1.2.2" +# eps8XM-private::DeviceId."" = STRING: "M0" +# eps8XM-private::DeviceId.1 = STRING: "S1" +# eps8XM-private::DeviceId.17 = STRING: "TH1" +# eps8XM-private::DeviceName."" = STRING: "F_Master" +# eps8XM-private::DeviceName.1 = STRING: "F_Satellit" +# eps8XM-private::DeviceName.17 = STRING: "SEN-1" +# eps8XM-private::DeviceActivated."" = Wrong Type (should be INTEGER): STRING: "1" +# eps8XM-private::DeviceActivated.1 = Wrong Type (should be INTEGER): STRING: "1" +# eps8XM-private::DeviceActivated.17 = Wrong Type (should be INTEGER): STRING: "1" +# eps8XM-private::DeviceDetected."" = Wrong Type (should be INTEGER): STRING: "1" +# eps8XM-private::DeviceDetected.1 = Wrong Type (should be INTEGER): STRING: "1" +# eps8XM-private::DeviceDetected.17 = Wrong Type (should be INTEGER): STRING: "1" +# eps8XM-private::DeviceType."" = STRING: "PowerSwitch" +# eps8XM-private::DeviceType.1 = STRING: "Power Switch 8-Port" +# eps8XM-private::DeviceType.17 = STRING: "TH Sensor" +# eps8XM-private::DeviceVersion."" = STRING: "v 3.3.0.0" +# eps8XM-private::DeviceVersion.1 = STRING: "v 4.0.0.5" +# eps8XM-private::DeviceVersion.17 = STRING: "v 7.10.0.0" +# +# .1.3.6.1.4.1.24734.13.1.1.0 = STRING: "v 3.1.2.2" +# .1.3.6.1.4.1.24734.13.2.1.1.1.0 = STRING: "M0" +# .1.3.6.1.4.1.24734.13.2.1.1.1.1 = STRING: "S1" +# .1.3.6.1.4.1.24734.13.2.1.1.1.17 = STRING: "TH1" +# .1.3.6.1.4.1.24734.13.2.1.1.2.0 = STRING: "F_Master" +# .1.3.6.1.4.1.24734.13.2.1.1.2.1 = STRING: "F_Satellit" +# .1.3.6.1.4.1.24734.13.2.1.1.2.17 = STRING: "SEN-1" +# .1.3.6.1.4.1.24734.13.2.1.1.3.0 = Wrong Type (should be INTEGER): STRING: "1" +# .1.3.6.1.4.1.24734.13.2.1.1.3.1 = Wrong Type (should be INTEGER): STRING: "1" +# .1.3.6.1.4.1.24734.13.2.1.1.3.17 = Wrong Type (should be INTEGER): STRING: "1" +# .1.3.6.1.4.1.24734.13.2.1.1.4.0 = Wrong Type (should be INTEGER): STRING: "1" +# .1.3.6.1.4.1.24734.13.2.1.1.4.1 = Wrong Type (should be INTEGER): STRING: "1" +# .1.3.6.1.4.1.24734.13.2.1.1.4.17 = Wrong Type (should be INTEGER): STRING: "1" +# .1.3.6.1.4.1.24734.13.2.1.1.5.0 = STRING: "PowerSwitch" +# .1.3.6.1.4.1.24734.13.2.1.1.5.1 = STRING: "Power Switch 8-Port" +# .1.3.6.1.4.1.24734.13.2.1.1.5.17 = STRING: "TH Sensor" +# .1.3.6.1.4.1.24734.13.2.1.1.6.0 = STRING: "v 3.3.0.0" +# .1.3.6.1.4.1.24734.13.2.1.1.6.1 = STRING: "v 4.0.0.5" +# .1.3.6.1.4.1.24734.13.2.1.1.6.17 = STRING: "v 7.10.0.0" +# +# sample string_table +# [ +# [ +# ['v 3.1.2.2'] +# ], +# [ +# ['M0', 'F_Master', '1', '1', 'PowerSwitch', 'v 3.3.0.0'], +# ['S1', 'F_Satellit', '1', '1', 'Power Switch 8-Port', 'v 4.0.0.5'], +# ['TH1', 'SEN-1', '1', '1', 'TH Sensor', 'v 7.10.0.0'] +# ] +# ] +# +# sample section +# { +# 'devices': +# [ +# {'id': 'M0', 'name': 'F_Master', 'type': 'PowerSwitch', 'version': 'v 3.3.0.0', +# 'status_columns': {'activated': '1', 'detected': '1'}}, +# {'id': 'S1', 'name': 'F_Satellit', 'type': 'Power Switch 8-Port', 'version': 'v 4.0.0.5', +# 'status_columns': {'activated': '1', 'detected': '1'}}, +# {'id': 'TH1', 'name': 'SEN-1', 'type': 'TH Sensor', 'version': 'v 7.10.0.0', +# 'status_columns': {'activated': '1', 'detected': '1'}} +# ], +# 'version': 'v 3.1.2.2' +# } + +from typing import List, NamedTuple, Optional, Dict, Any + +from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( + StringTable, + InventoryResult, +) + +from cmk.base.plugins.agent_based.agent_based_api.v1 import ( + register, + SNMPTree, + TableRow, + Attributes, + startswith, +) + + +def parse_inv_espm(string_table: List[StringTable]) -> Dict[str, Any]: # Dict[str, str, List[Dict[str, str]]: + version, devices = string_table + section = {} + section['devices'] = [] + section['version'] = version[0][0] + + for deviceid, devicename, deviceactivated, devicedetected, devicetype, deviceversion in devices: + + section['devices'].append({ + 'id': deviceid, + 'name': devicename, + 'type': devicetype, + 'version': deviceversion, + 'status_columns': { + 'activated': deviceactivated, + 'detected': devicedetected, + }, + }) + return section + + +def inventory_hw_modules(params, section: Dict[str, Any]) -> InventoryResult: + path = ['hardware', 'system'] + + yield Attributes( + path=path, + inventory_attributes={'version': section['version']} + ) + + path = ['hardware', 'devices'] + + for device in section['devices']: + + key_columns = {'id': device['id']} + + for key in key_columns.keys(): + device.pop(key) + + status_columns = device['status_columns'] + device.pop('status_columns') + yield TableRow( + path=path, + key_columns=key_columns, + inventory_columns=device, + status_columns=status_columns, + ) + + +register.snmp_section( + name='inv_espm', + parse_function=parse_inv_espm, + fetch=[ + SNMPTree( + base='.1.3.6.1.4.1.24734.13.1', # eps8XM-private::System + oids=[ + '1', # version + ] + ), + SNMPTree( + base='.1.3.6.1.4.1.24734.13.2.1.1', # eps8XM-private::Devices + oids=[ + '1', # DeviceId + '2', # DeviceName + '3', # DeviceActivated + '4', # DeviceDetected + '5', # DeviceType + '6', # DeviceVersion + ] + ), + ], + detect=startswith('.1.3.6.1.2.1.1.2.0', '.1.3.6.1.4.1.24734.'), +) + +register.inventory_plugin( + name='inv_espm', + inventory_function=inventory_hw_modules, + inventory_default_parameters={}, + inventory_ruleset_name='inv_espm', +) diff --git a/inv_epsm.mkp b/inv_epsm.mkp new file mode 100644 index 0000000000000000000000000000000000000000..55258164d4c46f97496ca52f87ed2be79b0b33af Binary files /dev/null and b/inv_epsm.mkp differ diff --git a/packages/inv_epsm b/packages/inv_epsm new file mode 100644 index 0000000000000000000000000000000000000000..47f919ef80eb2e01df042d4a19dc4105ce7aac6c --- /dev/null +++ b/packages/inv_epsm @@ -0,0 +1,11 @@ +{'author': 'Th.L. (thl-cmk[at]outlook[dot]com)', + 'description': 'Inventory Neols ePowerSwitch ', + 'download_url': 'https://thl-cmk.hopto.org', + 'files': {'agent_based': ['inv_epsm.py']}, + 'name': 'inv_epsm', + 'num_files': 1, + 'title': 'Neol ePowerswitch inventory', + 'version': '20211127.v.0.0.1', + 'version.min_required': '2.0.0', + 'version.packaged': '2021.09.20', + 'version.usable_until': None} \ No newline at end of file