Migrate metric info to Checmk 2.3 directory layout for plugins (cmk_addons)

CMK version: 2.3.0p24
OS version: Ubuntu 22.04

$ cmk-update-config --debug
cmk_addons.plugins.abc.graphing.abc_metrics:metric_info: {'uncommitted': {'title': l'Uncommitted', 'unit': 'bytes', 'color': '16/a'}, 'overprovisioned': {'title': l'Overprovisioned', 'unit': 'bytes', 'color': '24/a'}, 'precompiled': {'title': l'Precompiled', 'unit': 'bytes', 'color': '16/a'}, 'codewords_corrected': {'title': l'Corrected codewords', 'unit': '%', 'color': '#ff8040'}, 'codewords_uncorrectable': {'title': l'Uncorrectable codewords', 'unit': '%', 'color': '#ff4020'}, 'xda_hitratio': ....
Your site has not been modified.
The update can be retried after the error has been fixed.

cmk-update-config without --debug does not generate the line “The update can not be retried after the error has been fixed.”

I upgraded from 2.3.0p12 to 2.3.0p24.

I migrated a plugin to the new directory structure of Checkmk 2.3. Thus I created ~/local/lib/python3/cmk_addons/plugins/abc/agent_based/ and put my plugin in it. This works fine.

But I have another plugin which consists only of one metric definition file. This file defines two metric_info and two graph_info dictionaries. So, I created the dir. ~/local/lib/python3/cmk_addons/plugins/abc/graphing/ and put the metric definition script in it.

Now when I run “cmk-update-config --debug” I get huge dictionary output complaining about metric_info.

The checkmk instance can be started and all looks good.

I also tried putting the metric file into ~/local/lib/python3/cmk_addons/plugins/abc/metrics/. Now “cmk-update-config --debug” does not produce the huge output followed by the error message, but the metrics definition is not recogniced. Because in the Checkmk graph (in the browser UI) I don’t get the title of the graph from the metrics pluging. But I get the title as the variable name. The metric data are comming from an agent plugin. And the title is the variable name from the agent plugin with capialized first letters. For example var_name_of_metric becomes Var_Name_Of_Metric in the graph.

Does anybody know how to migrate metric_info[“…”] = {…} and graph_info[“…”] = {…} to the new directory layout (cmk_addons) of Checkmk 2.3.

–
Erwin

Hi,

correction:

The metric works and it is shown correctly in the browser UI. The title from the metrics definition file in ~/local/lib/python3/cmk_addons/plugins/abc/graphing/ is used.

But “cmk-update-config --debug” produces the error message (see above). But actually it is not an error. I guess I’m missing a convention introduced in Checkmk 2.3.

–
Erwin

Hi there,

i have also been playing around with plugins, but i stepped in on it directly on the CMK 2.3 layout, so i might be wrong.
When i look at the error the json-array looks weird to me:

image

Everything else is in single quotes, apart from that which i highlighted.

So how is this defined in your metrics ?

i mean, as an example from a metric-file i have (dirstructure cmk 2.3):

# Metrics for LDAP traffic
metric_inbytes = metrics.Metric(
    name="TrafficVolume_inBytes",
    title=Title("LDAP traffic bytes in"),
    unit=metrics.Unit(metrics.IECNotation("bytes")),
    color=metrics.Color.BROWN,
)

Side-note:
While upgrading from CRE 2.3.0p23 → 2.3.0p24 i detected/saw an error passing by on a special agent plugin i have been working on, but it did not fatal on the upgrade:

cmk_addons.plugins.edirectory_monitor.graphing.metrics: DecimalNotation.__init__() missing 1 required positional argument: 'symbol'

After looking over my metric file and comparing to plugin api docs it was missing the double-quotes :

unit=metrics.Unit(metrics.DecimalNotation()),

So changed it to:

unit=metrics.Unit(metrics.DecimalNotation("")),

re-ran cmk-update-config --debug, and the seen error is gone ^^

  • Glowsome
1 Like

Hi,

from scratch.

I reproduced the issue.

Local check:


$cat /usr/lib/check_mk_agent/local/xhost_cmk23_test
#!/usr/bin/bash
value=$(echo $RANDOM | cut -c1-2)
echo 0 xhost_cmk23_test the_value=$value Test metrics plugin in CMK 2.3

Metric Plugin:

$ cat local/lib/python3/cmk_addons/plugins/xhost/graphing/xhost_metrics.py 
#!/usr/bin/env python3

from cmk.gui.graphing._utils import  metric_info

metric_info["the_value"] = {
    "title": "The value of value",
    "unit": "count",
    "color": "13/a",
}

$ omd apache restart

The local check and the metric plugin works. The graph in the GUI
is showing “The value of value” as the title of the metric.

NOW THE ISSUE:

$ omd stop
$ cmk-update-config --debug

ATTENTION
Some steps may take a long time depending on your installation.
Please be patient.

Cleanup precompiled host and folder files
Verifying Checkmk configuration…

Traceback (most recent call last):
  File "/omd/sites/newmoni/lib/python3/cmk/update_config/main.py", line 101, in main_check_config
    check_config(logger, conflict)
  File "/omd/sites/newmoni/lib/python3/cmk/update_config/main.py", line 238, in check_config
    with disable_redis(), gui_context():
  File "/omd/sites/newmoni/lib/python3.12/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/omd/sites/newmoni/lib/python3/cmk/gui/utils/script_helpers.py", line 66, in gui_context
    app = session_wsgi_app(testing=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/newmoni/lib/python3/cmk/gui/utils/script_helpers.py", line 31, in session_wsgi_app
    return make_wsgi_app(debug=debug, testing=testing)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/newmoni/lib/python3/cmk/gui/wsgi/app.py", line 71, in make_wsgi_app
    app.register_blueprint(rest_api)
  File "/omd/sites/newmoni/lib/python3.12/site-packages/flask/sansio/scaffold.py", line 46, in wrapper_func
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/newmoni/lib/python3.12/site-packages/flask/sansio/app.py", line 599, in register_blueprint
    blueprint.register(self, options)
  File "/omd/sites/newmoni/lib/python3.12/site-packages/flask/sansio/blueprints.py", line 335, in register
    deferred(state)
  File "/omd/sites/newmoni/lib/python3.12/site-packages/flask/sansio/blueprints.py", line 242, in wrapper
    func(state)
  File "/omd/sites/newmoni/lib/python3/cmk/gui/wsgi/blueprints/rest_api.py", line 43, in rest_api_first_request
    main_modules.load_plugins()
  File "/omd/sites/newmoni/lib/python3/cmk/gui/main_modules.py", line 78, in load_plugins
    _call_load_plugins_hooks(main_modules)
  File "/omd/sites/newmoni/lib/python3/cmk/gui/main_modules.py", line 184, in _call_load_plugins_hooks
    module.load_plugins()
  File "/omd/sites/newmoni/lib/python3/cmk/gui/metrics.py", line 71, in load_plugins
    add_graphing_plugins(load_graphing_plugins())
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/newmoni/lib/python3/cmk/gui/graphing/_loader.py", line 47, in load_graphing_plugins
    ] = discover_plugins(
        ^^^^^^^^^^^^^^^^^
  File "/omd/sites/newmoni/lib/python3/cmk/discover_plugins/_python_plugins.py", line 56, in discover_plugins
    collector.add_from_module(mod_name, _import_optionally)
  File "/omd/sites/newmoni/lib/python3/cmk/discover_plugins/_python_plugins.py", line 204, in add_from_module
    self._collect_module_plugins(mod_name, vars(module))
  File "/omd/sites/newmoni/lib/python3/cmk/discover_plugins/_python_plugins.py", line 222, in _collect_module_plugins
    self._handle_error(TypeError(f"{location}: {value!r}"))
  File "/omd/sites/newmoni/lib/python3/cmk/discover_plugins/_python_plugins.py", line 237, in _handle_error
    raise exc
TypeError: cmk_addons.plugins.xhost.graphing.xhost_metrics:metric_info: {'uncommitted': {'title': l'Uncommitted', 'unit': 'bytes', 'color': '16/a'}, 'overprovisioned': {'title': l'Overprovisioned', 'unit': 'bytes', 'color': '24/a'}, 'precompiled': {'title': l'Precompiled', 'unit': 'bytes', 'color': '16/a'}, 'codewords_corrected': {'title': l'Corrected codewords', 'unit': '%', 'color': '#ff8040'}, 'codewords_uncorrectable': {'title': l'Uncorrectable codewords', 'unit': '%', 'color': '#ff4020'}, 'xda_hitratio': {'title': l'XDA hitratio', 'unit': '%', 'color': '#0ae86d'}, 'data_hitratio': {'title': l'Data hitratio', 'unit': '%', 'color': '#2828de'}, ......
Update aborted with Error: cmk_addons.plugins.xhost.graphing.xhost_metrics:metric_info: {'uncommitted': {'title': l'Uncommitted', 'unit': 'bytes', 'color': '16/a'}, 'overprovisioned': {'title': l'Overprovisioned', 'unit': 'bytes', 'color': '24/a'}, 'precompiled': {'title': l'Precompiled', 'unit': 'bytes', 'color': '16/a'}, 'codewords_corrected': {'title': l'Corrected codewords', 'unit': '%', 'color': '#ff8040'}, 'codewords_uncorrectable': {'title': l'Uncorrectable codewords', 'unit': '%', 'color': '#ff4020'}, 'xda_hitratio': {'title': l'XDA hitratio', 'unit': '%', 'color': '#0ae86d'}, 'data_hitratio': {'title': l'Data hitratio', 'unit': '%', 'color': '#2828de'}, ......
Your site has not been modified.
The update can be retried after the error has been fixed.

Try the following instead of your code, which is as described in the CheckMK Plugin APIs documentation.

#!/usr/bin/env python3

from cmk.graphing.v1 import metrics, Title

metric_the_value = metrics.Metric(
    name="the_value",
    title=Title("The value of value"),
    unit=metrics.Unit(metrics.DecimalNotation("")),
    color=metrics.Color.BLUE, # i have not yet played with color-codes, so i just picked a color 
)
  • Glowsome
2 Likes

Hi Michael,

thank you very much. Now it works as expected.

–
Erwin