2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

wireless_channel_occupation_: various improvements

* add documentation header
* support dirty config
* fix shellcheck issues
This commit is contained in:
Lars Kruse 2018-04-04 04:09:41 +02:00
parent 2b66ed321e
commit 50dd7cc94e

View File

@ -1,28 +1,50 @@
#!/bin/sh #!/bin/sh
#
# Monitor the wifi channel occupation (taken from "iw dev wlan0 survey dump"). : << =cut
#
# Symlink this plugin with the name of the wifi interface added (e.g. "wlan0"). =head1 NAME
#
# wireless_channel_occupation_ - Monitor occupation of wireless channels
# Copyright (C) 2015 Lars Kruse <devel@sumpfralle.de>
#
# This program is free software: you can redistribute it and/or modify =head1 APPLICABLE SYSTEMS
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or All systems with at least one wireless interface and the the tool "iw".
# (at your option) any later version.
# The wifi channel occupation is parsed from the output of "iw dev wlan0 survey dump".
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the =head1 CONFIGURATION
# GNU General Public License for more details.
# Symlink this plugin with the name of the wifi interface added (e.g. "wlan0").
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. Root permissions are probably required for accessing "iw".
#
# Magic markers [wireless_channel_occupation_*]
#%# capabilities=autoconf suggest user root
#%# family=auto
=head1 VERSION
1.1
=head1 AUTHOR
Lars Kruse <devel@sumpfralle.de>
=head1 LICENSE
GPLv3 or above
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf suggest
=cut
set -eu set -eu
@ -35,36 +57,26 @@ clean_fieldname() {
} }
get_wifi_devices() { get_wifi_interfaces() {
iw dev | grep Interface | awk '{print $2}' iw dev | grep Interface | awk '{print $2}'
} }
get_wifi_device_from_suffix() { get_wifi_device_from_suffix() {
local suffix local suffix
local called local real_dev
called=$(basename "$0") # pick the part after the basename of the real file
suffix="${called#$SCRIPT_PREFIX}" suffix=$(basename "$0" | sed "s/^$SCRIPT_PREFIX//")
# empty result if the prefix did not match (and was not removed) for real_dev in $(get_wifi_interfaces); do
[ "$suffix" = "$0" ] && echo "" || echo "$suffix" [ "$suffix" != "$(clean_fieldname "$real_dev")" ] || echo "$real_dev"
done | head -1
} }
if [ "${1:-}" = "autoconf" ]; then do_config() {
if which iw 2>/dev/null; then local device
if [ -n "$(get_wifi_devices)" ]; then local dev_field
echo "yes"
else
echo "no (missing wifi devices)"
fi
else
echo "no (missing 'iw' dependency)"
fi
elif [ "${1:-}" = "suggest" ]; then
get_wifi_devices
elif [ "${1:-}" = "config" ]; then
device=$(get_wifi_device_from_suffix) device=$(get_wifi_device_from_suffix)
[ -z "$device" ] && echo >&2 "Invalid wifi device name given" && exit 1 [ -z "$device" ] && echo >&2 "Invalid wifi device name given" && return 1
echo "graph_title Channel Occupation of $device" echo "graph_title Channel Occupation of $device"
echo "graph_vlabel %" echo "graph_vlabel %"
echo "graph_category wireless" echo "graph_category wireless"
@ -93,13 +105,39 @@ elif [ "${1:-}" = "config" ]; then
echo "${dev_field}_transmit.type DERIVE" echo "${dev_field}_transmit.type DERIVE"
echo "${dev_field}_transmit.draw STACK" echo "${dev_field}_transmit.draw STACK"
echo "${dev_field}_transmit.cdef 100,${dev_field}_transmit,${dev_field}_active,/,*" echo "${dev_field}_transmit.cdef 100,${dev_field}_transmit,${dev_field}_active,/,*"
else }
do_fetch() {
local device
device=$(get_wifi_device_from_suffix) device=$(get_wifi_device_from_suffix)
[ -z "$device" ] && echo >&2 "Invalid wifi device name given" && exit 1 [ -z "$device" ] && echo >&2 "Invalid wifi device name given" && return 1
iw dev "$device" survey dump \ iw dev "$device" survey dump \
| grep -F -A 5 "[in use]" \ | grep -F -A 5 "[in use]" \
| grep -E "channel (busy|receive|transmit|active) time:" \ | grep -E "channel (busy|receive|transmit|active) time:" \
| awk '{print "'${device}_'"$2"'.value'",$4}' | awk '{print "'"${device}_"'"$2"'.value'",$4}'
}
if [ "${1:-}" = "autoconf" ]; then
if which iw >/dev/null; then
if [ -n "$(get_wifi_interfaces)" ]; then
echo "yes"
else
echo "no (missing wifi devices)"
fi
else
echo "no (missing 'iw' dependency)"
fi
elif [ "${1:-}" = "suggest" ]; then
for dev in $(get_wifi_interfaces); do
clean_fieldname "$dev"
done
elif [ "${1:-}" = "config" ]; then
do_config || exit 1
[ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ] && do_fetch
else
do_fetch
fi fi
exit 0 exit 0