Network monitoring using Kubernetes Agent fails due to network bonding

CMK version:
2.2.0p23
OS version:
Ubuntu 22.04 (und Kubernetes 1.27.14 rke2)
Error message:
ValueError (not enough values to unpack (expected 2, got 1))
Traceback:

File "/omd/sites/nms_k8s/lib/python3/cmk/base/agent_based/data_provider.py", line 106, in _parse_raw_data
    return parse_function(list(raw_data))
  File "/omd/sites/nms_k8s/lib/python3/cmk/base/plugins/agent_based/section_lnx_container_host_if.py", line 138, in parse_lnx_container_host_if
    return [_create_interface(_parse_raw_stats(i)) for i in string_table], {}
  File "/omd/sites/nms_k8s/lib/python3/cmk/base/plugins/agent_based/section_lnx_container_host_if.py", line 138, in <listcomp>
    return [_create_interface(_parse_raw_stats(i)) for i in string_table], {}
  File "/omd/sites/nms_k8s/lib/python3/cmk/base/plugins/agent_based/section_lnx_container_host_if.py", line 47, in _parse_raw_stats
    k, v = stats.split("\v")

Local Variables:

{'k': 'tx_dropped',
 'line': ['name\x0bbonding_masters',
          'ifindex\x0b',
          'ifalias\x0b',
          'address\x0b',
          'type\x0b',
          'carrier\x0b',
          'speed\x0b',
          'rx_bytes\x0b',
          'rx_packets\x0b',
          'rx_errors\x0b',
          'rx_dropped\x0b',
          'multicast\x0b',
          'tx_bytes\x0b',
          'tx_packets\x0b',
          'tx_errors\x0b',
          'tx_dropped\x0b',
          'tx_fifo_errors'],
 'raw_stats': {'address': '',
               'carrier': '',
               'ifalias': '',
               'ifindex': '',
               'multicast': '',
               'name': 'bonding_masters',
               'rx_bytes': '',
               'rx_dropped': '',
               'rx_errors': '',
               'rx_packets': '',
               'speed': '',
               'tx_bytes': '',
               'tx_dropped': '',
               'tx_errors': '',
               'tx_packets': '',
               'type': ''},
 'stats': 'tx_fifo_errors',
 'v': ''}

The problem lies in the output of the check_mk_agent, specifically in the lnx_container_host_if.linux script which does not properly check whether it is a file or a folder. In my case I use network bonding which creates the file bonding_masters in the folder /sys/class/net/. This should be ignored by the script, which is currently not happening.

A possible solution is to change the script lnx_container_host_if.linux as follows:

for if_path in "${interface_filepath}"/*; do

-        # Directory does not exist or is empty
-        [ -e "${if_path}" ] || continue
+        # Check if Path is a directory, if not continue
+        [ -d "${if_path}" ] || continue
+        # Check if directory is empty, if true continue
+        [ -n "$(ls -A ${if_path})" ] || continue 

        printf "name\v%s\t" "$(basename "${if_path}")"
        __read_network_interface_files "${if_path}" "${network_interface_metadata}"
        __read_network_interface_files "${if_path}" "${network_interface_speed}"
        __read_network_interface_files "${if_path}/${interface_statistics_subpath}" "${network_interface_rx_stats}"
        __read_network_interface_files "${if_path}/${interface_statistics_subpath}" "${network_interface_tx_stats}"
        printf "\n"

    done

There is also a pull request for this fix PR #733

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.