Hi,
I’ve been reading the documentation page Labels (checkmk.com) on how to create host labels from agent plugins. The parser seems to be very picky, and I think the documentation does not match what is expected.
The documentation page shows the example:
Die Label-Ausgabe ist hierbei als Python Dictionary zu formatieren, wie im folgenden Beispiel:
<<<labels>>>
{"cpu/vendor": "zilog"}
First I tried just printing a python dictionary with print:
<<<labels>>>
{'a': 'b'}
The parser in CheckMk then complains about the single quotes, ok. So I switched to using json.dumps to create output with double quotes that looks exactly like in the example:
<<<labels>>>
{"a": "b"}
Now it fails with the following error:
File "/omd/sites/monitoring/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 6 (char 5)
I then tested around it found it does not like the space behind the colon, so I’m using the following parameters to get it working:
print(json.dumps(labels, separators=(',', ':')))
<<<labels>>>
{"a":"b"}
The parser seems to be really picky here, and I think the correct format should be shown in the documentation. The example from the documentation page does not work.
I did my test on the following version of CheckMk:
Checkmk Cloud Edition 2.2.0p20
License state: Free
Regards,
Sven