I’m trying to make my first plugin work. It’s just a basic SNMP plugin. I have the following SNMP output:
1.3.6.1.4.1.39165.1.1.0 = "TV-IP1319PI" [ASN_OCTET_STR]
1.3.6.1.4.1.39165.1.2.0 = "0" [ASN_OCTET_STR]
I’m trying to create 2 services named “SNMP deviceType” and “SNMP memSize”. Here is what I currently have based on a lot of reading through the doc and other similar plugins:
#!/usr/bin/env python3
from cmk.base.plugins.agent_based.agent_based_api.v1 import exists, register, SNMPTree, Service, Result, State
def parse_trendnet_camera(string_table):
parsed = {}
for line in string_table:
parsed[line[0]] = line[1]
return parsed
def discover_trendnet_camera(section):
for service_id in section:
yield Service(item=service_id)
def check_trendnet_camera(item, params, section):
yield Result(state=State.OK, summary=f"SNMP {State.OK}: {section[item]}")
register.snmp_section(
name = 'trendnet_camera',
detect = exists('.1.3.6.1.4.1.39165.1.1.0'),
fetch = SNMPTree(
base = '.1.3.6.1.4.1.39165.1.1',
oids = [
'1.0', # deviceType
'2.0', # memSize
],
),
parse_function=parse_trendnet_camera,
)
register.check_plugin(
name="trendnet_camera",
service_name="SNMP %s",
discovery_function=discover_trendnet_camera,
check_function=check_trendnet_camera,
check_default_parameters={}
)
Nothing is discovered. I still can’t exactly figure out how to map the service name to an OID (I have 34 OIDs total but currently just testing the first 2). I’m also not sure the parse_function
is required at all for my use case scenario. I know I’m very close to get this working and would appreciate if you could just point me in the right direction. I wish the doc had a completely working basic example.