mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
move postfix plugins into the mail directory
This commit is contained in:
parent
ab9c97caeb
commit
6de3ccf145
9 changed files with 0 additions and 0 deletions
|
@ -1,110 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Plugin to monitor the amavis mail filter for Debian
|
||||
# (based upon a plugin authored by Geoffroy Desvernay)
|
||||
#
|
||||
# This plugin is built and tested on Debian Etch using:
|
||||
# munin 1.2.5-1
|
||||
# amavisd-new 2.4.2-6.1
|
||||
#
|
||||
# With some minor modification it should also work on non-debian systems
|
||||
# This, however, is up to you
|
||||
#
|
||||
# Munin graph will sum up: Passed CLEAN, Blocked VIRUS, Blocked SPAM, Other
|
||||
#
|
||||
# Parameters understood:
|
||||
# config (required)
|
||||
# autoconf (optional)
|
||||
#
|
||||
# Config variables:
|
||||
# AMAVIS_LOG - file where amavis logs are written
|
||||
# STATEFILE - file which is needed to keep track of AMAVIS_LOG
|
||||
# LOGTAIL - location of logtail
|
||||
# BC - location of bc
|
||||
#
|
||||
# Enjoy!
|
||||
# Fili Wiese
|
||||
#
|
||||
|
||||
AMAVIS_LOG=${logfile:-/var/log/mail.log}
|
||||
STATEFILE=/var/lib/munin/plugin-state/amavis.offset
|
||||
LOGTAIL=${logtail:-`which logtail`}
|
||||
BC=${bc:-`which bc`}
|
||||
|
||||
mktempfile () {
|
||||
mktemp
|
||||
}
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ -f "${AMAVIS_LOG}" -a -n "${LOGTAIL}" -a -x "${LOGTAIL}" -a -n "${BC}" -a -x "${BC}" ] ; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo no
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo 'graph_title Amavis filter statistics'
|
||||
echo 'graph_category postfix'
|
||||
echo 'graph_order total clean spam virus other'
|
||||
echo 'graph_vlabel Mails filtered'
|
||||
echo 'graph_scale no'
|
||||
echo 'total.label Total'
|
||||
echo 'total.draw AREA'
|
||||
echo 'total.colour DDDDDD'
|
||||
echo 'clean.label Passed CLEAN'
|
||||
echo 'clean.draw LINE1'
|
||||
echo 'clean.colour 32FA00'
|
||||
echo 'spam.label Blocked SPAM'
|
||||
echo 'spam.draw LINE1'
|
||||
echo 'spam.colour FF0000'
|
||||
echo 'virus.label Blocked VIRUS'
|
||||
echo 'virus.draw LINE1'
|
||||
echo 'virus.colour 880088'
|
||||
echo 'other.label Other'
|
||||
echo 'other.draw LINE1'
|
||||
echo 'other.colour 0099FF'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
clean=0
|
||||
virus=0
|
||||
spams=0
|
||||
other=0
|
||||
total=0
|
||||
|
||||
ARGS=0
|
||||
`$LOGTAIL /etc/hosts 2>/dev/null >/dev/null`
|
||||
if [ $? = 66 ]; then
|
||||
if [ ! -n "$logtail" ]; then
|
||||
ARGS=1
|
||||
fi
|
||||
fi
|
||||
|
||||
TEMP_FILE=`mktempfile munin-amavis.XXXXXX`
|
||||
|
||||
if [ -n "$TEMP_FILE" -a -f "$TEMP_FILE" ]
|
||||
then
|
||||
if [ $ARGS != 0 ]; then
|
||||
$LOGTAIL ${AMAVIS_LOG} $STATEFILE | grep 'amavis\[.*\]:' | grep -v 'TIMED OUT' > ${TEMP_FILE}
|
||||
else
|
||||
$LOGTAIL ${AMAVIS_LOG} $STATEFILE | grep 'amavis\[.*\]:' | grep -v 'TIMED OUT' > ${TEMP_FILE}
|
||||
fi
|
||||
total=`cat ${TEMP_FILE} | wc -l`
|
||||
clean=`grep 'CLEAN' ${TEMP_FILE} | wc -l`
|
||||
virus=`grep 'INFECTED' ${TEMP_FILE} | wc -l`
|
||||
spam=`grep 'Blocked SPAM' ${TEMP_FILE} | wc -l`
|
||||
other=`echo ${total}-${clean}-${virus}-${other}-${spam} | ${BC}`
|
||||
|
||||
/bin/rm -f $TEMP_FILE
|
||||
fi
|
||||
|
||||
|
||||
echo "clean.value ${clean}"
|
||||
echo "virus.value ${virus}"
|
||||
echo "spam.value ${spam}"
|
||||
echo "other.value ${other}"
|
||||
echo "total.value ${total}"
|
||||
|
|
@ -1,185 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
"""
|
||||
Munin plugin that monitors the greyfix triplet database.
|
||||
Author: Tom Hendrikx <tom@whyscream.net> 2011-08-05
|
||||
|
||||
This plugin monitors the Greyfix greylisting tool for Postfix.
|
||||
It creates a nice overview of the number of triplets in the greyfix database,
|
||||
dividing the database population in configurable ages.
|
||||
|
||||
For more information about greyfix: http://trac.kim-minh.com/greyfix/
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
To install, create a symlink to the plugin in the munin plugin directory:
|
||||
$ ln -s /path/to/plugin/greyfix /etc/munin/plugins/greyfix
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
There are some settings that can be tweaked by adding statements to the
|
||||
munin-node config:
|
||||
|
||||
[greyfix]
|
||||
# run plugin as the same user as postfix does
|
||||
user nobody
|
||||
# path to greyfix binary (default: /usr/sbin/greyfix)
|
||||
env.greyfix /usr/local/sbin/greyfix
|
||||
# the length of each graph step in days (default: 7)
|
||||
env.step_size 3
|
||||
# the number of steps to graph (default: 11)
|
||||
env.num_steps 47
|
||||
# graph the greylisted triplets separate from the whitelisted ones (default: yes)
|
||||
env.greylist_step no
|
||||
|
||||
Please note that the last step has no end date, so it includes all triplets
|
||||
older than the second last step. I.e., the defaults (as named above) create a
|
||||
graph that shows 10 steps of one week each, and one last step for everything
|
||||
older than 10 weeks. Also, the separate greylist step is not considered
|
||||
when applying num_steps.
|
||||
|
||||
"""
|
||||
|
||||
# Settings: all of these can be redefined in the munin-node config
|
||||
settings = {
|
||||
'greyfix': '/usr/sbin/greyfix',
|
||||
'step_size': 7,
|
||||
'num_steps': 11,
|
||||
'greylist_step': 'yes'
|
||||
}
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import datetime
|
||||
|
||||
|
||||
def greyfix_parse_triplets():
|
||||
"""Parse output of greyfix --dump-triplets into something that we can use.
|
||||
|
||||
The output of the command has the following columns:
|
||||
sender_ip, sender_email, recipient_email, timestamp_first_seen, timestamp_last_seen, block_count, pass_count
|
||||
|
||||
Also see http://groups.google.com/group/greyfix/browse_thread/thread/510687a9ed94fc2c"""
|
||||
|
||||
greyfix = subprocess.Popen(args=[ settings['greyfix'], '--dump-triplets'], stdout=subprocess.PIPE)
|
||||
stdout = greyfix.communicate()[0]
|
||||
if greyfix.returncode > 0:
|
||||
print '# greyfix exited with exit code %i' % (greyfix.returncode)
|
||||
sys.exit(greyfix.returncode)
|
||||
|
||||
triplets = []
|
||||
for line in stdout.split("\n"):
|
||||
triplet = line.split("\t")
|
||||
if len(triplet) == 7:
|
||||
triplet[3] = datetime.datetime.strptime(triplet[3], '%c')
|
||||
triplet[4] = datetime.datetime.strptime(triplet[4], '%c')
|
||||
triplet[5] = int(triplet[5])
|
||||
triplet[6] = int(triplet[6])
|
||||
triplets.append(triplet)
|
||||
|
||||
return triplets
|
||||
|
||||
|
||||
def convert_step_to_days(step):
|
||||
"""Compute the days that are contained in a step, according to the configuration"""
|
||||
|
||||
start = settings['step_size'] * step
|
||||
end = (settings['step_size'] * (step + 1)) - 1
|
||||
if step >= (settings['num_steps'] -1):
|
||||
return (start, '')
|
||||
else:
|
||||
return (start, end)
|
||||
|
||||
|
||||
def print_fetch():
|
||||
"""Generates and prints the values as retrieved from greyfix."""
|
||||
|
||||
triplets = greyfix_parse_triplets()
|
||||
now = datetime.datetime.now()
|
||||
steps = [0 for i in range(0, settings['num_steps'])]
|
||||
greylist_step = 0
|
||||
|
||||
for triplet in triplets:
|
||||
if settings['greylist_step'] == 'yes' and triplet[6] == 0:
|
||||
greylist_step = greylist_step +1
|
||||
continue;
|
||||
|
||||
delta = now - triplet[3]
|
||||
step = delta.days / settings['step_size']
|
||||
step = min(step, settings['num_steps'] -1)
|
||||
# count the number of triplets in a group
|
||||
steps[ step ] = steps[ step ] +1
|
||||
|
||||
# print result counts for each group
|
||||
if settings['greylist_step'] == 'yes':
|
||||
print 'gl.value %i' % greylist_step
|
||||
for step, count in enumerate(steps):
|
||||
fieldname = 'd%s_%s' % convert_step_to_days(step)
|
||||
print '%s.value %i' % (fieldname, count)
|
||||
|
||||
|
||||
def print_config():
|
||||
"""Generates and prints a munin config for a given chart."""
|
||||
|
||||
print 'graph_title Greyfix triplets by age'
|
||||
print 'graph_vlabel Number of triplets'
|
||||
print 'graph_info The amount of triplets in the greyfix database with a certain age'
|
||||
print 'graph_category postfix'
|
||||
print 'graph_total All triplets'
|
||||
print 'graph_args --lower-limit 0 --base 1000'
|
||||
|
||||
if settings['greylist_step'] == 'yes':
|
||||
print 'gl.label Greylisted'
|
||||
print 'gl.info The number of greylisted triplets. These did not have a single pass (yet)'
|
||||
print 'gl.draw AREASTACK'
|
||||
print 'gl.colour aaaaaa'
|
||||
|
||||
steps = range(0, settings['num_steps'])
|
||||
for step in steps:
|
||||
days = convert_step_to_days(step)
|
||||
|
||||
fieldname = 'd%s_%s' % days
|
||||
label = 'Whitelisted for %s - %s days' % (days[0], days[1] if days[1] != '' else '...')
|
||||
info = 'The number of whitelisted triplets that is between %s and %s days old' % (days[0], days[1] if days[1] != '' else '...')
|
||||
|
||||
print '%s.label %s' % (fieldname, label)
|
||||
print '%s.info %s' % (fieldname, info)
|
||||
print '%s.draw AREASTACK' % fieldname
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
# read settings from config file / environment
|
||||
for key in settings.iterkeys():
|
||||
if key in os.environ:
|
||||
if os.environ[ key ].isdigit():
|
||||
settings[ key ] = int(os.environ[ key ])
|
||||
else:
|
||||
settings[ key ] = os.environ[ key ]
|
||||
#print '# setting %s updated to: %s' % (key, settings[ key ])
|
||||
|
||||
commands = ['fetch', 'autoconf', 'config']
|
||||
if len(sys.argv) > 1:
|
||||
command = sys.argv[1]
|
||||
else:
|
||||
command = commands[0]
|
||||
|
||||
if command not in commands:
|
||||
print '# command %s unknown, choose one of: %s' % (command, commands)
|
||||
sys.exit(1)
|
||||
|
||||
if command == 'fetch':
|
||||
print_fetch()
|
||||
elif command == 'config':
|
||||
print_config()
|
||||
elif command == 'autoconf':
|
||||
if os.path.exists( settings['greyfix'] ):
|
||||
print 'yes'
|
||||
else:
|
||||
print 'no (binary not found at %s)' % settings['greyfix']
|
|
@ -1,134 +0,0 @@
|
|||
#!/bin/sh
|
||||
# -*- sh -*-
|
||||
|
||||
: << =cut
|
||||
|
||||
=head1 NAME
|
||||
|
||||
postfix_mailqueue - Plugin to monitor postfix mail spools
|
||||
|
||||
=head1 ABOUT
|
||||
|
||||
A guide to postfix mail queue manageent can be found at
|
||||
L<http://www.postfix.org/QSHAPE_README.html#queues>
|
||||
|
||||
A summary:
|
||||
|
||||
=over 4
|
||||
|
||||
=item maildrop
|
||||
|
||||
Messages that have been submitted via the Postfix sendmail(1) command,
|
||||
but not yet brought into the main Postfix queue by the pickup(8)
|
||||
service.
|
||||
|
||||
=item hold
|
||||
|
||||
Messages placed in the "hold" queue stay there until the administrator
|
||||
intervenes
|
||||
|
||||
=item incoming
|
||||
|
||||
Inbound mail from the network, or mail picked up by the local
|
||||
pickup(8) daemon from the maildrop directory.
|
||||
|
||||
=item active
|
||||
|
||||
Messages that the queue manager has opened for delivery. Only a limited number
|
||||
of messages is allowed to enter the active queue (leaky bucket strategy, for a
|
||||
fixed delivery rate).
|
||||
|
||||
=item deferred
|
||||
|
||||
Mail that could not be delivered upon the first attempt. The queue manager
|
||||
implements exponential backoff by doubling the time between delivery attempts.
|
||||
|
||||
=item corrupt
|
||||
|
||||
Unreadable or damaged queue files are moved here for inspection.
|
||||
|
||||
=back
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
By default "postconf -h queue_directory" is used to determine the
|
||||
spool directory. Is postconf is not available in the $PATH then
|
||||
/var/spool/postfix is assumed. This can be overridden by the
|
||||
"spooldir" environment variable like so:
|
||||
|
||||
[postfix_mailqueue]
|
||||
env.spooldir /var/spool/postfix
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Unknown.
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
Unknown.
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
=begin comment
|
||||
|
||||
These magic markers are used by munin-node-configure when installing
|
||||
munin-node.
|
||||
|
||||
=end comment
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=cut
|
||||
|
||||
# atempt to get spooldir via postconf, but environment overrides.
|
||||
|
||||
# Remember that postconf is not available unless postfix is.
|
||||
POSTCONFSPOOL="$(postconf -h queue_directory 2>/dev/null || echo /var/spool/postfix)"
|
||||
SPOOLDIR=${spooldir:-$POSTCONFSPOOL}
|
||||
|
||||
. $MUNIN_LIBDIR/plugins/plugin.sh
|
||||
|
||||
case $1 in
|
||||
autoconf|detect)
|
||||
|
||||
if [ -d $SPOOLDIR ] ; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo "no (spooldir not found)"
|
||||
exit 0
|
||||
fi;;
|
||||
config)
|
||||
cat <<'EOF'
|
||||
graph_title Postfix Queue Size
|
||||
graph_vlabel KB in Queue
|
||||
graph_category postfix
|
||||
graph_total Total
|
||||
active.label active
|
||||
deferred.label deferred
|
||||
maildrop.label maildrop
|
||||
incoming.label incoming
|
||||
corrupt.label corrupt
|
||||
hold.label held
|
||||
EOF
|
||||
for field in active deferred maildrop incoming corrupt hold; do
|
||||
print_warning $field
|
||||
print_critical $field
|
||||
done
|
||||
exit 0;;
|
||||
esac
|
||||
|
||||
cd $SPOOLDIR >/dev/null 2>/dev/null || {
|
||||
echo "# Cannot cd to $SPOOLDIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
cat <<EOF
|
||||
deferred.value `du -sb $SPOOLDIR/* | grep deferred | awk '{print $1}'`
|
||||
active.value `du -sb $SPOOLDIR/* | grep active | awk '{print $1}'`
|
||||
maildrop.value `du -sb $SPOOLDIR/* | grep maildrop | awk '{print $1}'`
|
||||
incoming.value `du -sb $SPOOLDIR/* | grep incoming | awk '{print $1}'`
|
||||
corrupt.value `du -sb $SPOOLDIR/* | grep corrupt | awk '{print $1}'`
|
||||
hold.value `du -sb $SPOOLDIR/* | grep hold | awk '{print $1}'`
|
||||
EOF
|
|
@ -1,68 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Made by Boudewijn Ector, for Boudewijn Ector IT.
|
||||
# Comments can be sent to (boudewijn<AT>boudewijnector'dot'NL)
|
||||
# Loosely based on http://munin.projects.linpro.no/attachment/wiki/PluginCat/postfix_messages_hourly.txt
|
||||
# Script to show postfix stuff
|
||||
#
|
||||
# Modified by Paul Saunders <darac+munin@darac.org.uk>, 10 Dec 2010
|
||||
#
|
||||
# Parameters understood:
|
||||
#
|
||||
# config (required)
|
||||
# autoconf (optional - used by munin-config)
|
||||
#
|
||||
#
|
||||
# Magic markers (optional - used by munin-config and installation
|
||||
# scripts):
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
|
||||
LOGFILE=${logfile:-/var/log/maillog} # Allow user to specify logfile through env.logfile
|
||||
DATE=`date '+%b %e %H'`
|
||||
MAXLABEL=20
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [[ -r $LOGFILE ]]; then
|
||||
echo yes
|
||||
else
|
||||
echo no
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
|
||||
echo 'graph_title Postfix Mail Counter'
|
||||
echo 'graph_args --base 1000 -l 0'
|
||||
echo 'graph_vlabel Hourly Messages'
|
||||
echo 'recieved.label Delivered'
|
||||
echo 'sent.label Outgoing'
|
||||
echo 'rejecthelo.label Invalid HELO'
|
||||
echo 'rejectsenderdomain.label need FQDN'
|
||||
echo 'denyrelay.label Relay Denied'
|
||||
echo 'spamhaus.label Blocked using Spamhaus.org'
|
||||
echo 'spamcop.label Blocked using Spamcop'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -en "recieved.value "
|
||||
echo $(grep "status=sent (delivered" $LOGFILE | grep "$DATE" | wc -l)
|
||||
echo -n
|
||||
echo -en "sent.value "
|
||||
echo $(grep "status=sent (250" $LOGFILE | grep "$DATE" | wc -l)
|
||||
echo -en "rejecthelo.value "
|
||||
echo $(grep "Helo command rejected: need fully-qualified hostname" $LOGFILE | grep "$DATE" | wc -l)
|
||||
echo -en "rejectsenderdomain.value "
|
||||
echo $(grep "Sender address rejected: Domain not found" $LOGFILE | grep "$DATE" | wc -l)
|
||||
|
||||
|
||||
echo -en "denyrelay.value "
|
||||
echo $(grep "Relay access denied" $LOGFILE | grep "$DATE" | wc -l)
|
||||
echo -en "spamhaus.value "
|
||||
echo $(grep "blocked using sbl-xbl.spamhaus.org" $LOGFILE | grep "$DATE" | wc -l)
|
||||
echo -en "spamcop.value "
|
||||
echo $(grep "blocked using bl.spamcop.net" $LOGFILE | grep "$DATE" | wc -l)
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
#!/bin/sh
|
||||
# -*- sh -*-
|
||||
|
||||
: << =cut
|
||||
|
||||
=head1 NAME
|
||||
|
||||
postfix_mailqueue_ - Plugin to monitor postfix mail spools per running postfix
|
||||
|
||||
=head1 ABOUT
|
||||
|
||||
A guide to postfix mail queue manageent can be found at
|
||||
L<http://www.postfix.org/QSHAPE_README.html#queues>
|
||||
|
||||
A summary:
|
||||
|
||||
=over 4
|
||||
|
||||
=item maildrop
|
||||
|
||||
Messages that have been submitted via the Postfix sendmail(1) command,
|
||||
but not yet brought into the main Postfix queue by the pickup(8)
|
||||
service.
|
||||
|
||||
=item hold
|
||||
|
||||
Messages placed in the "hold" queue stay there until the administrator
|
||||
intervenes
|
||||
|
||||
=item incoming
|
||||
|
||||
Inbound mail from the network, or mail picked up by the local
|
||||
pickup(8) daemon from the maildrop directory.
|
||||
|
||||
=item active
|
||||
|
||||
Messages that the queue manager has opened for delivery. Only a limited number
|
||||
of messages is allowed to enter the active queue (leaky bucket strategy, for a
|
||||
fixed delivery rate).
|
||||
|
||||
=item deferred
|
||||
|
||||
Mail that could not be delivered upon the first attempt. The queue manager
|
||||
implements exponential backoff by doubling the time between delivery attempts.
|
||||
|
||||
=item corrupt
|
||||
|
||||
Unreadable or damaged queue files are moved here for inspection.
|
||||
|
||||
=back
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
Uses the last part of the symlink name to get the postfix queue directory for the config file.
|
||||
It then extract the queue path from the configuration file and uses it as a spooldir.
|
||||
A environment spooldir can be set as a fallback.
|
||||
|
||||
[postfix_mailqueue]
|
||||
env.spooldir /var/spool/postfix
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Unknown.
|
||||
|
||||
Extended to multiple queue use by Clemens Schwaighofer (gullevek@gullevek.org) in 2010.
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
Unknown.
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
=begin comment
|
||||
|
||||
These magic markers are used by munin-node-configure when installing
|
||||
munin-node.
|
||||
|
||||
=end comment
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=cut
|
||||
|
||||
# atempt to get spooldir via postconf, but environment overrides.
|
||||
|
||||
# Remember that postconf is not available unless postfix is.
|
||||
CONFIG=${0##*postfix_mailqueue_}
|
||||
CONFIG="/etc/"$CONFIG"/"
|
||||
POSTCONFSPOOL="$(postconf -c $CONFIG -h queue_directory 2>/dev/null || echo /var/spool/postfix)"
|
||||
SPOOLDIR=${spooldir:-$POSTCONFSPOOL}
|
||||
|
||||
. $MUNIN_LIBDIR/plugins/plugin.sh
|
||||
|
||||
case $1 in
|
||||
autoconf|detect)
|
||||
if [ -d $SPOOLDIR ] ; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo "no (spooldir not found)"
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
config)
|
||||
echo "graph_title Postfix Mailqueue $CONFIG";
|
||||
cat <<'EOF'
|
||||
graph_vlabel Mails in queue
|
||||
graph_category postfix
|
||||
graph_total Total
|
||||
active.label active
|
||||
deferred.label deferred
|
||||
maildrop.label maildrop
|
||||
incoming.label incoming
|
||||
corrupt.label corrupt
|
||||
hold.label held
|
||||
EOF
|
||||
for field in active deferred maildrop incoming corrupt hold; do
|
||||
print_warning $field
|
||||
print_critical $field
|
||||
done
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
cd $SPOOLDIR >/dev/null 2>/dev/null || {
|
||||
echo "# Cannot cd to $SPOOLDIR"
|
||||
exit 1
|
||||
}
|
||||
|
||||
cat <<EOF
|
||||
deferred.value `(test -d deferred && find deferred -type f) | wc -l`
|
||||
active.value `(test -d active && find active -type f) | wc -l`
|
||||
maildrop.value `(test -d maildrop && find maildrop -type f) | wc -l`
|
||||
incoming.value `(test -d incoming && find incoming -type f) | wc -l`
|
||||
corrupt.value `(test -d corrupt && find corrupt -type f) | wc -l`
|
||||
hold.value `( test -d hold && find hold -type f) | wc -l`
|
||||
EOF
|
|
@ -1,239 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
postfix_mailqueuelog_ - detailed stats for postfix queue data
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
Use the last part in the symlink to define which postfix you want to get stats from.
|
||||
|
||||
The user has to be set as root, else there might be some errors if
|
||||
the postfix config is not correctly set witht he alternate directories
|
||||
|
||||
[postfix_mailqueuelog_*]
|
||||
env.etcdir /etc/
|
||||
user root
|
||||
|
||||
=head2 DEFAULT CONFIGURATION
|
||||
|
||||
[postfix_mailqueuelog_*]
|
||||
user root
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Written in 2010 by Clemens Schwaighofer (gullevek@gullevek.org), based on the HoSaNIC module written by me
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
=begin comment
|
||||
|
||||
These magic markers are used by munin-node-configure when installing
|
||||
munin-node.
|
||||
|
||||
=end comment
|
||||
|
||||
#%# family=manual
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=head1 RANDOM COMMENTS
|
||||
|
||||
Would be cool if someone ported this to Munin::Plugin state file.
|
||||
|
||||
=cut
|
||||
|
||||
# get the postfix queue number to look for
|
||||
$0 =~ /postfix_mailqueuelog_([\w\d]+)$/;
|
||||
my $postfix = $1;
|
||||
#my $statefile = "$ENV{MUNIN_PLUGSTATE}/munin-plugin-".$postfix."_mailqueuelog.state";
|
||||
my $sum = 0;
|
||||
my $status = {};
|
||||
my @status_list = ('crefused', 'ctimeout', 'rtimeout', 'refusedtalk', 'nohost', 'msrefused', 'noroute', 'usernotfound', 'err450', 'err452', 'err421', 'err421a', 'err4', 'lostc', 'active', 'other');
|
||||
my $ETCDIR = $ENV{'etcdir'} || '/etc';
|
||||
|
||||
my $configdir = "$ETCDIR/$postfix/";
|
||||
|
||||
if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
|
||||
{
|
||||
if (-d $ETCDIR)
|
||||
{
|
||||
if (-d $configdir)
|
||||
{
|
||||
if (-r $configdir)
|
||||
{
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (config dir '$configdir' not readable)\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (config dir '$configdir' not found)\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (could not find etcdir '$ETCDIR')\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
#if ( -f $statefile)
|
||||
#{
|
||||
# open (IN, '<', $statefile) or die "Unable to open state-file: $!\n";
|
||||
# if (<IN> =~ /^sum:(\d+)/)
|
||||
# {
|
||||
# $sum = $1;
|
||||
# }
|
||||
# while (<IN>)
|
||||
# {
|
||||
# if (/^([0-9a-z.\-]+):(\d+)$/)
|
||||
# {
|
||||
# $status->{$1} = $2;
|
||||
# }
|
||||
# }
|
||||
# close IN;
|
||||
#}
|
||||
|
||||
if (! -d $configdir)
|
||||
{
|
||||
print "sum.value U\n";
|
||||
foreach my $i (@status_list)
|
||||
{
|
||||
print "r$i.value U\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
||||
parseLogfile($configdir);
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "config")
|
||||
{
|
||||
# descriptions for the rrd file
|
||||
my %descriptions = (
|
||||
'crefused' => 'Connection refused',
|
||||
'ctimeout' => 'Connection timed out',
|
||||
'rtimeout' => 'Lost connection',
|
||||
'refusedtalk' => 'Host refused connection',
|
||||
'nohost' => 'Host not found',
|
||||
'msrefused' => 'Mail service refused',
|
||||
'noroute' => 'Route not found',
|
||||
'usernotfound' => 'User not found',
|
||||
'err450' => '450 mailbox not okay (REJECT)',
|
||||
'err452' => '452 mailbox is full',
|
||||
'err421' => '421 service not okay (REJECT)',
|
||||
'err421a' => '421 service not okay (REJECT, SB)',
|
||||
'err4' => 'General 4xx error',
|
||||
'lostc' => 'Lost connection',
|
||||
'active' => 'Active running',
|
||||
'other' => 'Other error'
|
||||
);
|
||||
|
||||
|
||||
print "graph_title Postfix mailqueue log for $postfix\n";
|
||||
print "graph_args --base 1000 -l 0\n"; # numbers not bytes
|
||||
print "graph_vlabel Mails in Queue log\n";
|
||||
print "graph_scale no\n"; # so we do not print "micro, milli, kilo, etc"
|
||||
# print "graph_total Total\n";
|
||||
print "graph_category postfix\n";
|
||||
foreach my $i (@status_list)
|
||||
{
|
||||
if ($descriptions{$i})
|
||||
{
|
||||
print "r$i.label ".$descriptions{$i}."\n";
|
||||
print "r$i.type GAUGE\n";
|
||||
print "r$i.draw ".(!$field ? 'AREA' : 'STACK')."\n";
|
||||
print "r$i.min 0\n";
|
||||
$field = 'AREA';
|
||||
}
|
||||
}
|
||||
print "sum.label Sum\n";
|
||||
print "sum.type GAUGE\n";
|
||||
print "sum.draw LINE2\n";
|
||||
print "sum.min 0\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
print "sum.value $sum\n";
|
||||
foreach my $i (@status_list)
|
||||
{
|
||||
print "r$i.value ".($status->{$i} ? $status->{$i} : 0)."\n";
|
||||
}
|
||||
|
||||
#if(-l $statefile) {
|
||||
# die("$statefile is a symbolic link, refusing to touch it.");
|
||||
#}
|
||||
#open (OUT, '>', $statefile) or die "Unable to open statefile: $!\n";
|
||||
#print OUT "sum:$sum\n";
|
||||
#foreach my $i (@status_list)
|
||||
#{
|
||||
# print OUT "$i:".($status->{$i} ? $status->{$i} : 0)."\n";
|
||||
#}
|
||||
#close OUT;
|
||||
|
||||
sub parseLogfile
|
||||
{
|
||||
my ($fname) = @_;
|
||||
|
||||
# the search parts
|
||||
%search = (
|
||||
'crefused' => 'Connection refused',
|
||||
'ctimeout' => 'Connection timed out',
|
||||
'rtimeout' => 'read timeout',
|
||||
'refusedtalk' => 'refused to talk to me: 554',
|
||||
'nohost' => 'Host not found',
|
||||
'msrefused' => 'server refused mail service"',
|
||||
'noroute' => 'No route to host',
|
||||
'usernotfound' => 'address rejected',
|
||||
'err450' => ': 450 ',
|
||||
'err452' => ': 452 ',
|
||||
'err421' => ': 421 ',
|
||||
'err421a' => ': 421)',
|
||||
'err4' => 'said: 4',
|
||||
'lostc' => 'lost connection with',
|
||||
);
|
||||
|
||||
my $command = "mailq -C $fname";
|
||||
|
||||
open(FILE, "$command|") || die ("Cannot open $command: $!");
|
||||
while (<FILE>)
|
||||
{
|
||||
if (/^\w{10,}\*\s/o)
|
||||
{
|
||||
$status->{'active'} ++;
|
||||
}
|
||||
elsif (/^\s*\(/o)
|
||||
{
|
||||
$set = 0;
|
||||
foreach $i (@status_list)
|
||||
{
|
||||
if ($search{$i} && index($_, $search{$i}) >= 0 && !$set)
|
||||
{
|
||||
$status->{$i} ++;
|
||||
$set = 1;
|
||||
}
|
||||
}
|
||||
if (!$set)
|
||||
{
|
||||
$status->{'other'} ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
close(FILE) || die ("Cannot close $command: $!");
|
||||
|
||||
foreach $i (keys %{$status})
|
||||
{
|
||||
$sum += $status->{$i};
|
||||
}
|
||||
}
|
||||
|
||||
# vim:syntax=perl
|
|
@ -1,136 +0,0 @@
|
|||
#! /usr/bin/perl
|
||||
|
||||
# Copyright (C) 2008 Joey Schulze <joey@infodrom.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 dated June, 1991.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
|
||||
|
||||
# Rewrite of the postfix_mailstats plugin with Munin::Plugin
|
||||
|
||||
# Source: http://www.infodrom.org/Infodrom/tools/munin.html
|
||||
|
||||
# Supported configuration:
|
||||
#
|
||||
# [postfix_mailstats]
|
||||
# user root
|
||||
# group adm
|
||||
# env.logdir /var/log
|
||||
# env.logfile mail.log
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Munin::Plugin;
|
||||
|
||||
my $LOGDIR = $ENV{'logdir'} || '/var/log';
|
||||
my $LOGFILE = $ENV{'logfile'} || 'mail.log';
|
||||
my $logfile = $LOGDIR .'/'. $LOGFILE;
|
||||
|
||||
my $delivered;
|
||||
my %rejects;
|
||||
|
||||
sub autoconf
|
||||
{
|
||||
if (-d $LOGDIR) {
|
||||
if (-f $logfile) {
|
||||
if (open(my $f, $logfile)) {
|
||||
while (<$f>) {
|
||||
if (m,postfix/smtpd\[\d+\]: ,) {
|
||||
close $f;
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
print "no (no smtpd logs in logfile)\n";
|
||||
close $f;
|
||||
} else {
|
||||
print "no (logfile not readable)\n";
|
||||
}
|
||||
} else {
|
||||
print "no (logfile not found)\n";
|
||||
}
|
||||
} else {
|
||||
print "no (could not find logdir)\n";
|
||||
}
|
||||
exit 1;
|
||||
}
|
||||
|
||||
sub config
|
||||
{
|
||||
print "graph_title Postfix message throughput\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_vlabel mails / \${graph_period}\n";
|
||||
print "graph_scale no\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_category postfix\n";
|
||||
print "delivered.label delivered\n";
|
||||
print "delivered.type ABSOLUTE\n";
|
||||
print "delivered.draw AREA\n";
|
||||
print "delivered.min 0\n";
|
||||
foreach my $code (sort keys %rejects) {
|
||||
my $name = clean_fieldname('reject ' . $code);
|
||||
printf "%s.label reject %d\n", $name, $code;
|
||||
printf "%s.type ABSOLUTE\n", $name;
|
||||
printf "%s.draw STACK\n", $name;
|
||||
printf "%s.min 0\n", $name;
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
sub parse
|
||||
{
|
||||
my $logfile = shift;
|
||||
my $pos = shift;
|
||||
|
||||
my ($log,$rotated) = tail_open $logfile, $pos;
|
||||
|
||||
while (<$log>) {
|
||||
if (m,.* postfix/smtpd\[\d+\]: NOQUEUE: reject: [^:]+: (\d+) .*,) {
|
||||
$rejects{$1}++;
|
||||
next;
|
||||
} elsif (m/qmgr.*from=.*size=[0-9]*/) {
|
||||
$delivered++;
|
||||
next;
|
||||
}
|
||||
}
|
||||
return tail_close $log;
|
||||
}
|
||||
|
||||
autoconf if $#ARGV > -1 && $ARGV[0] eq "autoconf";
|
||||
|
||||
my @state_vector = restore_state;
|
||||
my $pos = shift @state_vector || 0;
|
||||
my $time = shift @state_vector;
|
||||
$delivered = shift @state_vector || 0;
|
||||
%rejects = @state_vector;
|
||||
|
||||
config if $#ARGV > -1 && $ARGV[0] eq "config";
|
||||
|
||||
if (defined $time) {
|
||||
if ($time < time-(60*5)+15) {
|
||||
$delivered = 0;
|
||||
$rejects{$_} = 0 foreach keys %rejects;
|
||||
$pos = parse $logfile, $pos;
|
||||
save_state $pos, time, $delivered, %rejects;
|
||||
}
|
||||
} else {
|
||||
# Prevent start peak
|
||||
$pos = (stat $logfile)[7];
|
||||
save_state $pos, time, $delivered;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
printf "delivered.value %d\n", $delivered;
|
||||
foreach my $code (sort keys %rejects) {
|
||||
printf "%s.value %d\n", clean_fieldname('reject ' . $code), $rejects{$code};
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
postfix_mailstats_ - Plugin to monitor the number of mails delivered and
|
||||
rejected by postfix
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
Uses the last part of the symlink name for grepping the correct data from the
|
||||
postfix log file. The name must be syslog_name from the postfix config.
|
||||
The environment settings still applay to this plugin.
|
||||
|
||||
Configuration parameters for /etc/munin/postfix_mailstats_,
|
||||
if you need to override the defaults below:
|
||||
|
||||
[postfix_mailstats]
|
||||
env.logdir - Which logfile to use
|
||||
env.logfile - What file to read in logdir
|
||||
|
||||
=head2 DEFAULT CONFIGURATION
|
||||
|
||||
[postfix_mailstats]
|
||||
env.logdir /var/log
|
||||
env.logfile mail.log
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Records show that the plugin was contributed by Nicolai Langfeldt in
|
||||
2003. Nicolai can't find anything in his email about this and expects
|
||||
the plugin is based on the corresponding exim plugin - to which it now
|
||||
bears no resemblence.
|
||||
|
||||
Extended for multiple queue use by Clemens Schwaighofer (gullevek@gullevek.org) in 2010.
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
=begin comment
|
||||
|
||||
These magic markers are used by munin-node-configure when installing
|
||||
munin-node.
|
||||
|
||||
=end comment
|
||||
|
||||
#%# family=manual
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=head1 RANDOM COMMENTS
|
||||
|
||||
Would be cool if someone ported this to Munin::Plugin for both state
|
||||
file and log tailing.
|
||||
|
||||
=cut
|
||||
|
||||
# get the postfix queue number to look for
|
||||
$0 =~ /postfix_mailstats_([\w\d]+)$/;
|
||||
my $postfix = $1;
|
||||
my $statefile = "$ENV{MUNIN_PLUGSTATE}/munin-plugin-".$postfix."_mailstats.state";
|
||||
my $pos;
|
||||
my $delivered = 0;
|
||||
my $rejects = {};
|
||||
my $LOGDIR = $ENV{'logdir'} || '/var/log';
|
||||
my $LOGFILE = $ENV{'logfile'} || 'mail.log';
|
||||
|
||||
my $logfile = "$LOGDIR/$LOGFILE";
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "autoconf")
|
||||
{
|
||||
my $logfile;
|
||||
if (-d $LOGDIR)
|
||||
{
|
||||
if (-f $logfile)
|
||||
{
|
||||
if (-r $logfile)
|
||||
{
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (logfile '$logfile' not readable)\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (logfile '$logfile' not found)\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (could not find logdir '$LOGDIR')\n";
|
||||
}
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
||||
if (-f $statefile)
|
||||
{
|
||||
open (IN, '<', $statefile) or die "Unable to open state-file: $!\n";
|
||||
if (<IN> =~ /^(\d+):(\d+)/)
|
||||
{
|
||||
($pos, $delivered) = ($1, $2);
|
||||
}
|
||||
while (<IN>)
|
||||
{
|
||||
if (/^([0-9a-z.\-]+):(\d+)$/)
|
||||
{
|
||||
$rejects->{$1} = $2;
|
||||
}
|
||||
}
|
||||
close IN;
|
||||
}
|
||||
|
||||
if (! -f $logfile)
|
||||
{
|
||||
print "delivered.value U\n";
|
||||
foreach my $i (sort keys %{$rejects})
|
||||
{
|
||||
print "r$i.value U\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
$startsize = (stat $logfile)[7];
|
||||
|
||||
if (!defined $pos)
|
||||
{
|
||||
# Initial run.
|
||||
$pos = $startsize;
|
||||
}
|
||||
|
||||
parseLogfile($logfile, $pos, $startsize);
|
||||
$pos = $startsize;
|
||||
|
||||
if ( $ARGV[0] and $ARGV[0] eq "config" )
|
||||
{
|
||||
print "graph_title Postfix message throughput for $postfix\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_vlabel mails / \${graph_period}\n";
|
||||
print "graph_scale no\n";
|
||||
print "graph_total Total\n";
|
||||
print "graph_category postfix\n";
|
||||
print "delivered.label delivered\n";
|
||||
print "delivered.type DERIVE\n";
|
||||
print "delivered.draw AREA\n";
|
||||
print "delivered.min 0\n";
|
||||
foreach my $i (sort keys %{$rejects})
|
||||
{
|
||||
print "r$i.label reject $i\n";
|
||||
print "r$i.type DERIVE\n";
|
||||
print "r$i.draw STACK\n";
|
||||
print "r$i.min 0\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
print "delivered.value $delivered\n";
|
||||
foreach my $i (sort keys %{$rejects})
|
||||
{
|
||||
print "r$i.value ", $rejects->{$i}, "\n";
|
||||
}
|
||||
|
||||
if (-l $statefile)
|
||||
{
|
||||
die ("$statefile is a symbolic link, refusing to touch it.");
|
||||
}
|
||||
open (OUT, '>', $statefile) or die "Unable to open statefile: $!\n";
|
||||
print OUT "$pos:$delivered\n";
|
||||
foreach my $i (sort keys %{$rejects})
|
||||
{
|
||||
print OUT "$i:", $rejects->{$i}, "\n";
|
||||
}
|
||||
close OUT;
|
||||
|
||||
sub parseLogfile
|
||||
{
|
||||
my ($fname, $start, $stop) = @_;
|
||||
open (LOGFILE, $fname)
|
||||
or die "Unable to open logfile $fname for reading: $!\n";
|
||||
seek (LOGFILE, $start, 0)
|
||||
or die "Unable to seek to $start in $fname: $!\n";
|
||||
|
||||
while (tell (LOGFILE) < $stop)
|
||||
{
|
||||
my $line = <LOGFILE>;
|
||||
chomp ($line);
|
||||
|
||||
if ($line =~ /qmgr.*from=.*size=[0-9]*/ ||
|
||||
$line =~ /$postfix\/smtp.* status=sent /)
|
||||
{
|
||||
$delivered++;
|
||||
}
|
||||
elsif ($line =~ /$postfix\/smtpd.*reject: \S+ \S+ \S+ (\S+)/ ||
|
||||
$line =~ /$postfix\/cleanup.* reject: (\S+)/)
|
||||
{
|
||||
$rejects->{$1}++;
|
||||
}
|
||||
}
|
||||
close(LOGFILE) or warn "Error closing $fname: $!\n";
|
||||
}
|
||||
|
||||
# vim:syntax=perl
|
|
@ -1,220 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
postfix_mailvolume - Plugin to monitor the volume of mails delivered
|
||||
by multiple postfix and stores per postfix delivered data.
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
Any postfix.
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
The following shows the default configuration.
|
||||
|
||||
[postfix*]
|
||||
env.logdir /var/log
|
||||
env.logfile syslog
|
||||
|
||||
=head2 Needed additional configuration
|
||||
|
||||
To correctly get all the postfix log data, the postfix system_log prefix names need to be defined with the env.postfix config setting.
|
||||
If this is not set, the script tries to find all the postfix config folders in /etc/postfix* and get the syslog names from there
|
||||
|
||||
env.postfix postfix10 postfix11 postfix12
|
||||
|
||||
=head1 INTERPRETATION
|
||||
|
||||
The plugin shows the number of bytes of mail that has passed through
|
||||
the postfix installation per postfix mailer running.
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None known
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
$Id: postfix_mailvolume.in 2314 2009-08-03 11:28:34Z ssm $
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Copyright (C) 2011.
|
||||
|
||||
Clemens Schwaighofer (gullevek@gullevek.org)
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Munin::Plugin;
|
||||
|
||||
my $pos = undef;
|
||||
my $syslog_name = '';
|
||||
my @postfix_syslog_name = ();
|
||||
my %volume = ();
|
||||
my @restore_state = ();
|
||||
my $i = 1;
|
||||
my $LOGDIR = $ENV{'logdir'} || '/var/log';
|
||||
my $LOGFILE = $ENV{'logfile'} || 'syslog';
|
||||
my $POSTFIX = $ENV{'postfix'} || '';
|
||||
# get the postfix syslog_name from the POSTFIX env var, if not set, find them in the /etc/postfix* type
|
||||
if (!$POSTFIX)
|
||||
{
|
||||
foreach my $dir (grep -d, glob "/etc/postfix*")
|
||||
{
|
||||
# remove the leading etc
|
||||
$dir =~ s/\/etc\///g;
|
||||
# add data to the postfix string
|
||||
$POSTFIX .= ' ' if ($POSTFIX);
|
||||
$POSTFIX .= $dir;
|
||||
}
|
||||
}
|
||||
if ($POSTFIX)
|
||||
{
|
||||
foreach my $config (split(/ /, $POSTFIX))
|
||||
{
|
||||
# find the syslog name
|
||||
$syslog_name = `postconf -c /etc/$config | grep "syslog_name"`;
|
||||
# remove any pending whitespace or line breaks
|
||||
chomp($syslog_name);
|
||||
$syslog_name =~ s/syslog_name = //g;
|
||||
# add this to the postfix syslog name array
|
||||
push(@postfix_syslog_name, $syslog_name);
|
||||
# also init set the syslog name 0
|
||||
$volume{$syslog_name} = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "Cannot get any postfix syslog_name data\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
sub parseLogfile
|
||||
{
|
||||
my ($fname, $start) = @_;
|
||||
|
||||
my ($LOGFILE, $rotated) = tail_open($fname, $start);
|
||||
|
||||
my $line;
|
||||
|
||||
while ($line =<$LOGFILE>)
|
||||
{
|
||||
chomp ($line);
|
||||
# get the postfix syslog name and the size
|
||||
if ($line =~ /\ (\w+)\/qmgr.*from=.*size=([0-9]+)/)
|
||||
{
|
||||
$volume{$1} += $2;
|
||||
}
|
||||
}
|
||||
return tail_close($LOGFILE);
|
||||
}
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "autoconf")
|
||||
{
|
||||
my $logfile;
|
||||
`which postconf >/dev/null 2>/dev/null`;
|
||||
if (!$?)
|
||||
{
|
||||
$logfile = "$LOGDIR/$LOGFILE";
|
||||
|
||||
if (-f $logfile)
|
||||
{
|
||||
if (-r "$logfile")
|
||||
{
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (logfile '$logfile' not readable)\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (logfile '$logfile' not found)\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print "no (postfix not found)\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "config")
|
||||
{
|
||||
print "graph_title Postfix bytes throughput per postfix\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_vlabel bytes / \${graph_period}\n";
|
||||
print "graph_scale yes\n";
|
||||
print "graph_category postfix\n";
|
||||
print "graph_total Throughput sum\n";
|
||||
# loop through the postfix names and create per config an entry
|
||||
foreach $syslog_name (@postfix_syslog_name)
|
||||
{
|
||||
print $syslog_name."_volume.label ".$syslog_name." throughput\n";
|
||||
print $syslog_name."_volume.type DERIVE\n";
|
||||
print $syslog_name."_volume.min 0\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
||||
my $logfile = "$LOGDIR/$LOGFILE";
|
||||
|
||||
if (! -f $logfile) {
|
||||
print "delivered.value U\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
@restore_state = restore_state();
|
||||
# first is pos, rest is postfix entries
|
||||
$pos = $restore_state[0];
|
||||
# per postfix values are store: postfix config,value
|
||||
for ($i = 1; $i < @restore_state; $i ++)
|
||||
{
|
||||
my ($key, $value) = split(/,/, $restore_state[$i]);
|
||||
$volume{$key} = $value;
|
||||
}
|
||||
|
||||
if (!$pos)
|
||||
{
|
||||
# No state file present. Avoid startup spike: Do not read log
|
||||
# file up to now, but remember how large it is now, and next
|
||||
# time read from there.
|
||||
|
||||
$pos = (stat $logfile)[7]; # File size
|
||||
foreach $syslog_name (@postfix_syslog_name)
|
||||
{
|
||||
$volume{$syslog_name} = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$pos = parseLogfile($logfile, $pos);
|
||||
}
|
||||
|
||||
@restore_state = ($pos);
|
||||
foreach $syslog_name (sort keys %volume)
|
||||
{
|
||||
print $syslog_name."_volume.value ".$volume{$syslog_name}."\n";
|
||||
push(@restore_state, $syslog_name.','.$volume{$syslog_name});
|
||||
}
|
||||
|
||||
# save the current state
|
||||
save_state(@restore_state);
|
||||
|
||||
# vim:syntax=perl
|
||||
|
||||
__END__
|
Loading…
Add table
Add a link
Reference in a new issue