Hi all,
I’m trying to write my first check snmp fo check_mk_raw-2.0.0p3, see code belowe
cat local/lib/check_mk/base/plugins/agent_based/damocles_in.py
#!/usr/bin/env python3
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# Damocles
# '.1.3.6.1.4.1.21796.3.4.1.1.3' => Check Name
# '.1.3.6.1.4.1.21796.3.4.1.1.2' => Check Value
# '.1.3.6.1.4.1.21796.3.4.1.1.4' => Alarm ON/OFF
# '.1.3.6.1.4.1.21796.3.4.1.1.6' => Pulse Counter
from .agent_based_api.v1 import *
from pprint import pprint
def parse_damocles_in(string_table):
print(string_table)
return string_table
register.snmp_section(
name = "damocles_in",
detect = startswith(".1.3.6.1.2.1.1.1.0", "Damocles"),
parse_function=parse_damocles_in,
fetch = SNMPTree(
base = '.1.3.6.1.4.1.21796.3.4.1.1',
oids = [
OIDEnd(),
'3', # Sensor Name
'2', # Sensor Value
'4', # Sensor alarm State (ON/OFF)
'6', # Sensor Pulse Counter
],
),
)
doing
cmk --detect-plugins=damocles_in -vnII MY_HOST
the output don’t print “string_table” informations
OUTPUT:
Discovering services and host labels on: MY_HOST
MY_HOST:
+ FETCHING DATA
[SNMPFetcher] Execute data source
No piggyback files for 'MY_HOST'. Skip processing.
No piggyback files for '192.168.70.17'. Skip processing.
[PiggybackFetcher] Execute data source
+ PARSE FETCHER RESULTS
Received no piggyback data
+ EXECUTING HOST LABEL DISCOVERY
+ PERFORM HOST LABEL DISCOVERY
+ EXECUTING DISCOVERY PLUGINS (0)
SUCCESS - Found no services, no host labels
Please can someone get me in the right direction?
Many thanks
There are no “register.check_plugin” in your code.
Without any registered check plugin the rest of the code will do nothing.
The “kentix_devices” check from @r.sander is a good example for a complex SNMP check but also it is not too complex to read
In this check you can see all the sections what are needed.
Thanks Andreas! I finished to write the plugin with all sections needed (I hope).
from .agent_based_api.v1 import *
from pprint import pprint
def parse_damocles_in(string_table):
section = []
for line in string_table:
alarm = int(line[3])
if alarm != 0:
section.append(line)
return section
def discover_damocles_in(section):
for line in section:
yield Service(item=line[1])
def check_damocles_in(item, section):
for id, check, state, enable, pulseCount in section:
if check == item:
perfdata = [("pulseCount", pulseCount, None, None, None)]
if state == "0":
yield Result(state=State.OK)
yield Metric(perfdata)
else:
yield Result(state=State.CRIT)
yield Metric(perfdata)
register.snmp_section(
name = "damocles_in",
detect = startswith(".1.3.6.1.2.1.1.1.0", "Damocles"),
parse_function=parse_damocles_in,
fetch = SNMPTree(
base = '.1.3.6.1.4.1.21796.3.4.1.1',
oids = [
OIDEnd(),
'3', # Sensor Name
'2', # Sensor Value
'4', # Sensor alarm State (ON/OFF)
'6', # Sensor Pulse Counter
],
),
)
register.check_plugin(
name="damocles_in",
service_name="%s",
discovery_function=discover_damocles_in,
check_function=check_damocles_in,
)
Now the cmk command work as expected:
cmk --detect-plugins=damocles_in -vnII IT1-Damocles-Ingresso
Discovering services and host labels on: IT1-Damocles-Ingresso
IT1-Damocles-Ingresso:
+ FETCHING DATA
[SNMPFetcher] Execute data source
No piggyback files for 'IT1-Damocles-Ingresso'. Skip processing.
No piggyback files for '192.168.70.17'. Skip processing.
[PiggybackFetcher] Execute data source
+ PARSE FETCHER RESULTS
Received no piggyback data
+ EXECUTING HOST LABEL DISCOVERY
+ PERFORM HOST LABEL DISCOVERY
+ EXECUTING DISCOVERY PLUGINS (1)
7 damocles_in
SUCCESS - Found 7 services, no host labels
But without “–detect-plugins” it doesn’t:
Discovering services and host labels on: IT1-Damocles-Ingresso
IT1-Damocles-Ingresso:
+ FETCHING DATA
[SNMPFetcher] Execute data source
ERROR: SNMP error
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: .1.3.6.1.4.1.232.2.2.4.2.0
ERROR: SNMP error
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: .1.3.6.1.2.1.25.1.1.0
ERROR: SNMP error
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: .1.3.6.1.4.1.2036.2.1.1.4.0
ERROR: SNMP error
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: .1.3.6.1.4.1.6302.2.1.1.1.0
ERROR: SNMP error
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: .1.3.6.1.4.1.14848.2.1.1.1.0
ERROR: SNMP error
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: .1.3.6.1.4.1.30155.2.1.1.0
No piggyback files for 'IT1-Damocles-Ingresso'. Skip processing.
No piggyback files for '192.168.70.17'. Skip processing.
[PiggybackFetcher] Execute data source
+ PARSE FETCHER RESULTS
Received no piggyback data
+ EXECUTING HOST LABEL DISCOVERY
+ PERFORM HOST LABEL DISCOVERY
+ EXECUTING DISCOVERY PLUGINS (3)
1 snmp_info
1 uptime
SUCCESS - Found 2 services, no host labels
I think one problem is the parse function. This should return a dictionary.
But @moritz is also replying and from the master of check API you can get more information
That strongly indicates that the decive might not be detected. To validate that assumption, try a broader detection (just for debugging!): detect = exists(".1.3.6.1.2.1.1.1.0")
With respect to what @andreas-doehler said: A dictionary would be nicer, IMHO. You could replace the above by section[line[1]] = line , discover yield from *(Service(item=k) for k in section) and in the check use the pattern
data = section.get(item)
if data is None:
return
id_, _, state, enable, pulse_count = data
But: A list should be fine. If you return None, processing stops. As if no data were fetched.
It’s hard to tell from a distance. Are there any other local changes that might be interfering? If so remove them temporarily. What’s the output of cmk --detect-plugins=damocles_in --debug -vvnII IT1-Damocles-Ingresso (note the --debug and the two -vv)?
I think there is something strange with scan function…
Doing “cmk --debug -vvnII IT1-Damocles-Ingresso”
Using cached OID .1.3.6.1.2.1.1.2.0: ‘.1.3.6.1.4.1.21796.3.4’
Using cached OID .1.3.6.1.2.1.1.1.0: ‘Damocles 1208 SNMP Supervisor v1.0.2’
Using cached OID .1.3.6.1.2.1.1.2.0: ‘.1.3.6.1.4.1.21796.3.4’
Using cached OID .1.3.6.1.2.1.1.2.0: ‘.1.3.6.1.4.1.21796.3.4’ SNMP scan found hr_mem poseidon_inputs poseidon_temp snmp_info snmp_os snmp_uptime
PS.: I’m monitoring this device with a custom plugin written for cmk 1.6 which I’m using lambda function:
'snmp_scan_function': \
lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.21796.") or \
oid(".1.3.6.1.2.1.1.1.0").startswith("Damocles"),
I deleted it and now the debug give me un’exeception
cmk --detect-plugins=damocles_in --debug -vvnII IT1-Damocles-Ingresso
Traceback (most recent call last):
File "/omd/sites/infra01_2/lib/python3/cmk/base/config.py", line 1986, in _extract_agent_and_snmp_sections
create_snmp_section_plugin_from_legacy(
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/__init__.py", line 240, in create_snmp_section_plugin_from_legacy
detect_spec = create_detect_spec(
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/convert_scan_functions.py", line 397, in create_detect_spec
_compute_detect_spec(
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/convert_scan_functions.py", line 373, in _compute_detect_spec
return _ast_convert_dispatcher(expression_ast)
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/convert_scan_functions.py", line 320, in _ast_convert_dispatcher
return _ast_convert_bool(arg)
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/convert_scan_functions.py", line 247, in _ast_convert_bool
return all_of(*(_ast_convert_dispatcher(v) for v in bool_ast.values))
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/convert_scan_functions.py", line 247, in <genexpr>
return all_of(*(_ast_convert_dispatcher(v) for v in bool_ast.values))
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/convert_scan_functions.py", line 323, in _ast_convert_dispatcher
return _ast_convert_compare(arg)
File "/omd/sites/infra01_2/lib/python3/cmk/base/api/agent_based/register/section_plugins_legacy/convert_scan_functions.py", line 222, in _ast_convert_compare
assert isinstance(comp_ast.comparators[0], ast.Str)
AssertionError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/omd/sites/infra01_2/bin/cmk", line 79, in <module>
errors = config.load_all_agent_based_plugins(check_api.get_check_api_context)
File "/omd/sites/infra01_2/lib/python3/cmk/base/config.py", line 1415, in load_all_agent_based_plugins
errors.extend(load_checks(get_check_api_context, filelist))
File "/omd/sites/infra01_2/lib/python3/cmk/base/config.py", line 1563, in load_checks
errors = (_extract_agent_and_snmp_sections(validate_creation_kwargs=did_compile) +
File "/omd/sites/infra01_2/lib/python3/cmk/base/config.py", line 2005, in _extract_agent_and_snmp_sections
raise MKGeneralException(exc) from exc
cmk.utils.exceptions.MKGeneralException