Initial check-in. master
authorThomas Hochstein <thh@inter.net>
Sat, 23 Oct 2010 20:51:18 +0000 (22:51 +0200)
committerThomas Hochstein <thh@inter.net>
Sat, 23 Oct 2010 20:51:18 +0000 (22:51 +0200)
Signed-off-by: Thomas Hochstein <thh@inter.net>
.gitattributes [new file with mode: 0644]
.gitignore [new file with mode: 0644]
bind95 [new file with mode: 0755]
thh_exim_mailqueue [new file with mode: 0755]
thh_exim_mailstats [new file with mode: 0755]

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..176a458
--- /dev/null
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/bind95 b/bind95
new file mode 100755 (executable)
index 0000000..4a53ed4
--- /dev/null
+++ b/bind95
@@ -0,0 +1,124 @@
+#!/usr/bin/perl
+#
+# Copyright Jean-Samuel Reynaud <js.reynaud@free.fr>
+# Licenced under GPL v2
+#
+# We use this script to produce graph with munin for dns requests
+#
+# Thanks for Benjamin Pineau for perl cleaning and correction in non root
+# running
+#
+# modified for bind 9.5 by -thh 2009-04-15
+#
+# Magic markers
+#%# family=auto
+#%# capabilities=autoconf
+
+use strict;
+use warnings;
+
+# change those to reflect your bind configuration
+# stat file
+my $stat_file = "/var/log/named/stats";
+# rndc path
+my $rndc = "/usr/sbin/rndc";
+
+
+
+my $lst = { "success" => 1,
+            "referral" => 1,
+            "nxrrset" => 1,
+            "nxdomain" => 1,
+            "recursion" => 1,
+            "failure" => 1};
+
+#my $domain = $0;
+#$domain =~ s/^.*bind_([\w\d\._\-]*)$/$1/;
+my $domain = '';
+
+
+# Parse the statistic file
+sub parseFile {
+    my $dom = shift @_;
+    open(IN,"<$stat_file") or die "Can't open $stat_file : $!";
+
+    while (<IN>) {
+        chomp;
+        s/^ *//; 
+        my ($count,@type) = split(/ /,$_);
+        my $type = join(' ',@type);
+        #$zone = defined($zone) ? $zone : "";
+        #if ($zone eq $dom) {
+        #    if (defined $lst->{$type}) {
+        #        # only keep the latest occurence for each value
+        #        $lst->{$type} = $count;
+        #    }
+        #
+        #}
+        if ($type=~/successful answer/) {
+            $lst->{'success'} = $count;
+        } elsif ($type=~/FIXME/) {
+            $lst->{'referral'} = $count;
+        } elsif ($type=~/nxrrset/) {
+            $lst->{'nxrrset'} = $count;
+        } elsif ($type=~/resulted in NXDOMAIN/i) {
+            $lst->{'nxdomain'} = $count;
+        } elsif ($type=~/recursion/) {
+            $lst->{'recursion'} = $count;
+        } elsif ($type=~/failures/) {
+            $lst->{'failure'} = $count;
+        }
+    }
+
+    close(IN);
+    printf "%s.value %u\n", $_, $lst->{$_} foreach (keys %$lst);
+}
+
+
+
+# Config mode
+if ( defined($ARGV[0]) && $ARGV[0] eq "config" ) {
+    printf "graph_title Dns requests %s\n",($domain eq "" ? "all domains":$domain);
+    printf "graph_vlabel requests/s\n";
+    printf "graph_category network\n";
+    printf "graph_info This graph display dns requests for   %s\n",($domain eq "" ? "all domains":$domain);
+    printf "success.label Success\n";
+    printf "success.type COUNTER\n";
+
+    printf "referral.label Referral\n";
+    printf "referral.type COUNTER\n";
+
+    printf "nxrrset.label Nx RR set\n";
+    printf "nxrrset.type COUNTER\n";
+
+    printf "nxdomain.label NX domain\n";
+    printf "nxdomain.type COUNTER\n";
+
+    printf "recursion.label Recursion\n";
+    printf "recursion.type COUNTER\n";
+
+    printf "failure.label Failure\n";
+    printf "failure.type COUNTER\n";
+
+    exit 0;
+}
+
+if ( defined($ARGV[0]) && $ARGV[0] eq "autoconf" ) {
+    if (! -f $stat_file) {
+        printf "Unable to file bind stat file on %s",$stat_file;
+        exit 1;
+    }
+    if (! -f $rndc) {
+        printf "Unable to file rndc tool (configured : %s)",$rndc;
+        exit 1;
+    }
+    exit 0;
+}
+
+# Remove old stat file
+unlink ($stat_file);
+# Ask to bind to build new one
+`$rndc stats`;
+# Parse the stat file and return result
+parseFile($domain);
+
diff --git a/thh_exim_mailqueue b/thh_exim_mailqueue
new file mode 100755 (executable)
index 0000000..52b42f9
--- /dev/null
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# Plugin to monitor exim queue size
+#
+# Usage: Copy or link into /etc/munin/node.d/
+#
+# Parameters:
+#
+#      config   (required)
+#      autoconf (optional - used by munin-config)
+#
+# Config variables:
+#
+#      spooldir     - Override what exim says
+#      exim         - Where's exim?
+#      queuewarn    - When to warn
+#      queuecrit    - When to crit
+#
+# $Log$
+# Revision 1.4  2004/11/10 15:47:10  jimmyo
+# Made graph_title a parameter for generic/exim_mailqueue (patch by Torstein T. Svendsen, SF#1060834).
+#
+# Revision 1.3  2004/05/20 13:57:12  jimmyo
+# Set categories to some of the plugins.
+#
+# Revision 1.2  2004/01/29 19:39:00  jimmyo
+# Generic plugins now use printf instead of echo -n, as this is more portable (SF#885564)
+#
+# Revision 1.1  2004/01/02 18:50:00  jimmyo
+# Renamed occurrances of lrrd -> munin
+#
+# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
+# Import of LRRD CVS tree after renaming to Munin
+#
+# Revision 1.5  2003/11/07 17:43:16  jimmyo
+# Cleanups and log entries
+#
+#
+#
+# Magic markers (optional - used by installation scripts and
+# munin-config):
+#
+#%# family=auto
+#%# capabilities=autoconf
+
+DIRNAME=`dirname $0`
+SPOOLDIR='/var/spool/exim'
+#EXIM=`which exim 2>/dev/null || which exim4 2>/dev/null`
+EXIM='/usr/exim/bin/exim'
+QUEUEWARN=100
+QUEUECRIT=200
+GRAPHTITLE='Exim Mailqueue'
+
+if [ "$spooldir"  ]; then  SPOOLDIR=$spooldir ; fi
+if [ "$exim"      ]; then      EXIM=$exim     ; fi
+if [ "$queuewarn" ]; then QUEUEWARN=$queuewarn; fi
+if [ "$queuecrit" ]; then QUEUECRIT=$queuecrit; fi
+if [ "$graphtitle" ]; then GRAPHTITLE=$graphtitle; fi
+
+if [ "$SPOOLDIR" = "unset" ]
+then
+       SPOOLDIR=`($EXIM -bP spool_directory | awk '{ print $3 "/input" }') 2>/dev/null`
+fi
+
+if [ "$1" = "autoconf" ]; then
+       if ( $EXIM -bV 2>/dev/null >/dev/null ); then
+               if ( /usr/bin/find $SPOOLDIR -iname "*-H" -print 2>/dev/null >/dev/null ); then
+                       echo yes
+                       exit 0
+               else
+                       if [ $? -eq 1 ]; then
+                               echo "no (permission denied on spooldir)"
+                               exit 1
+                       else
+                               echo "no"
+                               exit 1
+                       fi
+               fi
+       else
+               if [ $? -eq 127 ]
+               then
+                       echo "no (exim not found)"
+                       exit 1
+               else
+                       echo no
+                       exit 1
+               fi
+       fi
+fi
+
+if [ "$1" = "config" ]; then
+        if [ ! -z $SPOOLDIR ];then
+       echo "graph_title $GRAPHTITLE"
+       echo 'graph_args --base 1000 -l 0'
+       echo 'graph_vlabel mails in queue'
+       echo 'graph_category Mail'
+       echo 'mails.label mails'
+       echo 'mails.draw AREA'
+       echo "mails.warning $QUEUEWARN"
+       echo "mails.critical $QUEUECRIT"
+       fi;
+       exit 0
+fi
+
+printf "mails.value "
+/usr/bin/find $SPOOLDIR -iname "*-H" -print 2>/dev/null |wc -l | sed 's/ *//'
diff --git a/thh_exim_mailstats b/thh_exim_mailstats
new file mode 100755 (executable)
index 0000000..f0a5af8
--- /dev/null
@@ -0,0 +1,381 @@
+#!/usr/bin/perl
+#
+# Plugin to monitor the number of mails received and delivered by exim.
+#
+# Usage: copy or link into /etc/munin/node.d/
+#
+# Parameters:
+#
+#      config   (required)
+#      autoconf (optional - used by munin-config)
+#
+# Config variables:
+#
+#      logdir       - Override what exim says
+#      exim         - Where's exim?
+#
+# $Log$
+# Revision 1.7.2.2  2005/03/12 23:07:17  jimmyo
+# Avoid negative spike in generic/exim_mailstats.
+#
+# Revision 1.7.2.1  2005/03/09 19:24:12  jimmyo
+# Thanks to Stephen Gran, generic/exim_mailstats now graphs rejects (Deb#295799).
+#
+# Revision 1.7  2004/12/10 18:51:43  jimmyo
+# linux/apt* has been forced to LANG=C, to get predictable output.
+#
+# Revision 1.6  2004/12/10 10:47:47  jimmyo
+# Change name from ${scale} to ${graph_period}, to be more consistent.
+#
+# Revision 1.5  2004/12/09 22:12:54  jimmyo
+# Added "graph_period" option, to make "graph_sums" usable.
+#
+# Revision 1.4  2004/11/21 00:16:56  jimmyo
+# Changed a lot of plugins so they use DERIVE instead of COUNTER.
+#
+# Revision 1.3  2004/11/10 15:54:49  jimmyo
+# Applied patch from Torstein T. Svendsen to generic/exim_mailstats, to handle logfiles with timestamps in the name (SF#1055214)
+#
+# Revision 1.2  2004/05/20 13:57:12  jimmyo
+# Set categories to some of the plugins.
+#
+# Revision 1.1  2004/01/02 18:50:00  jimmyo
+# Renamed occurrances of lrrd -> munin
+#
+# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
+# Import of LRRD CVS tree after renaming to Munin
+#
+# Revision 1.7  2003/11/15 11:10:28  jimmyo
+# Various fixes
+#
+# Revision 1.6  2003/11/07 17:43:16  jimmyo
+# Cleanups and log entries
+#
+#
+#
+# Magic markers (optional - used by munin-config and some installation
+# scripts):
+#
+#%# family=auto
+#%# capabilities=autoconf
+
+
+sub get_exim_logfile {
+    my ($spec, $type, $time) = @_;
+    chomp($spec);
+    $time = time() unless $time;
+    my $logfile = $spec;
+    $logfile =~ s/^log_file_path = //;
+    $logfile =~ s/\%s/$type/;
+
+    if( $logfile =~ /\%D/ ) {
+       my @t=localtime($time);
+       my $ts = sprintf("%04d%02d%02d",$t[5]+1900, $t[4]+1, $t[3]);
+       $logfile =~ s/\%D/$ts/g;
+    }        
+    my @lfiles = split(/\s?:\s?/, $logfile);
+    foreach (@lfiles) {
+       return $_ unless /^syslog/;
+    }
+}
+
+
+
+$statefile = "/var/lib/munin/plugin-state/plugin-exim_mailstats.state";
+$pos   = undef;
+$received = 0;
+$completed = 0;
+$rejected = 0;
+$greylisted = 0;
+$rbl = 0;
+$spam = 0;
+$sender = 0;
+$user = 0;
+$protocol = 0;
+$helo = 0;
+$virus = 0;
+$fakemx = 0;
+($dirname = $0) =~ s/[^\/]+$//;
+$EXIM = "/usr/sbin/exim";
+$EXIM = "/usr/sbin/exim4" if (-x "/usr/sbin/exim4"); # a Debianism
+$EXIM = $ENV{'exim'} if defined  $ENV{'exim'};
+$EXIM = "/usr/exim/bin/exim"; 
+$LOGDIR = $ENV{'logdir'} || undef;
+
+if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
+{
+    my $logfile;
+    
+    if(defined($LOGDIR)) {
+       if(! -d $LOGDIR) {
+           print "no (logdir does not exist)\n";
+           exit(1);
+       }
+       $logfile = $LOGDIR . '/mainlog';
+    } else {
+       my $logfilespec = `$EXIM -bP log_file_path 2>/dev/null`;
+       if (! $?)
+       {
+           $logfile = get_exim_logfile( $logfilespec, 'main');
+       }
+       elsif ($? eq "127")
+       {
+           print "no (exim not found)\n";
+       }
+       else
+       {
+           print "no\n";
+       }
+    }
+
+    if ($logfile)
+    {
+       if (-r "$logfile")
+       {
+           print "yes\n";
+           exit 0;
+       }
+       else
+       {
+           print "no (logfile not readable)\n";
+       }
+    }
+    exit 1;
+}
+
+
+my $logfilespec;
+
+if(defined($LOGDIR)) {
+    $logfilespec = '';
+    $logfile = $LOGDIR . '/' . 'mainlog';
+} else {
+    $logfilespec = `$EXIM -bP log_file_path`;
+    $logfile = get_exim_logfile( $logfilespec, 'main');
+}
+
+exit 1 unless -r $logfile;
+
+if( $logfilespec =~ /\%D/ ) {
+    $rotlogfile = get_exim_logfile( $logfilespec, 'main', (time()-(24*60*60)));
+} else {
+if (-f "$logfile.0")
+{
+    $rotlogfile = $logfile . ".0";
+}
+elsif (-f "$logfile.1")
+{
+    $rotlogfile = $logfile . ".1";
+}
+elsif (-f "$logfile.01")
+{
+    $rotlogfile = $logfile . ".01";
+}
+else
+{
+    $rotlogfile = $logfile . ".0";
+}
+}
+
+if ( $ARGV[0] and $ARGV[0] eq "config" )
+{
+    print "graph_title Exim mail throughput\n";
+    print "graph_args --base 1000 -l 0\n";
+    print "graph_vlabel mails/\${graph_period}\n";
+    print "graph_scale  no\n";
+    print "graph_category Mail\n";
+    print "received.label received\n";
+    print "received.type DERIVE\n";
+    print "received.min 0\n";
+    print "received.draw LINE\n";
+    print "completed.label completed\n";
+    print "completed.type DERIVE\n";
+    print "completed.min 0\n";
+#    print "completed.draw AREA\n";
+    print "rejected.label rejected (other)\n";
+    print "rejected.type DERIVE\n";
+    print "rejected.min 0\n";
+#    print "rejected.draw STACK\n";
+    print "rbl.label rejected (RBL)\n";
+    print "rbl.type DERIVE\n";
+    print "rbl.min 0\n";
+#    print "rbl.draw STACK\n";
+    print "spam.label rejected (spam)\n";
+    print "spam.type DERIVE\n";
+    print "spam.min 0\n";
+#    print "spam.draw STACK\n";
+    print "greylisted.label greylisted\n";
+    print "greylisted.type DERIVE\n";
+    print "greylisted.min 0\n";
+#    print "greylisted.draw STACK\n";
+    print "sender.label rejected (sender verify)\n";
+    print "sender.type DERIVE\n";
+    print "sender.min 0\n";
+#    print "sender.draw STACK\n";
+    print "user.label rejected (user unknown)\n";
+    print "user.type DERIVE\n";
+    print "user.min 0\n";
+#    print "user.draw STACK\n";
+    print "protocol.label rejected (protocol violation)\n";
+    print "protocol.type DERIVE\n";
+    print "protocol.min 0\n";
+#    print "protocol.draw STACK\n";
+    print "helo.label rejected (helo/ehlo)\n";
+    print "helo.type DERIVE\n";
+    print "helo.min 0\n";
+#    print "helo.draw STACK\n";
+    print "virus.label rejected (virus)\n";
+    print "virus.type DERIVE\n";
+    print "virus.min 0\n";
+#    print "virus.draw STACK\n";
+    print "fakemx.label rejected (fakeMX)\n";
+    print "fakemx.type DERIVE\n";
+    print "fakemx.min 0\n";
+#    print "fakemx.draw STACK\n";
+    exit 0;
+}
+
+if (! -f $logfile and ! -f $rotlogfile)
+{
+    print "completed.value U\n";
+    print "received.value U\n";
+    print "rejected.value U\n";
+    print "greylisted.value U\n";
+    print "rbl.value U\n";
+    print "spam.value U\n";
+    print "sender.value U\n";
+    print "user.value U\n";
+    print "protocol.value U\n";
+    print "helo.value U\n";
+    print "virus.value U\n";
+    print "fakemx.value U\n";
+    exit 0;
+}
+
+if (-f "$statefile")
+{
+    open (IN, "$statefile") or exit 4;
+       my $in = <IN>;
+    if ($in =~ /^(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+)/)
+    {   
+        ($pos, $received, $completed, $rejected, $greylisted, $rbl, $spam, $sender, $user, $protocol, $helo, $virus, $fakemx) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);
+    }
+    elsif ($in =~ /^(\d+):(\d+):(\d+):(\d+):(\d+):(\d+):(\d+)/)
+    {
+        ($pos, $received, $completed, $rejected, $greylisted, $rbl, $spam) = ($1, $2, $3, $4, $5, $6, $7);
+    }
+    elsif ($in =~ /^(\d+):(\d+):(\d+):(\d+)/)
+    {   
+        ($pos, $received, $completed, $rejected) = ($1, $2, $3, $4);
+    }
+
+    elsif ($in =~ /^(\d+):(\d+):(\d+)/)
+    {
+       ($pos, $received, $completed) = ($1, $2, $3);
+       $rejected = 0;
+    }
+    close IN;
+}
+
+$startsize = (stat $logfile)[7];
+
+if (!defined $pos)
+{
+    # Initial run.
+    $pos = $startsize;
+}
+
+if ($startsize < $pos)
+{
+    # Log rotated
+    parseEximfile ($rotlogfile, $pos, (stat $rotlogfile)[7]);
+    $pos = 0;
+}
+
+parseEximfile ($logfile, $pos, $startsize);
+$pos = $startsize;
+
+print "received.value $received\n";
+print "completed.value $completed\n";
+print "rejected.value $rejected\n";
+print "rbl.value $rbl\n";
+print "spam.value $spam\n";
+print "greylisted.value $greylisted\n";
+print "sender.value $sender\n";
+print "user.value $user\n";
+print "protocol.value $protocol\n";
+print "helo.value $helo\n";
+print "virus.value $virus\n";
+print "fakemx.value $fakemx\n";
+
+if(-l $statefile) {
+       die("$statefile is a symbolic link, refusing to touch it.");
+}                              
+open (OUT, ">$statefile") or exit 4;
+print OUT "$pos:$received:$completed:$rejected:$greylisted:$rbl:$spam:$sender:$user:$protocol:$helo:$virus:$fakemx\n";
+close OUT;
+
+sub parseEximfile 
+{    
+    my ($fname, $start, $stop) = @_;
+    open (LOGFILE, $fname) or exit 3;
+    seek (LOGFILE, $start, 0) or exit 2;
+
+    while (tell (LOGFILE) < $stop) 
+    {
+       my $line =<LOGFILE>;
+       chomp ($line);
+
+       if (substr ($line, 37,2 ) eq '<=') 
+       {
+           $received++;
+       } 
+       elsif (substr ($line, 37,9) eq 'Completed')
+       {
+           $completed++;
+       }
+        elsif ($line=~/greylisted\.$/)
+        {   
+            $greylisted++;
+        }
+        elsif ($line=~/in a RBL/)
+        {   
+            $rbl++;
+        }
+        elsif ($line=~/considered spam/)
+        {   
+            $spam++;
+        }
+        elsif ($line=~/sender verify/)
+        {   
+            $sender++;
+        }
+        elsif ($line=~/Unknown user/)
+        {   
+            $user++;
+        }
+        elsif ($line=~/synchronization error/)
+        {   
+            $protocol++;
+        }
+        elsif ($line=~/HELO\/EHLO/)
+        {   
+            $helo++;
+        }
+        elsif ($line=~/contains a virus/)
+        {   
+            $virus++;
+        }
+        elsif ($line=~/fakemx for/)
+        {   
+            $fakemx++;
+        }
+        elsif ($line=~/rejected/)
+        {
+            $rejected++;
+        }
+    }
+    close(LOGFILE);    
+}
+
+# vim:syntax=perl
This page took 0.018189 seconds and 4 git commands to generate.