1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

- have some dirs

This commit is contained in:
Steve Schnepp 2012-02-13 18:24:46 +01:00
parent 0b089ea777
commit 08346aac58
687 changed files with 0 additions and 0 deletions

110
plugins/postfix/amavis-debian Executable file
View file

@ -0,0 +1,110 @@
#!/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}"

185
plugins/postfix/greyfix Executable file
View file

@ -0,0 +1,185 @@
#!/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']

View file

@ -0,0 +1,134 @@
#!/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

View file

@ -0,0 +1,68 @@
#!/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)

136
plugins/postfix/postfix_mailstats Executable file
View file

@ -0,0 +1,136 @@
#! /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};
}