root / plugins / network / ipfwnat_ @ 1bed50bb
Historique | Voir | Annoter | Télécharger (2,8 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# |
| 3 |
# Copyright (C) 2009 Alexey Illarionov <littlesavage@rambler.ru> |
| 4 |
# |
| 5 |
# Wildcard plugin to monitor ipfw nat aliasing links count |
| 6 |
# |
| 7 |
# Usage: Link ipfwnat_<nat number> to this file. E.g, |
| 8 |
# |
| 9 |
# ln -s ipfwnat_ /etc/munin/node.d/ipfwnat_123 |
| 10 |
# |
| 11 |
# ... will moninot nat number 123 |
| 12 |
# |
| 13 |
# This plugin needs to be run as root. Sample plugins.conf: |
| 14 |
# |
| 15 |
# [ipfwnat_*] |
| 16 |
# user root |
| 17 |
# |
| 18 |
# Furthermore, nat configuration must contain "log" option. E.g. |
| 19 |
# |
| 20 |
# ipfw nat 123 config ip 198.76.28.4 log |
| 21 |
# |
| 22 |
# This plugin is based on the if_ plugin. |
| 23 |
# |
| 24 |
# Magic markers (optional - used by munin-config and some installation |
| 25 |
# scripts): |
| 26 |
# |
| 27 |
#%# family=auto |
| 28 |
#%# capabilities=autoconf suggest |
| 29 |
|
| 30 |
NAT_NUM=`basename $0 | sed 's/^ipfwnat_//g'` |
| 31 |
|
| 32 |
ipfw="/sbin/ipfw" |
| 33 |
|
| 34 |
if [ "$1" = "autoconf" ]; then |
| 35 |
if [ ! -x $ipfw ]; then |
| 36 |
echo "no ($ipfw not found)" |
| 37 |
exit 1 |
| 38 |
fi |
| 39 |
|
| 40 |
err=$($ipfw nat show config 2>&1) |
| 41 |
if [ $? -ne 0 ]; then |
| 42 |
echo "no ($err)" |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
|
| 46 |
echo "yes" |
| 47 |
exit 0 |
| 48 |
fi |
| 49 |
|
| 50 |
if [ "$1" = "suggest" ]; then |
| 51 |
$ipfw nat show config 2> /dev/null | /usr/bin/awk '/nat [0-9]+ .+ log/{print $3;}'
|
| 52 |
exit 0 |
| 53 |
fi |
| 54 |
|
| 55 |
if [ "$1" = "config" ]; then |
| 56 |
echo "graph_title Ipfw NAT ${NAT_NUM} aliasing links count"
|
| 57 |
echo 'graph_args --base 1000 -l 0' |
| 58 |
echo 'graph_vlabel links count' |
| 59 |
echo 'graph_noscale true' |
| 60 |
echo 'graph_category fw' |
| 61 |
|
| 62 |
echo 'tcp.draw AREA' |
| 63 |
echo 'tcp.label tcp' |
| 64 |
echo 'tcp.info TCP aliasing links count' |
| 65 |
|
| 66 |
echo 'udp.draw STACK' |
| 67 |
echo 'udp.label udp' |
| 68 |
echo 'udp.info UDP aliasing links count' |
| 69 |
|
| 70 |
echo 'sctp.draw STACK' |
| 71 |
echo 'sctp.label sctp' |
| 72 |
echo 'sctp.info SCTP aliasing links count' |
| 73 |
|
| 74 |
echo 'icmp.draw STACK' |
| 75 |
echo 'icmp.label icmp' |
| 76 |
echo 'icmp.info ICMP aliasing links count' |
| 77 |
|
| 78 |
echo 'pptp.draw STACK' |
| 79 |
echo 'pptp.label pptp' |
| 80 |
echo 'pptp.info PPTP aliasing links count' |
| 81 |
|
| 82 |
echo 'proto.draw STACK' |
| 83 |
echo 'proto.label proto' |
| 84 |
echo 'proto.info proto aliasing links count' |
| 85 |
|
| 86 |
echo 'fragid.draw STACK' |
| 87 |
echo 'fragid.label frag_id' |
| 88 |
echo 'fragid.info Fragment id aliasing links count' |
| 89 |
|
| 90 |
echo 'fragptr.draw STACK' |
| 91 |
echo 'fragptr.label frag_ptr' |
| 92 |
echo 'fragptr.info Fragment ptr aliasing links count' |
| 93 |
|
| 94 |
echo "graph_info Ipfw NAT ${NAT_NUM} aliasing links count."
|
| 95 |
exit 0 |
| 96 |
fi |
| 97 |
|
| 98 |
$ipfw nat ${NAT_NUM} show 2>/dev/null | /usr/bin/awk '
|
| 99 |
BEGIN {
|
| 100 |
res["tcp"] = "U"; |
| 101 |
res["udp"] = "U"; |
| 102 |
res["sctp"] = "U"; |
| 103 |
res["icmp"] = "U"; |
| 104 |
res["pptp"] = "U"; |
| 105 |
res["proto"] = "U"; |
| 106 |
res["frag_id"] = "U"; |
| 107 |
res["frag_ptr"] = "U"; |
| 108 |
} |
| 109 |
/^nat [0-9]+:/{
|
| 110 |
split($0, a, /[,\/:[:space:]]+/); |
| 111 |
for (f in a) {
|
| 112 |
if (a[f] ~ /^[a-z_]+=[0-9]+$/) {
|
| 113 |
split(a[f], v, /=/); |
| 114 |
res[v[1]] += (v[2] + 0); |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
END {
|
| 119 |
printf "tcp.value %s\n", res["tcp"]; |
| 120 |
printf "udp.value %s\n", res["udp"]; |
| 121 |
printf "sctp.value %s\n", res["sctp"]; |
| 122 |
printf "icmp.value %s\n", res["icmp"]; |
| 123 |
printf "pptp.value %s\n", res["pptp"]; |
| 124 |
printf "proto.value %s\n", res["proto"]; |
| 125 |
printf "fragid.value %s\n", res["frag_id"]; |
| 126 |
printf "fragptr.value %s\n", res["frag_ptr"]; |
| 127 |
} |
| 128 |
' |
| 129 |
|
