root / plugins / other / assp-smtp-connection-statistics @ 31412baa
Historique | Voir | Annoter | Télécharger (4,61 ko)
| 1 | a200c77b | Diego Elio Pettenò | #!/usr/bin/perl |
|---|---|---|---|
| 2 | |||
| 3 | # +----------------------------------------------------------------------+ |
||
| 4 | # | A Munin Graph Plugin for ASSP | |
||
| 5 | # | [ assp-smtp-connection-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@guel.info ); # the list of admins receivced messages on an error |
||
| 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 | 4055fb15 | Steve Schnepp | my %index = ( # for Version 2 |
| 35 | a200c77b | Diego Elio Pettenò | 'from' => 25, # <-- index frame from ( a tweak for other ASSP Versions ) |
| 36 | 'to' => 38 # <-- index frame to ( "" ) |
||
| 37 | ); |
||
| 38 | |||
| 39 | # ----------------------------------------------------------------------- |
||
| 40 | my @muninlabel = ( |
||
| 41 | # SMTP Connection Statistics --> index 25..38 |
||
| 42 | "Accepted Logged SMTP Connections", |
||
| 43 | "SSL SMTP Connections", |
||
| 44 | "TLS SMTP Connections", |
||
| 45 | "Not Logged SMTP Connections", |
||
| 46 | "SMTP Connection Limits", |
||
| 47 | "Overall Limits", |
||
| 48 | "By IP Limits", |
||
| 49 | "By IP Frequency Limits", |
||
| 50 | "By Domain IP Limits", |
||
| 51 | "SMTP Connections Timeout", |
||
| 52 | "SMTP SSL-Connections Timeout", |
||
| 53 | "SMTP TLS-Connections Timeout", |
||
| 54 | "Denied SMTP Connections", |
||
| 55 | "SMTP damping" |
||
| 56 | ); |
||
| 57 | |||
| 58 | # ============= SANITY CHECKS ================ |
||
| 59 | unless( defined(@ARGV) ){
|
||
| 60 | $ARGV[0] = ""; |
||
| 61 | } |
||
| 62 | |||
| 63 | # =============== THE GET ==================== |
||
| 64 | if( $ARGV[0] eq "" ){
|
||
| 65 | my $agent = LWP::UserAgent->new(); |
||
| 66 | $agent->agent("$agentname");
|
||
| 67 | $response = $agent->get( $url ); |
||
| 68 | &response_error() unless $response->is_success; |
||
| 69 | @content = split( /\n/, $response->content ); |
||
| 70 | |||
| 71 | my $line = ""; |
||
| 72 | my $count = $index{from};
|
||
| 73 | my $label; |
||
| 74 | my( $key, $value, $last ); |
||
| 75 | while( 1 ){
|
||
| 76 | &finish() if( $count > $index{to} );
|
||
| 77 | $line = $content[$count]; |
||
| 78 | $count++; |
||
| 79 | chomp( $line ); |
||
| 80 | next if $line eq ""; # no empty lines |
||
| 81 | next if $line =~ /^\n$/; # no newlines |
||
| 82 | next if $line =~ /^\r$/; # or else |
||
| 83 | next if $line =~ /^\r\n$/; # http specific |
||
| 84 | ( $key, $value, $last) = split( /\|/, $line ); # split up to three values |
||
| 85 | $key =~ s/^\s//g; $key =~ s/\s$//g; # no spaces at the end and the begining |
||
| 86 | $value =~ s/^\s//g; $value =~ s/\s$//g; |
||
| 87 | $value =~ s/(\d*)\s*.*/$1/g; # remove more than one values from splited data |
||
| 88 | $value =~ s/[a-zA-Z\(\)\%]//g; # and not alphanummeric glyphs |
||
| 89 | $last =~ s/^\s//g; $last =~ s/\s$//g; |
||
| 90 | |||
| 91 | $label = $key; |
||
| 92 | $label =~ s/\s/\_/g; # generate a label |
||
| 93 | $label =~ s/\-/\_/g; # the subs glyph to underline |
||
| 94 | $label =~ s/[\(\)]//g; # no special glyphs feel free to add more |
||
| 95 | print "$label.value $value\n"; # print the result to the label |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | # =============== FUNCTIONS ================== |
||
| 100 | sub finish{
|
||
| 101 | exit 0; |
||
| 102 | } |
||
| 103 | sub response_error{
|
||
| 104 | if( $DEBUG ){
|
||
| 105 | foreach my $admin ( @to ){
|
||
| 106 | my %mail = ( smtp => "$smtp", To => "$admin", From => "$from", Subject => "Munin Plugin $pluginname", Message => "ERROR: $agentname at $muninnodename\n" ); |
||
| 107 | &sendmail(%mail) or die "ERROR: $Mail::Sendmail::error\n"; |
||
| 108 | |||
| 109 | if( $EMAILDEBUG ){
|
||
| 110 | print "OK. Log says:\n$Mail::Sendmail::log\n"; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | exit 1; # if no admin exists |
||
| 115 | } |
||
| 116 | |||
| 117 | # ============== MUNIN GRAPHER COINFIG ======= |
||
| 118 | |||
| 119 | if( $ARGV[0] eq "config" ){
|
||
| 120 | print "graph_title ASSP - SMTP Connection Statistics\n"; |
||
| 121 | print "graph_vlabel Counter in k,m\n"; |
||
| 122 | print "graph_category ASSP\n"; |
||
| 123 | |||
| 124 | my $label; |
||
| 125 | foreach my $key ( @muninlabel ){
|
||
| 126 | $label = $key; |
||
| 127 | $label =~ s/\s/\_/g; |
||
| 128 | $label =~ s/\-/\_/g; |
||
| 129 | $label =~ s/[\(\)]//g; |
||
| 130 | print "$label.label $key\n"; |
||
| 131 | } |
||
| 132 | exit 0; |
||
| 133 | } |
