CMK version:: 2.4.0p2
OS version: : docker
Error message:
Loading "rulespec/meraki_agent" failed: cmk_addons.plugins.meraki.rulesets.meraki_agent:rule_spec_cisco_meraki: plug-in 'cisco_meraki' already defined at cmk.plugins.cisco.rulesets.meraki:rule_spec_cisco_meraki
During the migration of the extended Cisco Meraki Special Agent to CMK2.4, I ran into the problem that I can no longer shadow the built-in ruleset.
built-in ruleset
/omd/sites/cmk/lib/python3/cmk/plugins/cisco/rulesets/meraki.py
shadow dummy file
/omd/sites/cmk/local/lib/python3/cmk/plugins/cisco/rulesets/meraki.py
new ruleset
/omd/sites/local/lib/python3/cmk_addons/plugins/meraki/rulesets/meraki_agent.py
If I move the new ruleset to
/omd/sites/cmk/local/lib/python3/cmk/plugins/cisco/rulesets/meraki.py
the error is gone, but the new ruleset is not used (not even after omd restart [apache]).
So the question is, how can i replace a built-in ruleset in CMK2.4.x, without deleting the original files?
Cheers
Thomas
2 Likes
I think the problem from @thl-cmk is a little more widespread in the latest CMK releases.
Today i encountered the following problem/error with shadowing files.
I tried to fix a bug inside the Nutanix checks.
Original file location.
lib/python3/cmk/plugins/prism/agent_based/
If i copy the check where i want to fix the bug to
local/lib/python3/cmk/plugins/prism/agent_based/
it is completely ignored (no pycache directory is created)
no error message nothing only ignored
If I copy the file to another location then i will get an error.
Here an example where i tried to put the changed file inside the “cmk_addons” folder structure.
ValueError: cmk_addons.plugins.prism.agent_based.prism_vm_stats:check_plugin_prism_vm_stats: plug-in 'prism_vm_stats' already defined at cmk.plugins.prism.agent_based.prism_vm_stats:check_plugin_prism_vm_stats
@martin.hirschvogel this problem has an very huge impact on all who try to fix bugs. It is not really possible at the moment.
Will ask a developer to take a look into it. Thanks!
1 Like
In general it is correct that you can shadow built-in plugins by placing your files under
local/lib/python3/cmk/plugins
(although do so at your own risk).
Trying to replace them via cmk_addons will not work, as you saw.
The issue here is that the plugins you are trying to shadow contain an __init__.py at the “family” (cisco, prism) folder level.
This is something we want for our internal development (due to issues with e.g. our test framework), but also causes python to only recognize the built-in lib/python3/cmk/plugins/<family>.
You can place an __init__.py file at the same place in the local folder (local/lib/python3/cmk/plugins/<family>/__init__.py ) to override that.
However this means that the builtin plugin is completely shadowed, so any other built-in functionality in the built-in family folder will be missing unless you copy them over to your local folder.
Instead of copying over the whole folder, an old approach to namespace packages should work as well:
In your local/lib/python3/cmk/plugins/<family>/__init__.py add
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
@Rebekka just tried the variant with __init__.py. Unfortunately no success.
No error messages, but unfortunately the built-in rule set is still loaded and not my extended set. omd restart apache and also a complete restart (omd restart) does not help.
My init file:
OMD[cmk]:~$ cat local/lib/python3/cmk/plugins/cisco/__init__.py
#!/usr/bin/env python3
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
Cheers
Thomas
second try, with a empty __init__.py → works. The other rulesets in this folder are still there (not shadowed) . In my case i.e. the cisco_prime special agent. To me this looks ok.
Crosschecked witch Checkmk 2.3., here are all plugins in the shadowed folder gone if i use an empty __init__py. With a non empty init file the shadowing works as expected. So the oposite to Checkmk 2.4.
Is there any way to have one solution for both Checmk versions?
1 Like
@Rebekka looks like you need to add the __init__.py in every subdirectory starting with ~local/lib/python3/cmk/plugins/<family>. In my case
~local/lib/python3/cmk/plugins/cisco/__init__.py
~local/lib/python3/cmk/plugins/cisco/rulesets/__init__.py
~local/lib/python3/cmk/plugins/cisco/server_side_calls/__init__.py
This way its working with CMK2.3 and CMK 2.4 without overshadowing.
Looks like i can finaly finish the migration of the extended Meraki agent to CMK 2.4.
Thanks
Thomas
2 Likes
Thanks Thomas and Rebekka 