How to get SNMP credentials for own check in check_mk 1.6

Hi,

years ago I have custominzed a check to query different snmp values. For this I have to get the snmp credentials in the inventory and check functions. I have done this with function cmk_base.config.snmp_credentials_of(host_name()).
But after updateing my instance form 1.5 to 1.6 I get the error: AttributeError (‘module’ object has no attribute ‘snmp_credentials_of’).

What is the correct function to get the snmp credentials?

there are different way`s

i use the Rule: Acces to Agents -> SNMP credentinals of monitored hosts

and bind them to a label

in the Host config i just need to add the label for getting the credentinals

Greets

Sorry but I don’t understand your way.
I have set the credentials in the properties of the host and need to access the properties in the python script of the check, witch is a customization of the original check_mk check sni_octopuse_trunks:

#.1.3.6.1.4.1.231.7.2.9.3.8.1.3.1  "OpenStage 30"
#.1.3.6.1.4.1.231.7.2.9.3.8.1.3.2  "OpenStage 30"
#.1.3.6.1.4.1.231.7.2.9.3.8.1.3.7  "P. O. T."
#.1.3.6.1.4.1.231.7.2.9.3.8.1.3.9  "S0 extension"
#.1.3.6.1.4.1.231.7.2.9.3.8.1.3.11  "S0 trunk: extern"
#.1.3.6.1.4.1.231.7.2.9.3.8.1.3.13  "<not configured>: extern"
#[...]
#.1.3.6.1.4.1.231.7.2.9.3.8.1.4.11  2
#.1.3.6.1.4.1.231.7.2.9.3.8.1.4.13  1

import netsnmp
import cmk_base.config as config

def inventory_siemenshipath_trunks(info):
    trunkports = [ "S0 trunk:", "CorNet NQ Trunk:" ]
    oidporttypes = netsnmp.VarList(netsnmp.Varbind('.1.3.6.1.4.1.231.7.2.9.3.8.1.3'))
    porttypes = netsnmp.snmpwalk(oidporttypes, Version=2, DestHost=host_name(), Community=config.snmp_credentials_of(host_name()))
    inventory = []
    indexI = 0
    while indexI < len(porttypes):
        for port in trunkports:
            porttype = porttypes[indexI]
            if port in porttype:
                oid = netsnmp.Varbind('.1.3.6.1.4.1.231.7.2.9.3.8.1.1.' + str(indexI+1))
                portindex = netsnmp.snmpget(oid, Version=2, DestHost=host_name(), Community=config.snmp_credentials_of(host_name()))
                oid = netsnmp.Varbind('.1.3.6.1.4.1.231.7.2.9.3.8.1.2.' + str(indexI+1))
                cardindex = netsnmp.snmpget(oid, Version=2, DestHost=host_name(), Community=config.snmp_credentials_of(host_name()))
                portdesc = "%s/%s/%s" % (cardindex[0], portindex[0], porttype)
                inventory.append((portdesc, None))
        indexI += 1
    return inventory


def check_siemenshipath_trunks(item, _no_params, info):
    perfdata = []
    cardindex, portindex, porttype = item.split('/')

    oid = netsnmp.Varbind('.1.3.6.1.4.1.231.7.2.9.3.8.1.4.' + portindex)
    portstates = netsnmp.snmpget(oid, Version=2, DestHost=host_name(), Community=config.snmp_credentials_of(host_name()))

    perfdata = [ ("Active", portstates[0], 1, 0, 0, 2) ]

    if portstates[0] == "1":
        return (2, "Port [%s] is inactive" % porttype, perfdata)
    elif portstates[0] == "2":
        return (0, "Port [%s] is active" % porttype, perfdata)

    return (3, "UNKW - unknown data received from agent", perfdata)

check_info['sni_siemenshipath_trunks'] = {
    'check_function'     : check_siemenshipath_trunks,
    'inventory_function' : inventory_siemenshipath_trunks,
    'service_description': "Trunk %s",
    "has_perfdata"            : True,
    'snmp_scan_function' : lambda oid: "agent for hipath" in \
                                  oid(".1.3.6.1.2.1.1.1.0").lower(),
    'snmp_info'          : [ (".1.3.6.1.4.1.231.7.2.9.3.8.1.4.1", []), ]
}

Hi @deutarthrosehilfe,

as far as i know you don’t need to care about the credential handling in your check. The function snmp_scan_function internally handles all the information, if it’s version 1, 2c or 3, and just gives you back all information from the oids. Just check other SNMP checks within the folder ~site/share/check_mk/checks who to deal with.

Also take a look on the documentation and howto:

https://checkmk.com/cms_devel_check_plugins.html
https://checkmk.com/cms_legacy_devel_snmpbased.html

EDIT:

The info variable in your check and inventory function should already contain all informations you need.

1 Like

Hi @tosch,
that’s right, but the problem is, that if I set snmp_scan_function + snmp_info to get all needed snmp values, check_mk makes so many snmp querys that the check needs over a minute and it makes so many load on my phone system, that I get disconnects from calls. So it was no option to go this way. That was the reason I customized the original check.

Normally the core does a snmpwalk on the monitored hosts. There are rules to overcome this problem with hugh walks and timeouts. It was discussed several times on the english aswell the german mailing list.

Check the rules related to SNMP if they fit your requirements.

@tosch,

I have checked the mailling list a second time, but all I found is that it is not possible to limit the queries in the checkfunction on the result of the scanfunction. That was the reason I make my snmp_get queries in the checkfunction. If I get no way to get the credentials in 1.6, then the only way is to hardcode the credentials in my checkfunction.

It was a better, if I can avoid this.

Please talk to your phone system vendor. They have a non-working SNMP agent.