root / plugins / other / assp-message-statistics @ e5ce7492
Historique | Voir | Annoter | Télécharger (4,88 ko)
| 1 | a200c77b | Diego Elio Pettenò | #!/usr/bin/perl |
|---|---|---|---|
| 2 | |||
| 3 | # +----------------------------------------------------------------------+ |
||
| 4 | # | A Munin Graph Plugin for ASSP | |
||
| 5 | # | [ assp-message-statistics ] | |
||
| 6 | # +----------------------------------------------------------------------+ |
||
| 7 | # | Author: Enrico Labedzki | |
||
| 8 | # | Email: enrico.labdzki@brodos.de | |
||
| 9 | # | Last Modified: 2010-02-22 | |
||
| 10 | # | Licence: GPLv3 http://www.gnu.org/licenses/gpl-3.0.txt | |
||
| 11 | # +----------------------------------------------------------------------+ |
||
| 12 | |||
| 13 | use strict; |
||
| 14 | use warnings; |
||
| 15 | use File::Basename; |
||
| 16 | use LWP; |
||
| 17 | use Mail::Sendmail; |
||
| 18 | |||
| 19 | # -------------------------- DEBUG VARS --------------------------------- |
||
| 20 | my $DEBUG = 0; # for debugging purpose |
||
| 21 | my $EMAILDEBUG = 0; # for email debugging |
||
| 22 | my $pluginname = &basename( "$0" ); # get the basename of the plugin |
||
| 23 | my @to = qw( webmaster@bguel.info ); # the list of admins receivced messages on an |
||
| 24 | my $from = "$pluginname-at-host\@guel.info"; # the host from where it comes |
||
| 25 | my $muninnodename = "mail.guel.info"; # the Node from where it comes |
||
| 26 | my $smtp = "mail.guel.info"; # the smtp relay to send the mail |
||
| 27 | |||
| 28 | # ------------------------- GLOBAL VARS --------------------------------- |
||
| 29 | my $version = "1.0"; # UA Version |
||
| 30 | my $agentname = "$pluginname Munin Plugin V$version"; # UA String |
||
| 31 | my $url = "http://localhost:55553/"; # (defaults to localhost) |
||
| 32 | my $response = 0; # the server output |
||
| 33 | my @content = (); # the content we're retrive from $response |
||
| 34 | my %index # for Version 2 |
||
| 35 | 'from' => 66, # <-- index frame from ( a tweak for other ASSP Versions ) |
||
| 36 | 'to' => 100 # <-- index frame to ( "" ) |
||
| 37 | ); |
||
| 38 | |||
| 39 | |||
| 40 | # ----------------------------------------------------------------------- |
||
| 41 | my @muninlabel = ( |
||
| 42 | # Message Statistics --> index 66..100 |
||
| 43 | "Bayesian Hams", |
||
| 44 | "Whitelisted", |
||
| 45 | "Local", |
||
| 46 | "Noprocessing", |
||
| 47 | "Spamlover Spams Passed", |
||
| 48 | "Bayesian Spams", |
||
| 49 | "Domains Blacklisted", |
||
| 50 | "HELO Blacklisted", |
||
| 51 | "HELO Invalid", |
||
| 52 | "HELO Forged", |
||
| 53 | "Missing MX", |
||
| 54 | "Missing PTR", |
||
| 55 | "Invalid PTR", |
||
| 56 | "Spam Collected Messages", |
||
| 57 | "Penalty Trap Messages", |
||
| 58 | "Bad Attachments", |
||
| 59 | "Viruses Detected", |
||
| 60 | "Sender Regex", |
||
| 61 | "Bomb Regex", |
||
| 62 | "Penalty Box", |
||
| 63 | "Message Scoring", |
||
| 64 | "Invalid Local Sender", |
||
| 65 | "Invalid Internal Mail", |
||
| 66 | "Scripts", |
||
| 67 | "SPF Failures", |
||
| 68 | "RBL Failures", |
||
| 69 | "URIBL Failures", |
||
| 70 | "Max Errors Exceeded", |
||
| 71 | "Delayed", |
||
| 72 | "Empty Recipient", |
||
| 73 | "Not SRS Signed Bounces", |
||
| 74 | "MSGID Signature", |
||
| 75 | "DKIM", |
||
| 76 | "DKIM pre Check", |
||
| 77 | "Pre Header" |
||
| 78 | ); |
||
| 79 | |||
| 80 | # ============= SANITY CHECKS ================ |
||
| 81 | unless( defined(@ARGV) ){
|
||
| 82 | $ARGV[0] = ""; |
||
| 83 | } |
||
| 84 | |||
| 85 | # =============== THE GET ==================== |
||
| 86 | if( $ARGV[0] eq "" ){
|
||
| 87 | my $agent = LWP::UserAgent->new(); |
||
| 88 | $agent->agent("$agentname");
|
||
| 89 | $response = $agent->get( $url ); |
||
| 90 | &response_error() unless $response->is_success; |
||
| 91 | @content = split( /\n/, $response->content ); |
||
| 92 | |||
| 93 | my $line = ""; |
||
| 94 | my $count = $index{from};
|
||
| 95 | my $label; |
||
| 96 | my( $key, $value, $last ); |
||
| 97 | while( 1 ){
|
||
| 98 | &finish() if( $count > $index{to} );
|
||
| 99 | $line = $content[$count]; |
||
| 100 | $count++; |
||
| 101 | chomp( $line ); |
||
| 102 | next if $line eq ""; # no empty lines |
||
| 103 | next if $line =~ /^\n$/; # no newlines |
||
| 104 | next if $line =~ /^\r$/; # or else |
||
| 105 | next if $line =~ /^\r\n$/; # http specific |
||
| 106 | ( $key, $value, $last) = split( /\|/, $line ); # split up to three values |
||
| 107 | $key =~ s/^\s//g; $key =~ s/\s$//g; # no spaces at the end and the begining |
||
| 108 | $value =~ s/^\s//g; $value =~ s/\s$//g; |
||
| 109 | $value =~ s/(\d*)\s*.*/$1/g; # remove more than one values from splited data |
||
| 110 | $value =~ s/[a-zA-Z\(\)\%]//g; # and not alphanummeric glyphs |
||
| 111 | $last =~ s/^\s//g; $last =~ s/\s$//g; |
||
| 112 | |||
| 113 | $label = $key; |
||
| 114 | $label =~ s/\s/\_/g; # generate a label |
||
| 115 | $label =~ s/\-/\_/g; # the subs glyph to underline |
||
| 116 | $label =~ s/[\(\)]//g; # no special glyphs feel free to add more |
||
| 117 | print "$label.value $value\n"; # print the result to the label |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | # =============== FUNCTIONS ================== |
||
| 122 | sub finish{
|
||
| 123 | exit 0; |
||
| 124 | } |
||
| 125 | sub response_error{
|
||
| 126 | if( $DEBUG ){
|
||
| 127 | foreach my $admin ( @to ){
|
||
| 128 | my %mail = ( smtp => "$smtp", To => "$admin", From => "$from", Subject => "Munin Plugin $pluginname", Message => "ERROR: $agentname at $muninnodename\n" ); |
||
| 129 | &sendmail(%mail) or die "ERROR: $Mail::Sendmail::error\n"; |
||
| 130 | |||
| 131 | if( $EMAILDEBUG ){
|
||
| 132 | print "OK. Log says:\n$Mail::Sendmail::log\n"; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | exit 1; # if no admin exists |
||
| 137 | } |
||
| 138 | |||
| 139 | # ============== MUNIN GRAPHER COINFIG ======= |
||
| 140 | |||
| 141 | if( $ARGV[0] eq "config" ){
|
||
| 142 | print "graph_title ASSP - Message Statistics\n"; |
||
| 143 | print "graph_vlabel Counter in k,m\n"; |
||
| 144 | print "graph_category ASSP\n"; |
||
| 145 | |||
| 146 | my $label; |
||
| 147 | foreach my $key ( @muninlabel ){
|
||
| 148 | $label = $key; |
||
| 149 | $label =~ s/\s/\_/g; |
||
| 150 | $label =~ s/\-/\_/g; |
||
| 151 | $label =~ s/[\(\)]//g; |
||
| 152 | print "$label.label $key\n"; |
||
| 153 | } |
||
| 154 | exit 0; |
||
| 155 | } |
