2.0.x create custom SNMP check

I try to write some SNMP checks for 2.0.0pX
Unfortunatly the documentation https://docs.checkmk.com/latest/en/devel_check_plugins.html does not help very much. I searched this forum and found some hints, but nothing got me in the right direction yet. The SNMP checks delivered with checkmk that i found so far are using the old methods.

We have multiple devices that deliver many information and state by SNMP. I wanted to try something simple first and check the Dell Compellent Power Supply.
For the Dell Compellent there are some checks already delivered with check_mk but those are using the legacy checks as well.

I could also not find any SNMP check using v2 mechanism in the exchange.

So here is what i have and tried so far:
Partially output of OIDs

#.1.3.6.1.4.1.674.11000.2000.500.1.2.1.0 Dell-Compellent Storage Center
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.2.1.1 1
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.2.1.2 2
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.3.1.1 1
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.3.1.2 1
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.4.1.1 Power Supply 1
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.4.1.2 Power Supply 2
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.5.1.1 Empty
#.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1.5.1.2 Empty 

latest try

#!/usr/bin/env python3

from .agent_based_api.v1 import (
    contains,
    register,
    SNMPTree,
)

register.snmp_section(
    name = "dell_compellent_power",
	detect = contains(".1.3.6.1.4.1.674.11000.2000.500.1.2.1.0", "Compellent"),
	fetch = SNMPTree(
		base = '.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1',
		oids = [
			"2.1", # 0 scPSNbr
			"3.1", # 1 scPSStatus
            "4.1", # 2 scPSName
		],
	),
)

Output:

Error in agent based plugin dell_compellent_power: invalid characters in OID descriptor: ' '

I would really appreciate a link to a good and complete documentation for writing 2.0 SNMP checks. Or the name of a delivered plugin that already uses the new way of SNMP checks to get started.

a bit further, i discovered a few SNMP checks using the new mechanisms. So I tried to adapt it to my check.
Well i do not get an error anymore, but no inventory or check as well…

Maybe someone can push me in the right direction. What i got so far:

#!/usr/bin/env python3

from typing import Mapping, NamedTuple, Optional
from .agent_based_api.v1.type_defs import CheckResult, DiscoveryResult, StringTable
from .agent_based_api.v1 import (
    exists,
    register,
    Result,
    Service,
    SNMPTree,
    State,
)

class Section(NamedTuple):
    id: str
    state: str
    name: str
 
_DEVICE_STATE_MAP: Mapping[str, str] = {
    '1': 'OK',
    '2': 'FAILED',
    '3': 'DEGRADED',
}
 
def check_dell_compellent_power(section: Section)-> CheckResult:
    state_txt = _DEVICE_STATE_MAP.get(section.state, f"Unknown [{section.state}]")
    yield Result(
        state=State.get(state_txt, 3), 
        summary=state_txt,
    )
 
def parse_dell_compellent_power(string_table: StringTable) -> Optional[Section]:
    return Section(*string_table[0]) if string_table else None

def discover_dell_compellent_power(section: Section) -> DiscoveryResult:
    yield Service()
 
register.snmp_section(
    name = "dell_compellent_power",
    parse_function = parse_dell_compellent_power,
	detect = exists(".1.3.6.1.4.1.674.11000.2000.500.1.2.1.0"),
	fetch = SNMPTree(
		base = '.1.3.6.1.4.1.674.11000.2000.500.1.2.17.1',
		oids = [
			"2.1", # 0 scPSNbr
			"3.1", # 1 scPSStatus
            "4.1", # 2 scPSName
		],
	),
)

register.check_plugin(
    name = 'dell_compellent_power',
    sections = ['dell_compellent_power'],
    service_name = 'Power Supply Status',
    check_function = check_dell_compellent_power,
    discovery_function = discover_dell_compellent_power,
)

There are two power supplies in your example SNMP data. Why do you create only one service check without item?

To debug check plugins I add the following:

from cmk.utils import debug
from pprint import pprint

And then where needed e.g.:

if debug.enabled():
    pprint(string_table)

This code gets executed when calling cmk on the command line like:

cmk -vp --debug <hostname>

There are two power supplies in your example SNMP data. Why do you create only one service check without item?

Do I? I am not good in reading or coding Python. For me it would be easier in Perl :slight_smile:

I will have a look at your hint to the debug code. Maybe it will help me understand what ist happening.

Thanks

Have a look at check_mk_extensions/gamatronic_elphase.py at cmk2.0 · HeinleinSupport/check_mk_extensions · GitHub for an example.

Thanks a lot sander. I learned another bit of Python and that i will have to learn Python before i continue.

Maybe the other compellent checks will be implemented as default cmk plug-in soon.
I just thought i could “easily” build checks for PowerSupply, Fan and Volume checks that the, not working with 2.0, check from the exchange had. Well, not that easy :slight_smile:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.