Eigener SNMP Check: UNKN - Item not found in SNMP data

Moin Zusammen

ich probiere gerade einen SNMP Check zur Überwachung von Lancom WLC zu schreiben. Gleichzeitig ist es für mich das erste Mal mit python…
Inventory und Parse läuft in meinen Augen fein. Im Check ist noch etwas fault, ich bekomme nämlich immer o.g. Fehler und stehe etwas auf dem Schlauch. Vielleicht kann mur jemand einen Schubs in die richtige Richtung geben…

Inventory Function:

def inventory_lancom_wlc_ap_status(parsed):
   return [(None, None)]

Parse:

def parse_lancom_wlc_ap_status(info):    
    parsed = {
            "expected": int(info[0][0]),
            "connectedExpected": int(info[0][1]),
            "connectedManaged": int(info[0][2]),
            "connectedNew": int(info[0][3])
        }
    return parsed

Check:
d

ef check_lancom_wlc_ap_status(item, params, parsed):
	
	perf = [("Expected AP",parsed['expected'], parsed['expected'] + ":" + parsed['expected'] )]
	
	statustext = "Accesspoints expected: %d; Accespoints connected %d; Accespoints connected and managed: %d; new Accespoints: %d;" % (parsed['expected'], parsed['connectedExpected'], parsed['connectedManaged'], parsed['connectedNew'])

	
	if parsed['expected'] == parsed['connectedExpected']:
		status = 0
	elif parsed['connectedNew'] >= 0:
		status = 1
	else:
		status = 2
		
	return status, statustext, perf

Config:

check_info["lancomwlc"] = {
    "inventory_function":   inventory_lancom_wlc_ap_status,
	#"inventory_function":   discover(),
	"parse_function": 		parse_lancom_wlc_ap_status,
    "check_function":       check_lancom_wlc_ap_status,
    "service_description":  "LANCOM WLC AP Status",
    "snmp_scan_function":   lambda oid: "WLC-1000" in oid(".1.3.6.1.4.1.2356.11.1.47.6.0"),
    "snmp_info":            ( ".1.3.6.1.4.1.2356.11.1.73", 
								[
								"5", # lcsStatusWlanMngmtExpectedAp
								"6", # lcsStatusWlanMngmtConnectedExpectedAp
								"7", # lcsStatusWlanMngmtConnectedManagedAp
								"8"  # lcsStatusWlanMngmtConnectedNewAp
								]),
    "has_perfdata":         True,
    "group":                "lancomwlc",
}

Die Parse Funktion gibt wie gewollt folgendes zurück:
{'expected': 37, 'connectedManaged': 35, 'connectedExpected': 35, 'connectedNew': 0}

Mir fehlt irgendwie der Ansatz…

Randinfo: Wir sind noch auf der 1.6…

@BuzzLightyear habe mir deinen Check mal ein wenig angesehen. Was mir aufgefallen ist, ist das du Tabs und Leerzeichen verwendes für die Idents, das mag Python gar nicht. Ersetze bitte mal alle Tabs durch 4xLeerzeichen und probiere es dann noch einmal. Du kannst auch auf der CLI mit cmk --debug -vII <hostname> testen ob CMK irgendwelche Fehler wirft. Da müssten Fehler in der Art kommen

    statustext = "Accesspoints expected: %d; Accespoints connected %d; Accespoints connected and managed: %d; new Accespoints: %d;" % (
    ^
IndentationError: unexpected indent

Ansonsten kanst du zum Testen auch in der Inventory und Check Funktion ein print(parsed) einbauen um zu sehen ob CMK bis zu diesen Funktionen kommt und die korrekten Daten übergibt.

Der zweite Punkt der Fehlt ist der “Python Header” ganz am Anfang der Datei

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
1 Like

Moin,
danke für die Hinweise mit den Tabstops. Da ist man von anderen Sprachen einfach sehr dran gewöhnt, ich gelobe Besserung. :wink:
Seltsamerweise läuft die Inventory Funktion sauber durch, lancomwlc wird wie gewünscht einmal gefunden.
Erst danach sagt er dann beim Ergebis des checks den o.g. Fehler. Daraus resultieren fliegt der Check natürlich als vanished wieder raus :confused:

Ich werde die Tage mal ein paar weiter Debug Outputs dazupacken. Vi

Moin,

ich habe die Tabs einmal entfernt und ich auch wenig gespielt. Im Iventory habe ich das gewünschte Ergebnis.

OMD[clage]:~/local/share/check_mk/checks$ cmk -v -II XXXXXX
Discovering services on: XXXXXX
XXXXXX:
+ FETCHING DATA
 [snmp] Execute data source
+ EXECUTING DISCOVERY PLUGINS (8)
  1 hr_cpu
  1 hr_mem
  2 if_lancom
  1 lancomwlc
  1 snmp_info
  1 snmp_uptime

Wenn ich über WATO suche, dann steht er direkt unten drin, allerdings mit einem UNKN Status…

Hier noch einmal der komplette Check:

#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-

# (c) 2022 Gesellschaft für Digitale Werte mbH
#          Heiner Ohm <heiner.ohm@digitale-werte.com>

# This is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# tails. You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.


def inventory_lancom_wlc_ap_status(parsed):    
    return [(None, None)]


def parse_lancom_wlc_ap_status(info):    
    parsed = {
            "expected": int(info[0][0]),
            "connectedExpected": int(info[0][1]),
            "connectedManaged": int(info[0][2]),
            "connectedNew": int(info[0][3])
            }
    return parsed


@get_parsed_item_data
def check_lancom_wlc_ap_status(item, params, parsed):
    
    perf = [("Expected AP",parsed['expected'], parsed['expected'] + ":" + parsed['expected'] )]
    
    statustext = "Accesspoints expected: %d; Accespoints connected %d; Accespoints connected and managed: %d; new Accespoints: %d;" % (parsed['expected'], parsed['connectedExpected'], parsed['connectedManaged'], parsed['connectedNew'])
    print(statustext)
    
    if parsed['expected'] == parsed['connectedExpected']:
        status = 0
    elif parsed['connectedNew'] > 0:
        status = 1
    else:
        status = 2
        
    return status, statustext, perf
    

    
    
check_info["lancomwlc"] = {
    "inventory_function":   inventory_lancom_wlc_ap_status,
    #"inventory_function":   discover(),
    "parse_function":         parse_lancom_wlc_ap_status,
    "check_function":       check_lancom_wlc_ap_status,
    "service_description":  "LANCOM WLC AP Status",
    "snmp_scan_function":   lambda oid: "WLC-1000" in oid(".1.3.6.1.4.1.2356.11.1.47.6.0"),
    "snmp_info":            ( ".1.3.6.1.4.1.2356.11.1.73", 
                                [
                                "5", # lcsStatusWlanMngmtExpectedAp
                                "6", # lcsStatusWlanMngmtConnectedExpectedAp
                                "7", # lcsStatusWlanMngmtConnectedManagedAp
                                "8"  # lcsStatusWlanMngmtConnectedNewAp
                                ]),
    "has_perfdata":         True,
    "group":                "lancomwlc",
}

Vermutlich ist es total offensichtlich und ich sehe den Baum vor lauter Bäumen nicht…

your check has no item so I think there is no need to use @get_parsed_item_data. Just comment out this line and try again.

1 Like

Als Ergänzung zur Antwort von @thl-cmk kannst auch einen Blick auf eines meiner alten Check Templates werfen. Da wird nur keine Parse Funktion verwendet. Ist aber hier bei dem Problem egal.

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.