[19] | 1 | #!@@GOODSH@@ |
---|
| 2 | # |
---|
| 3 | # Plugin to graph number of courier login/logouts |
---|
| 4 | # Requires: logtail |
---|
| 5 | # |
---|
| 6 | # This plugin should be symlinked to have the service name that you |
---|
| 7 | # want to track. If you want to watch imaplogin entries you would do: |
---|
| 8 | # ln -s /usr/share/munin/plugins/courier_ /etc/munin/plugins/courier_imaplogin |
---|
| 9 | # if you wanted to track courierpop3login entries, then you would do: |
---|
| 10 | # ln -s /usr/share/munin/plugins/courier_ /etc/munin/plugins/courier_courierpop3login |
---|
| 11 | # |
---|
| 12 | # Coypright Micah Anderson <micah@riseup.net> |
---|
| 13 | # Jan 22, 2005 |
---|
| 14 | # |
---|
| 15 | # |
---|
| 16 | #%# family=contrib |
---|
| 17 | #%# capabilities=autoconf |
---|
| 18 | |
---|
| 19 | # The different log lines we are interested in: |
---|
| 20 | # |
---|
| 21 | # imaplogin: |
---|
| 22 | # Jan 22 10:53:35 raven imaplogin: Connection, ip=[::ffff:192.168.0.1] |
---|
| 23 | # Jan 22 06:28:19 raven imaplogin: DISCONNECTED, user=someuser, ip=[::ffff:192.168.0.1], headers=0, body=0, time=22 |
---|
| 24 | # Jan 22 10:53:35 raven imaplogin: LOGIN, user=someuser, ip=[::ffff:192.168.0.1], protocol=IMAP |
---|
| 25 | # Jan 22 06:28:16 raven imaplogin: LOGOUT, user=someuser, ip=[::ffff:192.168.0.1], headers=0, body=2811, time=0 |
---|
| 26 | # |
---|
| 27 | # courierpop3login: |
---|
| 28 | # Jan 22 06:28:24 raven courierpop3login: Connection, ip=[::ffff:192.168.0.1] |
---|
| 29 | # Jan 22 06:48:22 raven courierpop3login: DISCONNECTED, user=someuser, ip=[::ffff:192.168.0.1], top=0, retr=0, time=21 |
---|
| 30 | # Jan 22 06:28:24 raven courierpop3login: LOGIN, user=someuser, ip=[::ffff:192.168.0.1] |
---|
| 31 | # Jan 22 06:28:25 raven courierpop3login: LOGOUT, user=someuser, ip=[::ffff:192.168.0.1], top=0, retr=0, time=0 |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | # Set the location of the courier logs |
---|
| 35 | COURIER_LOG=${logfile:-/var/log/mail.log} |
---|
| 36 | SERVICE=${service:-`basename $0 | sed 's/^courier_//g'`} |
---|
| 37 | OFFSET_FILE=@@PLUGSTATE@@/courier_${SERVICE}.offset |
---|
| 38 | LOGTAIL=${logtail:-/usr/sbin/logtail} |
---|
| 39 | |
---|
| 40 | mktempfile () { |
---|
| 41 | @@MKTEMP@@ |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | case $1 in |
---|
| 45 | autoconf|detect) |
---|
| 46 | if [ -f ${COURIER_LOG} -a -x ${LOGTAIL} ] |
---|
| 47 | then |
---|
| 48 | # Makes no sense for wildcard plugin to autoconf to yes |
---|
| 49 | # unless you can provide suggestions. |
---|
| 50 | echo no |
---|
| 51 | exit 0 |
---|
| 52 | else |
---|
| 53 | echo "no (either $COURIER_LOG was not found, or logtail was not in your path)" |
---|
| 54 | exit 1 |
---|
| 55 | fi |
---|
| 56 | ;; |
---|
| 57 | config) |
---|
| 58 | cat <<EOF |
---|
| 59 | graph_title Courier $SERVICE Connections |
---|
| 60 | graph_vlabel Number of Connections |
---|
| 61 | graph_total Total |
---|
| 62 | connection.label connections |
---|
| 63 | disconnected.label disconnections |
---|
| 64 | login.label logins |
---|
| 65 | logout.label logouts |
---|
| 66 | EOF |
---|
| 67 | exit 0 |
---|
| 68 | ;; |
---|
| 69 | esac |
---|
| 70 | |
---|
| 71 | ARGS=0 |
---|
| 72 | `$LOGTAIL /etc/hosts 2>/dev/null >/dev/null` |
---|
| 73 | if [ $? = 66 ]; then |
---|
| 74 | if [ ! -n "$logtail" ]; then |
---|
| 75 | ARGS=1 |
---|
| 76 | fi |
---|
| 77 | fi |
---|
| 78 | |
---|
| 79 | TEMP_FILE=`mktempfile munin-courier.XXXXXX` |
---|
| 80 | |
---|
| 81 | if [ -z "$TEMP_FILE" -o ! -f "$TEMP_FILE" ]; then |
---|
| 82 | exit 3 |
---|
| 83 | fi |
---|
| 84 | |
---|
| 85 | if [ $ARGS != 0 ]; then |
---|
| 86 | ${LOGTAIL} -f ${COURIER_LOG} -o ${OFFSET_FILE} | grep "$SERVICE" > ${TEMP_FILE} |
---|
| 87 | else |
---|
| 88 | ${LOGTAIL} ${COURIER_LOG} ${OFFSET_FILE} | grep "$SERVICE" > ${TEMP_FILE} |
---|
| 89 | fi |
---|
| 90 | connection=`grep Connection ${TEMP_FILE} | wc -l` |
---|
| 91 | disconnected=`grep DISCONNECTED ${TEMP_FILE} | wc -l` |
---|
| 92 | login=`grep LOGIN ${TEMP_FILE} | wc -l` |
---|
| 93 | logout=`grep LOGOUT ${TEMP_FILE} | wc -l` |
---|
| 94 | |
---|
| 95 | rm ${TEMP_FILE} |
---|
| 96 | |
---|
| 97 | echo "connection.value ${connection}" |
---|
| 98 | echo "disconnected.value ${disconnected}" |
---|
| 99 | echo "login.value ${login}" |
---|
| 100 | echo "logout.value ${logout}" |
---|