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