bashclub / checkmk-opnsense-agent

73 stars 14 forks source link

Opnsense 24.7 interfaces not recognized anymore #53

Open virus2500 opened 1 month ago

virus2500 commented 1 month ago

Hi,

seems like 24.7 broke the check for interfaces. "Check plug-in received no monitoring data"

when i run root@OPNsense:~ # /usr/local/etc/rc.syshook.d/start/99-checkmk_agent --debug

i get

Traceback (most recent call last):
  File "/usr/local/etc/rc.syshook.d/start/99-checkmk_agent", line 212, in do_checks
    _lines += getattr(self,_check)()
              ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/etc/rc.syshook.d/start/99-checkmk_agent", line 565, in check_net
    if _interface_dict["flags"] & 0x2 or _interface_dict["flags"] & 0x10 or _interface_dict["flags"] & 0x80: ## nur broadcast oder ptp .. und noarp
       ~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'flags'
<<<check_mk>>>
AgentOS: OPNsense
Version: 1.0.7

Then some normal check output and at the end

<<<check_mk>>>
FailedPythonPlugins: net

Really hope you can adopt this check for the new version.

Thanks and br Mike

obkgroove21 commented 1 month ago

Same problem here. Any suggestions/ideas? @thorstenspille

Yoshi-081 commented 1 month ago

As quick fix you can fix this by replace following in the file /usr/local/etc/rc.syshook.d/start/99-checkmk_agent on line 565 in Version 1.07

from

if _interface_dict["flags"] & 0x2 or _interface_dict["flags"] & 0x10 or _interface_dict["flags"] & 0x80: ## nur broadcast oder ptp .. und noarp

to

if "flags" in _interface_dict.keys() and (_interface_dict["flags"] & 0x2 or _interface_dict["flags"] & 0x10 or _interface_dict["flags"] & 0x80): ## nur broadcast oder ptp .. und noarp

After modify stop and start the script

/usr/local/etc/rc.syshook.d/start/99-checkmk_agent --stop /usr/local/etc/rc.syshook.d/start/99-checkmk_agent --start

The interface checks should now work again

obkgroove21 commented 1 month ago

Yeah this workaround is working on my side. Thank you very much. Maybe this should be merged in main.

darkain commented 1 month ago

I believe part of the issue is that its not a dict, its an object. I went and simplified the block of code and ensured statistics are being properly reported again.

            flags = _interface_dict.flags
            if isinstance(flags, int) and (flags & 0x92): ## nur broadcast oder ptp .. und noarp
                self._all_interfaces[_interface] = _interface_dict.__dict__ 
            else:
                continue