2012-01-20 12:05:31 +01:00
|
|
|
#! /bin/bash
|
2007-05-11 16:05:57 +02:00
|
|
|
#
|
|
|
|
# Munin Plugin
|
|
|
|
# to count logins to your dovecot mailserver
|
|
|
|
#
|
|
|
|
# Created by Dominik Schulz <lkml@ds.gauner.org>
|
|
|
|
# http://developer.gauner.org/munin/
|
|
|
|
# Contributions by:
|
|
|
|
# - Stephane Enten <tuf@delyth.net>
|
2013-09-05 00:24:19 +02:00
|
|
|
# - Steve Schnepp <steve.schnepp@pwkf.org>
|
2007-05-11 16:05:57 +02:00
|
|
|
#
|
|
|
|
# Parameters understood:
|
|
|
|
#
|
|
|
|
# config (required)
|
|
|
|
# autoconf (optional - used by munin-config)
|
|
|
|
#
|
|
|
|
# Config variables:
|
|
|
|
#
|
|
|
|
# logfile - Where to find the syslog file
|
|
|
|
#
|
|
|
|
# Add the following line to a file in /etc/munin/plugin-conf.d:
|
|
|
|
# env.logfile /var/log/your/logfile.log
|
|
|
|
#
|
|
|
|
# Magic markers (optional - used by munin-config and installation scripts):
|
|
|
|
#
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Configuration
|
|
|
|
######################
|
|
|
|
EXPR_BIN=/usr/bin/expr
|
|
|
|
LOGFILE=${logfile:-/var/log/mail.log}
|
|
|
|
######################
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
|
|
echo yes
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
2013-04-08 12:49:39 +02:00
|
|
|
echo 'graph_title Dovecot Logins'
|
|
|
|
echo 'graph_category Mail'
|
2007-05-11 16:05:57 +02:00
|
|
|
echo 'graph_args --base 1000 -l 0'
|
|
|
|
echo 'graph_vlabel Login Counters'
|
2013-09-05 00:24:19 +02:00
|
|
|
|
|
|
|
for t in Total TLS SSL IMAP POP3
|
|
|
|
do
|
|
|
|
field=$(echo $t | tr '[:upper:]' '[:lower:]')
|
|
|
|
echo "login_$field.label $t Logins"
|
|
|
|
echo "login_$field.type DERIVE"
|
|
|
|
echo "login_$field.min 0"
|
|
|
|
done
|
|
|
|
|
2007-05-11 16:05:57 +02:00
|
|
|
echo 'connected.label Connected Users'
|
|
|
|
|
2013-09-05 00:24:19 +02:00
|
|
|
exit 0
|
2007-05-11 16:05:57 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Total Logins
|
|
|
|
######################
|
|
|
|
echo -en "login_total.value "
|
2013-09-05 00:27:02 +02:00
|
|
|
VALUE=$(egrep -c '[dovecot]?.*Login' $LOGFILE)
|
2013-09-05 00:24:19 +02:00
|
|
|
if [ ! -z "$VALUE" ]; then
|
|
|
|
echo "$VALUE"
|
2007-05-11 16:05:57 +02:00
|
|
|
else
|
|
|
|
echo "0"
|
|
|
|
fi
|
|
|
|
echo -n
|
|
|
|
######################
|
|
|
|
# Connected Users
|
|
|
|
######################
|
2013-09-05 00:27:02 +02:00
|
|
|
DISCONNECTS=$(egrep -c '[dovecot]?.*Disconnected' $LOGFILE)
|
|
|
|
CONNECTS=$(egrep -c '[dovecot]?.*Login' $LOGFILE)
|
2013-09-05 00:24:19 +02:00
|
|
|
VALUE=$($EXPR_BIN $CONNECTS - $DISCONNECTS)
|
2015-04-29 11:28:38 +02:00
|
|
|
if [ -z "$VALUE" ] || [ "$VALUE" -lt 0 ]; then
|
|
|
|
VALUE=0
|
2007-05-11 16:05:57 +02:00
|
|
|
fi
|
|
|
|
echo -en "connected.value "
|
2015-04-29 11:28:38 +02:00
|
|
|
echo $VALUE
|
2007-05-11 16:05:57 +02:00
|
|
|
echo -n
|
|
|
|
######################
|
|
|
|
# TLS Logins
|
|
|
|
######################
|
|
|
|
echo -en "login_tls.value "
|
2013-09-05 00:27:02 +02:00
|
|
|
VALUE=$(egrep -c '[dovecot]?.*Login.*TLS' $LOGFILE)
|
2013-09-05 00:24:19 +02:00
|
|
|
if [ ! -z "$VALUE" ]; then
|
|
|
|
echo "$VALUE"
|
2007-05-11 16:05:57 +02:00
|
|
|
else
|
|
|
|
echo "0"
|
|
|
|
fi
|
|
|
|
echo -n
|
|
|
|
######################
|
|
|
|
# SSL Logins
|
|
|
|
######################
|
|
|
|
echo -en "login_ssl.value "
|
2013-09-05 00:27:02 +02:00
|
|
|
VALUE=$(egrep -c '[dovecot]?.*Login.*SSL' $LOGFILE)
|
2013-09-05 00:24:19 +02:00
|
|
|
if [ ! -z "$VALUE" ]; then
|
|
|
|
echo "$VALUE"
|
2007-05-11 16:05:57 +02:00
|
|
|
else
|
|
|
|
echo "0"
|
|
|
|
fi
|
|
|
|
echo -n
|
|
|
|
######################
|
|
|
|
# IMAP Logins
|
|
|
|
######################
|
|
|
|
echo -en "login_imap.value "
|
2013-09-05 00:27:02 +02:00
|
|
|
VALUE=$(egrep -c '[dovecot]?.*imap.*Login' $LOGFILE)
|
2013-09-05 00:24:19 +02:00
|
|
|
if [ ! -z "$VALUE" ]; then
|
|
|
|
echo "$VALUE"
|
2007-05-11 16:05:57 +02:00
|
|
|
else
|
|
|
|
echo "0"
|
|
|
|
fi
|
|
|
|
echo -n
|
|
|
|
######################
|
|
|
|
# POP3 Logins
|
|
|
|
######################
|
|
|
|
echo -en "login_pop3.value "
|
2013-09-05 00:27:02 +02:00
|
|
|
VALUE=$(egrep -c '[dovecot]?.*pop3.*Login' $LOGFILE)
|
2013-09-05 00:24:19 +02:00
|
|
|
if [ ! -z "$VALUE" ]; then
|
|
|
|
echo "$VALUE"
|
2007-05-11 16:05:57 +02:00
|
|
|
else
|
|
|
|
echo "0"
|
|
|
|
fi
|
|
|
|
echo -n
|