1#!/usr/local/bin/bash
2#
3# Show noise and signal levels of wifi enabled devices.
4# Author: Nicolai Langfeldt, janl@linprolno
5# Modifications: Sebastián Cruz, crux@lugmen.org.ar
6# License: GPL v. 2
7#
8#%# family=auto
9#%# capabilities=autoconf
10
11PNWL=/proc/net/wireless
12
13do_fetch () {
14    awk -F'[ :]*' '/:/ {
15                gsub(/\. /," ",$0); # Remove periods with no decimals after
16	        print $2"_noise.value "$6;
17	        print $2"_signal.value "$5;
18	}' $PNWL
19}
20
21do_config () {
22    echo "graph_title WiFi signal and noise"
23    echo "graph_args --base 1000 -u 0"
24    echo "graph_vlabel dB"
25    echo "graph_category wireless"
26    echo "graph_info This graph shows the noise and signal levels of your WiFi devices"
27
28    awk -F'[ :]*' '/:/ {
29	        print $2"_noise.label Noise "$2;
30	        print $2"_signal.label Signal "$2;
31	}' $PNWL
32}
33
34do_autoconf () {
35    if [ ! -f "$PNWL" ]; then
36        echo "no (missing file '$PNWL')"
37    elif [ ! -r "$PNWL" ]; then
38        echo "no (cannot read file '$PNWL')"
39    elif grep -qs : "$PNWL"; then
40        echo yes
41    else
42        echo "no (no devices in $PNWL)"
43    fi
44    exit 0
45}
46
47case $1 in
48    config|autoconf)
49        eval do_$1
50	exit 0;;
51    '')
52        do_fetch
53	exit 0;;
54esac
55
56