check-unifi-controller icon indicating copy to clipboard operation
check-unifi-controller copied to clipboard

Deprication for cmk 2.4.0

Open FirstS0ul opened this issue 7 months ago • 1 comments
trafficstars

Image

FirstS0ul avatar Apr 04 '25 09:04 FirstS0ul

Same problem here - looking forward to an upgrade of the package :)

47k avatar May 06 '25 10:05 47k

Are there any news about support for checkmk 2.4?

martux69 avatar May 27 '25 19:05 martux69

Over the last couple of days I've spent the time to convert this check to the 2.3.0 API that's also used for 2.4.0. On top of that I've added a couple of fixes that we had to implement quite a while ago; otherwise there would have been crashes/certain devices not being recognized etc. You can find that effort in my fork.

I have not published an MKP for the converted version, neither directly in the repo nor on the CheckMK Exchange. I have no plans of doing so either as I'm simply not interested in being a maintainer for the plugin. I solely offer the conversion so that other maintainers, be it bashclub or new ones, can save themselves a lot of time. Take it, do whatever you want with it. I'm perfectly fine with my changes being licensed under the MIT, same as the original plugin.

Please note that I've only tested this on my 2.3.0 instances, not on an actual 2.4.0 instance. I have verified that when creating an MKP from the files CheckMK doesn't show deprecation warnings for the extension package just created.

If anyone wants to test my converted variant, rough installation instructions are:

  • uninstall the existing plugin
  • shut down the site
  • copy the lib structure into the site's local directory so that you'll end up with /omd/sites/<site>/local/lib/python3/cmk/plugins/unifi/…
  • as the site's user run cmk-update-config (not sure if this is strictly required)
  • start the site

mbunkus avatar May 31 '25 15:05 mbunkus

With 2.4.0 the fork solution does not work for me:

cmk --debug -vvn xxxxxxxx
Trying to acquire lock on /omd/sites/monitor/var/check_mk/crashes/base/bddbb6c6-4c69-11f0-b0a0-bc24118d04ac/crash.info
Got lock on /omd/sites/monitor/var/check_mk/crashes/base/bddbb6c6-4c69-11f0-b0a0-bc24118d04ac/crash.info
Releasing lock on /omd/sites/monitor/var/check_mk/crashes/base/bddbb6c6-4c69-11f0-b0a0-bc24118d04ac/crash.info
Released lock on /omd/sites/monitor/var/check_mk/crashes/base/bddbb6c6-4c69-11f0-b0a0-bc24118d04ac/crash.info
Traceback (most recent call last):
  File "/omd/sites/monitor/lib/python3/cmk/discover_plugins/_python_plugins.py", line 217, in add_from_module
    module = importer(mod_name, raise_errors=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/monitor/lib/python3/cmk/discover_plugins/_python_plugins.py", line 178, in _import_optionally
    return importlib.import_module(module_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/monitor/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 999, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/omd/sites/monitor/local/lib/python3/cmk_addons/plugins/unifi_controller/agent_based/unifi_controller.py", line 45, in <module>
    from .utils import interfaces
ModuleNotFoundError: No module named 'cmk_addons.plugins.unifi_controller.agent_based.utils'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/omd/sites/monitor/bin/cmk", line 135, in <module>
    errors = config.load_all_plugins(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/monitor/lib/python3/cmk/base/config.py", line 1421, in load_all_plugins
    errors = agent_based_register.load_all_plugins(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/monitor/lib/python3.12/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/monitor/lib/python3/cmk/base/api/agent_based/register/_discover.py", line 67, in load_all_plugins
    discovered_plugins: DiscoveredPlugins[_ABPlugins] = discover_all_plugins(
                                                        ^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/monitor/lib/python3/cmk/discover_plugins/_python_plugins.py", line 55, in discover_all_plugins
    return discover_plugins_from_modules(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/omd/sites/monitor/lib/python3/cmk/discover_plugins/_python_plugins.py", line 70, in discover_plugins_from_modules
    collector.add_from_module(mod_name, _import_optionally)
  File "/omd/sites/monitor/lib/python3/cmk/discover_plugins/_python_plugins.py", line 220, in add_from_module
    self._handle_error(exc_sub)
  File "/omd/sites/monitor/lib/python3/cmk/discover_plugins/_python_plugins.py", line 259, in _handle_error
    raise exc
ModuleNotFoundError: cmk_addons.plugins.unifi_controller.agent_based.unifi_controller: No module named 'cmk_addons.plugins.unifi_controller.agent_based.utils'

martux69 avatar Jun 18 '25 17:06 martux69

@martux69 on my test instance running 2.4.0p6.cce my current code works fine. Furthermore, the current code I'm hosting does not contain the code from .utils import interfaces anymore. Meaning what you're running is not strictly my forked & updated version.

mbunkus avatar Jul 05 '25 13:07 mbunkus

To be clear: when running find /opt/omd/sites/<sitename>/local -name "*unifi*" you should only find hits in the directory /opt/omd/sites/<sitename>/local/lib/python3/cmk/plugins/unifi and below that, not anywhere else. The 2.4.0 compatible plugin only resides in that folder.

mbunkus avatar Jul 05 '25 13:07 mbunkus

Works fine on 2.4.0p8. Thanks a lot.

spenneb avatar Jul 23 '25 12:07 spenneb

I've moved my fork over to Codeberg. Additionally I've built an MKP for you to use & added it there as a release. Even better, I've uploaded that one to the CheckMK exchange (where it currently awaits approval). I intend to update it with any fixes I need to apply myself for our own needs. Apart from that I still make no guarantee for further development.

mbunkus avatar Jul 25 '25 08:07 mbunkus

My package has been approved over on the CheckMK exchange & can be downloaded from there now, too.

mbunkus avatar Jul 29 '25 09:07 mbunkus

Thanks a lot @mbunkus ! Was finally able to install it. Does someone use multi-sites and is able to show the monitoring data beside the one site configured in a rule? I tried a second rule with another site name but I think I got this wrong in my head.

Also I wonder how I can monitor the access point directly with an host object. Maybe there is some documentation needed (have I overseen something?)

Thanks again and have a nice weekend. Helped me a lot to get the main site implemented!

EDIT: I found out how to do it. I implemented it with the newest version from @mbunkus 20250814.16.45 from here: https://exchange.checkmk.com/p/linet-unifi-controller

  1. Create an unifi host somewhere in checkmk with "configured api integrations, no checkmk agent" enabled.
  2. Add a rule under Setup > Agents > Other integrations > Unifi Controller via API
  3. Add API Username, API Password, Port, "Ignore certificate validation" (and tick the second checkbox also!), Enable "Receive Piggyback data by IP". Please note that I created a User on my unifi controller that has read only access to my unifi controller. Its working fine. And dont forget to set the explicit host to the unifi host. To use multi site leave site unticked and empty!
  4. Add a subfolder "unifi" somewhere (optional to make options easier) and enable "no api integrations, no checkmk agents" and "always use and expect piggyback data" under piggyback.
  5. After that create hosts per unifi device in this subfolder and be aware that you need to set the IP accordingly to the ip in unifi. hostname: hostname.sub.domain.tld, alias: hostname.sub.domain.tld, ip: 192.168.1.2 (eg).

Note: It is also possible to use hostname for piggyback. The hostname of the unifi device in checkmk needs to be the same as shown in unifi itself. For me it wasnt a good idea because I have multiple "ap01", one per site for example.

Pro Tip: You can add multiple devices by adding them via csv and do a bulk discovery.

hostname;ip address;alias; hostname.sub.domain.tld; 192.168.1.2; hostname.sub.domain.tld;

Hope that helps someone!

Atomique avatar Aug 22 '25 13:08 Atomique

Personally I create host objects without an IP (as in: on the folder containing all the APs I set "IP address family" to "no IP") for each AP, configure piggyback to go via host names & then (if needed) a "host name translation for piggyback hosts" rule to match the two sides (names as they come out of the controller & as I've just created them in CheckMK), and finally a rule that configures the "host check command" for that folder to "always up". That way it works regardless of the IPs actually assigned to the APs. When an AP is actually offline you still get a CRIT via the service Device Status which switches to Status: disconnected.

mbunkus avatar Sep 26 '25 14:09 mbunkus

Hi @mbunkus ,

thanks for working on that extension.

One comment from me: You should change the path from $OMD_ROOT/local/lib/python3/cmk/plugins to $OMD_ROOT/local/lib/python3/cmk_addons/plugins. The first is for overriding builtin checks, the second for your own extensions.

gurubert avatar Sep 26 '25 15:09 gurubert

@gurubert yeah I know, already planned for when I do the next releases of each plugin.

All: please file any further comments on/issues with my maintained package over on Codeberg. I won't monitor this one anymore.

mbunkus avatar Sep 26 '25 15:09 mbunkus