openwisp / openwrt-openwisp-monitoring

OpenWRT monitoring agent for openwisp-monitoring
https://openwisp.io/docs/dev/openwrt-monitoring-agent/
GNU General Public License v3.0
23 stars 20 forks source link

[bug/change] Do not add wireless interface information if channel is not available #113

Closed nemesifier closed 1 year ago

nemesifier commented 1 year ago

This is an issue I have been observing for a few months. If a device has some misconfigured wifi interfaces or radios, even though the WiFI interface is not completely brought up and hence not working, the system will report its presence with some important information like channel omitted, eg:

wlan1     ESSID: unknown
          Access Point: 46:D1:FA:D2:29:7C
          Mode: Client  Channel: unknown (unknown)
          Center Channel 1: unknown 2: unknown
          Tx-Power: 20 dBm  Link Quality: unknown/70
          Signal: unknown  Noise: -92 dBm
          Bit Rate: unknown
          Encryption: unknown
          Type: nl80211  HW Mode(s): 802.11nacax
          Hardware: 14C3:7915 14C3:7915 [MediaTek MT7915E]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy1

The result is a JSON payload which will be rejected by OpenWISP Monitoring.

For this reason, I think we should change this block of code as follows:

https://github.com/openwisp/openwrt-openwisp-monitoring/blob/8e49082ce7ded3f2ec7e10beedf8c6305f21239f/openwisp-monitoring/files/sbin/netjson-monitoring.lua#L85-L106

We should check whether the channel information is present (iwinfo.channel is nil) and if it's not present we should not add the wireless key to the netjson_interface dictionary (lua table) nor look for wifi clients.

I think the whole block shown above could be moved to a separate utility function which is called only after we check that iwinfo.channel is not nil.

We will need to add a test for this in test_wifi.lua.