From 44faf386256366c3845cf151c38726e27f4c085d Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 28 Oct 2023 19:47:44 +0300 Subject: [PATCH] cmk plugin --- .../check_mk_agent/plugins/wifi_interfaces | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 generic_config/ath79/dlink_dap-2695-a1/usr/lib/check_mk_agent/plugins/wifi_interfaces diff --git a/generic_config/ath79/dlink_dap-2695-a1/usr/lib/check_mk_agent/plugins/wifi_interfaces b/generic_config/ath79/dlink_dap-2695-a1/usr/lib/check_mk_agent/plugins/wifi_interfaces new file mode 100755 index 0000000..1f2804a --- /dev/null +++ b/generic_config/ath79/dlink_dap-2695-a1/usr/lib/check_mk_agent/plugins/wifi_interfaces @@ -0,0 +1,39 @@ +#!/bin/sh + +CACHE_FILE=/usr/lib/check_mk_agent/plugins/wifi_interfaces.cache + +echo "<<>>" # 59 = ascii semi-colon (;) + +interfaces=$(ls /sys/class/net | grep -iE 'phy.+') + +# Create empty file if it does not exist +# First plugin run may produce garbage data or not run at all, which is OK +# Cache file format: $interface,$time,$busy +touch $CACHE_FILE +cached_output="$(cat "$CACHE_FILE")" +echo -n "" > "$CACHE_FILE" + +for interface in $interfaces +do + ch_time_old="$(echo "$cached_output" | awk -v interface="$interface" -F';' '$1 ~ interface { print $2 }')" + ch_time_busy_old="$(echo "$cached_output" | awk -v interface="$interface" -F';' '$1 ~ interface { print $3 }')" + + output="$(ethtool -S "$interface")" + + ch_time="$(echo "$output" | awk -F ': ' '/ch_time:/{ print $2 }')" + ch_time_busy="$(echo "$output" | awk -F ': ' '/ch_time_busy:/{ print $2 }')" + echo "$interface;$ch_time;$ch_time_busy" >> "$CACHE_FILE" + + # The noise is represented as an unsigned byte, we need a signed one. Thus, we subtract 2**7. + noise="$(expr $(echo "$output" | awk -F ': ' '/noise:/{ print $2 }') - 256)" + + phy="$(echo "$interface" | awk -F '-' '//{print $1 }')" + client_count="$(ls /sys/kernel/debug/ieee80211/$phy/netdev:$interface/stations/ | wc -l)" + + # We calculate the deltas to use for alarms locally; fields are u64 + delta_ch_time=$(expr $(expr $ch_time - $ch_time_old) % 18446744073709551616) + delta_ch_time_busy=$(expr $(expr $ch_time_busy - $ch_time_busy_old) % 18446744073709551616) + + + echo "$interface;$ch_time;$ch_time_busy;$noise;$delta_ch_time;$delta_ch_time_busy;$client_count" +done