Own SNMP Plugin for Cisco FXOS fails to register services

Hello,
at the moment im trying to develop a SNMP-Plugin for our Firepower OS to monitor the PSU’s and fans
I tried 2 different Version each with their own problems.
One version is using the older check_info[]={} , which i mainly found guides on the internet for and the older checks that come with CMK.
The other is using mainly the documentation for cmkv2 Writing your own check plug-ins and some newer plugins I found.
I’d like to mainly focus on the “newer” plugin, even if I got further using the old one.
We are using Version 2.0.0p17 (CEE)

from .agent_based_api.v1 import *

def check_firepower_psu(item, section):
    for domain, status in section:
        Message = ""
        status = int(status)
        if domain == item:
            if status == 1:
                checkstate = State.OK
                Message ="Is operational"
            elif status == 0:
                checkstate = State.CRIT
                Message ="Not operational"
            else:
                Message = "Unknown Status"
                status = State.UNKNOWN
            yield Result(state=checkstate, summary=Message)
        return

def inventory_firepower_psu(section):
    for list in section:
        yield Service(item=list[0])


register.check_plugin(
    name="firepower_snmp_plugin_psu",
    service_name="Operability PSU %s",
    discovery_function = inventory_firepower_psu,
    check_function = check_firepower_psu,
)

register.snmp_section(
    name = "Firepower_PSU_Operability",
    detect = contains(".1.3.6.1.2.1.1.1.0", "fxos"),
    fetch = SNMPTree(
        base = ".1.3.6.1.4.1.9.9.826.1.20.109.1",
        oids = [
            "2", #2 ist Domäne des PSU
            "10", #10 ist Operability des PSU
        ],
    ),
)

The problem I’m having is that it does not register any services for the actual system that needs the Plugin and even if I change the detection to:
detect=exists(".1.3.6.1.2.1.1.1.0")
and generate a test service in the inventory function, it doesn’t detect a new service on any device.
On the older plugin the service discovery works but i either get a check crash or “No item found in monitoring data”
An example output i got using the older plugin and and pprint in the inventory function is:

[['sys/chassis-1/psu-1', '1'], ['sys/chassis-1/psu-2', '1']]

I tried debugging it with different pprint’s but I dont get any output on the CLI.
Can anybody help me with this or tell me how to effectively debug my Plugin?
Thank you

Welcome,

try a snmpget from the checkmk server to the device with the snmp section: (using snmp 2 with public community here))

snmpget -v2c -c public YOURDEVICEIPHERE 1.3.6.1.2.1.1.1.0

you should get something like:
SNMPv2-MIB::sysDescr.0 = STRING: Saia Burgess Controls - Saia PCD Operating System

(thats a leakage Sensor in my case) yours should contain “fxos” somewhere in the string to detect a Device

Hello Holger,
i indeed get a response with fxos inside:

SNMPv2-MIB::sysDescr.0 = STRING: Cisco FX-OS(tm) fxos, Software (fxos-k9-system), Version 5.0(3)N2(4.101), Interim version 5.0(3)N2(4.101., RELEASE SOFTWARE Copyright (c) 2002-2021 by Cisco Systems, Inc.   Compiled 8/6/2021 2:00:00

and the OID exists so even if I just check if it exist the plugin should atleast try to apply here.

ok, that line was just to check if the section was called, now on the checkmk server:

cmk --debug -IIv --detect-plugins YOURSCRIPTNAME YOURHOSTNAME

YOURHOSTNAME exactly as it is in checkmk (upper/lowercase matters)

this will try a service Discovery on the host with debug options

looks like there is a difference in the snmp section name and the check_plugin name.

register.check_plugin(
    name="firepower_snmp_plugin_psu",
)

register.snmp_section(
    name = "Firepower_PSU_Operability",
)

This names have to match exacly.

register.check_plugin(
    name="firepower_snmp_plugin_psu",
)

register.snmp_section(
    name = "firepower_snmp_plugin_psu",
)

or you can add the snmp sections your check should use in the register.check_plugin like this

register.snmp_section(
    name = "Firepower_PSU_Operability",
    sections = ["firepower_snmp_plugin_psu"],
)

The second issue is, your plugin is missing a parse function.

def parse_firepower_psu(string_table):
    section = string_table
    # put in here your code to parse the input data for the check function
    return section

register.snmp_section(
    parse_function=parse_firepower_psu,
)

Third issue is with the check function, in the else statement status = State.UNKNOWN should be checkstate = State.UNKNOWN

cheers
Thomas

1 Like

Hello Thomas,
Thank you very much for your input I got it to work with the same names in the register(). Never occured to me that they are references to each other :sweat_smile:
Obviously needs some work to round out the edges but that should be no problem,
Thank you very much for your help you both :grinning: