2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/mail/dovecot

154 lines
3.7 KiB
Text
Raw Normal View History

#! /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>
#
# 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
######################
2013-06-22 16:20:11 +02:00
STAT_FILE=${STAT_FILE:-/var/lib/munin-node/plugin-state/root/plugin-dovecot.state}
2007-05-11 16:05:57 +02:00
EXPR_BIN=/usr/bin/expr
LOGFILE=${logfile:-/var/log/mail.log}
######################
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
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'
echo 'login_total.label Total Logins'
echo 'login_tls.label TLS Logins'
echo 'login_ssl.label SSL Logins'
echo 'login_imap.label IMAP Logins'
echo 'login_pop3.label POP3 Logins'
echo 'connected.label Connected Users'
exit 0
fi
#############################
# Initialization
#############################
if [ ! -r $STAT_FILE ]; then
echo "TOTAL=0" > $STAT_FILE
echo "TLS=0" >> $STAT_FILE
echo "SSL=0" >> $STAT_FILE
echo "IMAP=0" >> $STAT_FILE
echo "POP3=0" >> $STAT_FILE
fi
#############################
######################
# Total Logins
######################
echo -en "login_total.value "
NEW_TOTAL=$(egrep '[dovecot]?.*Login' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
2007-05-11 16:05:57 +02:00
OLD_TOTAL=$(grep TOTAL $STAT_FILE | cut -f2 -d '=')
TOTAL=$($EXPR_BIN $NEW_TOTAL - $OLD_TOTAL)
if [ $TOTAL -gt 0 ]; then
echo "$TOTAL"
else
echo "0"
fi
echo -n
######################
# Connected Users
######################
DISCONNECTS=$(egrep '[dovecot]?.*Disconnected' $LOGFILE | sort | wc -l)
CONNECTS=$(egrep '[dovecot]?.*Login' $LOGFILE | sort | wc -l)
2007-05-11 16:05:57 +02:00
DISCON=$($EXPR_BIN $CONNECTS - $DISCONNECTS)
if [ $DISCON -lt 0 ]; then
DISCON=0
fi
echo -en "connected.value "
echo $DISCON
echo -n
######################
# TLS Logins
######################
echo -en "login_tls.value "
NEW_TLS=$(egrep '[dovecot]?.*Login.*TLS' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
2007-05-11 16:05:57 +02:00
OLD_TLS=$(grep TLS $STAT_FILE | cut -f2 -d '=')
TLS=$($EXPR_BIN $NEW_TLS - $OLD_TLS)
if [ $TLS -gt 0 ]; then
echo "$TLS"
else
echo "0"
fi
echo -n
######################
# SSL Logins
######################
echo -en "login_ssl.value "
NEW_SSL=$(egrep '[dovecot]?.*Login.*SSL' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
2007-05-11 16:05:57 +02:00
OLD_SSL=$(grep SSL $STAT_FILE | cut -f2 -d '=')
SSL=$($EXPR_BIN $NEW_SSL - $OLD_SSL)
if [ $SSL -gt 0 ]; then
echo "$SSL"
else
echo "0"
fi
echo -n
######################
# IMAP Logins
######################
echo -en "login_imap.value "
NEW_IMAP=$(egrep '[dovecot]?.*imap.*Login' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
2007-05-11 16:05:57 +02:00
OLD_IMAP=$(grep IMAP $STAT_FILE | cut -f2 -d '=')
IMAP=$($EXPR_BIN $NEW_IMAP - $OLD_IMAP)
if [ $IMAP -gt 0 ]; then
echo "$IMAP"
else
echo "0"
fi
echo -n
######################
# POP3 Logins
######################
echo -en "login_pop3.value "
NEW_POP3=$(egrep '[dovecot]?.*pop3.*Login' $LOGFILE | grep "`date '+%b %e'`" | sort | wc -l)
2007-05-11 16:05:57 +02:00
OLD_POP3=$(grep POP3 $STAT_FILE | cut -f2 -d '=')
POP3=$($EXPR_BIN $NEW_POP3 - $OLD_POP3)
if [ $POP3 -gt 0 ]; then
echo "$POP3"
else
echo "0"
fi
echo -n
######################
# Save the new values
######################
echo "TOTAL=$NEW_TOTAL" > $STAT_FILE
echo "TLS=$NEW_TLS" >> $STAT_FILE
echo "SSL=$NEW_SSL" >> $STAT_FILE
echo "IMAP=$NEW_IMAP" >> $STAT_FILE
echo "POP3=$NEW_POP3" >> $STAT_FILE