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:
parent
2b66ed321e
commit
50dd7cc94e
@ -1,28 +1,50 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Monitor the wifi channel occupation (taken from "iw dev wlan0 survey dump").
|
||||
#
|
||||
# Symlink this plugin with the name of the wifi interface added (e.g. "wlan0").
|
||||
#
|
||||
#
|
||||
# Copyright (C) 2015 Lars Kruse <devel@sumpfralle.de>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# 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
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Magic markers
|
||||
#%# capabilities=autoconf suggest
|
||||
|
||||
: << =cut
|
||||
|
||||
=head1 NAME
|
||||
|
||||
wireless_channel_occupation_ - Monitor occupation of wireless channels
|
||||
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
All systems with at least one wireless interface and the the tool "iw".
|
||||
|
||||
The wifi channel occupation is parsed from the output of "iw dev wlan0 survey dump".
|
||||
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
Symlink this plugin with the name of the wifi interface added (e.g. "wlan0").
|
||||
|
||||
Root permissions are probably required for accessing "iw".
|
||||
|
||||
[wireless_channel_occupation_*]
|
||||
user root
|
||||
|
||||
|
||||
=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
|
||||
|
||||
@ -35,36 +57,26 @@ clean_fieldname() {
|
||||
}
|
||||
|
||||
|
||||
get_wifi_devices() {
|
||||
get_wifi_interfaces() {
|
||||
iw dev | grep Interface | awk '{print $2}'
|
||||
}
|
||||
|
||||
|
||||
get_wifi_device_from_suffix() {
|
||||
local suffix
|
||||
local called
|
||||
called=$(basename "$0")
|
||||
suffix="${called#$SCRIPT_PREFIX}"
|
||||
# empty result if the prefix did not match (and was not removed)
|
||||
[ "$suffix" = "$0" ] && echo "" || echo "$suffix"
|
||||
local real_dev
|
||||
# pick the part after the basename of the real file
|
||||
suffix=$(basename "$0" | sed "s/^$SCRIPT_PREFIX//")
|
||||
for real_dev in $(get_wifi_interfaces); do
|
||||
[ "$suffix" != "$(clean_fieldname "$real_dev")" ] || echo "$real_dev"
|
||||
done | head -1
|
||||
}
|
||||
|
||||
|
||||
if [ "${1:-}" = "autoconf" ]; then
|
||||
if which iw 2>/dev/null; then
|
||||
if [ -n "$(get_wifi_devices)" ]; then
|
||||
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
|
||||
do_config() {
|
||||
local device
|
||||
local dev_field
|
||||
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_vlabel %"
|
||||
echo "graph_category wireless"
|
||||
@ -93,13 +105,39 @@ elif [ "${1:-}" = "config" ]; then
|
||||
echo "${dev_field}_transmit.type DERIVE"
|
||||
echo "${dev_field}_transmit.draw STACK"
|
||||
echo "${dev_field}_transmit.cdef 100,${dev_field}_transmit,${dev_field}_active,/,*"
|
||||
else
|
||||
}
|
||||
|
||||
|
||||
do_fetch() {
|
||||
local device
|
||||
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 \
|
||||
| grep -F -A 5 "[in use]" \
|
||||
| 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
|
||||
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user