Need help for a custom Quantum tape library SNMP script

Hello fellow CheckMK users,

I’m fairly new to CheckMK and Python, but I am trying to write some scripts that can monitor Quantum’s RAS tickets or retrieve other information from the tape library via SNMP.

After doing some research, I am still unable to identify the errors causing the script to fail in creating the services. That’s why I’m asking for your guidance to point me in the right direction.

This script should create a new service for each existing RAS ticket and display the contents of the ticket.

from .agent_based_api.v1 import (
    register,
    startswith,
    Result,
    Service,
    SNMPTree,
    State,
)

def discover_quantum(section):
    for eventTicketID, eventTicketDateTime, eventTicketName, eventTicketDescription, eventTicketSeverity in section:
        yield Service()

def checkTicketContent(section):             #Ticket content auslesen und angeben
    for eventTicketID, eventTicketDateTime, eventTicketName, eventTicketDescription, eventTicketSeverity in section:
        if eventTicketSeverity == 1:
            yield Result(state = State.CRIT, summary=f"{eventTicketID} / {eventTicketDateTime} / {eventTicketName} / {eventTicketDescription} / {eventTicketSeverity}") #Severity critical
        elif eventTicketSeverity == 3 or eventTicketSeverity == 0 or eventTicketSeverity == 2 or eventTicketSeverity == 4:
            yield Result(state = State.WARN, summary=f"{eventTicketID} / {eventTicketDateTime} / {eventTicketName} / {eventTicketDescription} / {eventTicketSeverity}") #Severity unknown/degraded/attention
        else:
            yield Result(state = State.OK, summary=f"{eventTicketID} / {eventTicketDateTime} / {eventTicketName} / {eventTicketDescription} / {eventTicketSeverity}") #Severity informational
    return


register.snmp_section(
    name = "QuantumRAS",
    detect = all_of(
        startswith(".1.3.6.1.2.1.1.1.0", "Linux library 4.9.243") #SysDesc OID, "Linux library 4.9.243" ist die Beschreibung der Quantum Scalar i3
    ),
    fetch=[ 
        SNMPTree(
            base=".1.3.6.1.4.1.3697.1.10.15.5.50.10.2.1",
            oids = [
            "2", #TicketID
            "3", #DateTime
            "5", #Name
            "6", #Description
            "7" #Severity
            ]
        )   
    ] 
)

register.check_plugin(
    name="QuantumRAS",
    sections=["Quantum_RAS_Ticket"],
    service_name="RAS Ticket",
    discovery_function=discover_quantum,
    check_function=checkTicketContent
)

I understand that the code is not optimal and there are likely many mistakes, but please keep in mind that I just started learning Python yesterday.

I am grateful for any help that i can receive.

@niklast welcome to the forum :slight_smile:

i think you should remove the sections line from your register.check_plugin function.

register.check_plugin(
    name="QuantumRAS",
    service_name="RAS Ticket",
    discovery_function=discover_quantum,
    check_function=checkTicketContent
)

you need this only if yor check expects more than one section or
if the section name differs from the check name.

1 Like

Hi, thank you for your advice!

I’ve implemented the advice into my scripts, but I’m still unable to make the checks appear after a discovery.

Is there a way to troubleshoot via the CLI and check if the script is being loaded?

EDIT:
When I use the command “cmk --detect-plugins=QuantumRAS -vI Quantum_iScalar_3”, I receive:

  • ANALYSE DISCOVERED HOST LABELS
    SUCCESS - Found no new host labels
  • ANALYSE DISCOVERED SERVICES
  • EXECUTING DISCOVERY PLUGINS (0)

Therefore, I suppose there might be an issue with the discovery check?

EDIT 2:
When using the command “cmk -L”, the plugin doesn’t appear. Now I suspect there is a problem with the register.check_plugin function. :roll_eyes:

best regards,
Niklas

Found the issue, it was the checkTicketContent function. :slight_smile: