-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathzabbix_netstat
executable file
·75 lines (66 loc) · 1.74 KB
/
zabbix_netstat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#
# Zabbix agent extension for monitoring interfaces in /proc/net/dev
BUFFER=/tmp/zabbix-netstat
SOFTWARE="jo"
function discover_interfaces() {
jo -p data=$( jo -a $(
tail -n+3 /proc/net/dev | cut -d: -f1 | sort -u | while read interface
do
jo {\#INTERFACE}=${interface}
done ) )
}
function getdata() {
mkdir $BUFFER.$$; chmod 750 $BUFFER.$$
cd $BUFFER.$$
tail -n+3 /proc/net/dev | cut -d: -f1 | sort -u | while read interface
do
grep -w $interface /proc/net/dev | while read ifname rx_bytes rx_packets rx_errs rx_drop rx_fifo rx_frame rx_compressed rx_multicast tx_bytes tx_packets tx_errs tx_drop tx_fifo tx_colls tx_carrier tx_compressed
do
cat <<-EOF > $interface
rx_bytes:$rx_bytes
rx_packets:$rx_packets
rx_errs:$rx_errs
rx_drop:$rx_drop
rx_fifo:$rx_fifo
rx_frame:$rx_frame
rx_compressed:$rx_compressed
rx_multicast:$rx_multicast
tx_bytes:$tx_bytes
tx_packets:$tx_packets
tx_errs:$tx_errs
tx_drop:$tx_drop
tx_fifo:$tx_fifo
tx_colls:$tx_colls
tx_carrier:$tx_carrier
tx_compressed:$tx_compressed
EOF
done
done
test -d $BUFFER && mv $BUFFER $BUFFER.old
mv $BUFFER.$$ $BUFFER
rm -rf $BUFFER.old
}
function sanity_check() {
ok=1
for prog in $SOFTWARE
do
which $prog > /dev/null || { echo "Missing program $prog."; ok=0; }
done
test -f $CONFIG || { echo "Missing configfile $CONFIG"; ok=0; }
test $ok -ne 1 && { echo "Sanity check failed. Aboring." ; exit 1; }
}
sanity_check
action=$1
arg=$2
case "$action" in
getdata)
getdata
;;
netstat.discover)
discover_interfaces
;;
netstat.master)
test -f $BUFFER/$arg && cat $BUFFER/$arg
;;
esac