60 lines
1.2 KiB
Bash
Executable file
60 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# # Parameters:
|
|
#
|
|
# config (required)
|
|
# autoconf (optional - used by munin-config)
|
|
# suggest (optional - used by munin-config)
|
|
#
|
|
|
|
#. $MUNIN_LIBDIR/plugins/plugin.sh
|
|
|
|
myname="connexions"
|
|
|
|
name="${name-\<$myname\>}"
|
|
REGEX="${regex-\<$name\>}"
|
|
services=(http ssh smtp imap nfs ldap)
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
echo yes
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$1" = "suggest" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$1" = "config" ]; then
|
|
cat <<EOF
|
|
graph_title Number of $myname
|
|
graph_args --base 1000 --vertical-label connexions -l 0
|
|
graph_category network
|
|
`for dmn in ${services[@]}; do echo $dmn.label Connexions $dmn; done`
|
|
other.label Connexions diverses
|
|
in.label Connexions entrantes
|
|
out.label Connexions sortantes
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
ip=$(ifconfig | perl -ne 'print ${^MATCH} if /10\.231\.136\.\d+/p')
|
|
ips=${IP/10/}
|
|
TMP=`mktemp -t sockets.XXXXXX`
|
|
trap "rm $TMP* 2>/dev/null" 0
|
|
|
|
/sbin/ss > $TMP
|
|
|
|
for dmn in ${services[@]}; do
|
|
printf "$dmn.value "
|
|
grep "$ips:$dmn" $TMP | wc -l
|
|
done
|
|
|
|
printf "other.value "
|
|
perl -ne "print if ! /$ips:`echo ${services[@]} | sed 's/ /|/g'`/" $TMP | wc -l
|
|
|
|
printf "in.value "
|
|
perl -ne "print if ! /$ips:\d{5}/" $TMP | wc -l
|
|
|
|
printf "out.value "
|
|
perl -ne "print if /$ips:\d{5}/" $TMP | wc -l
|