Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / mail / qmailsend_plesk @ 430d68ff

Historique | Voir | Annoter | Télécharger (2,72 ko)

1 75128651 Moser Oliver
#!/usr/bin/perl -w
2
#
3
# Plugin to show amount of individual outgoing smtp-replies per hour
4
#
5
# Contributed by H?kon Nessj?en <lunatic@cpan.org>
6
#
7
# Magic markers - optional - used by installation scripts and
8
# munin-config:
9
#
10
#%# family=manual
11
#%# capabilities=autoconf
12
13
use strict;
14
15
my $logpath = $ENV{'logpath'} || '/usr/local/psa/var/log/';
16
17
if (exists $ARGV[0]) {
18
  if ($ARGV[0] eq "autoconf") {
19
	if (-f "${logpath}maillog") {
20
		print "yes\n";
21
		exit 0;
22
	} else {
23
		print STDERR "no (Cannot find ${logpath}maillog. Please specify env.logpath)\n";
24
		exit 1;
25
	}
26
  }
27
}
28
29
my %responses;
30
31
#	'453' => 'You have no mail (atrn)',
32
#	'503' => 'Bad sequence of commands',
33
34
my %descriptions = (
35
	'250' => 'Mail delivery ok',
36
	'421' => 'Service unavail or timeout',
37
	'441' => 'No established connection',
38
	'442' => 'Connection Died',
39
	'450' => 'Mbox unavail or greylist',
40
	'451' => 'Err processing or greylist',
41
	'452' => 'Insufficient storage space',
42
	'454' => 'TLS not available now',
43
	'472' => 'DNS transaction timeout',
44
	'500' => 'Unsolicited mail',
45
	'501' => 'Syntax error',
46
	'511' => 'Blocked or blacklisted',
47
	'522' => 'Mailbox full',
48
	'550' => 'Mailbox unavailable',
49
	'551' => 'User not local',
50
	'552' => 'Content or storage error',
51
	'553' => 'Mailbox name not allowed',
52
	'554' => 'Session failed or blocked',
53
	'557' => 'Too many duplicate msgs'
54
);
55
56
#open(DATA,"cat ${logpath}maillog $logpath\@* | perl -ne'm/Remote_host_said:_(\\d+)/ && print \$1.\"\n\";' | sort | uniq -c|");
57
open(DATA,"grep -E '_\\(\\#4\\.4\\.1\\)|_\\(\\#4\\.4\\.2\\)|Remote_host_said:_' ${logpath}maillog | sed 's/_(\\#4\\.4\\.1)/\\/Remote_host_said:_441_/; s/_(\\#4\\.4\\.2)/\\/Remote_host_said:_442_/' | perl -ne'm/Remote_host_said:_(\\d+)/ && print \$1.\"\n\";' | sort -n | uniq -c|");
58
while (<DATA>) {
59
	if (m/\s*(\d+)\s+(\d+)/) {
60
		$responses{$2} = $1;
61
	}
62
}
63
close(DATA);
64
65
66
if (exists $ARGV[0]) {
67
  if ($ARGV[0] eq 'config') {
68
        print "graph_title Qmail outgoing SMTP replies\n";
69
        print "graph_args --base 1000 -l 0 \n";
70
        print "graph_vlabel replies/hour\n";
71
        print "graph_category Mail\n";
72
	print "graph_total Total\n" if (keys (%descriptions) > 1);
73
	print "graph_info This graph shows qmail-send transaction response codes.\n";
74
        print "graph_order res" . join(" res", sort by_code keys %descriptions) . "\n";
75
	foreach (sort by_code keys %descriptions) {
76
		my $name = 'res' . $_;
77
	        print "$name.label ";
78
		print $_." ".$descriptions{$_}."\n";
79
	        print "$name.min 0\n";
80
	        print "$name.draw LINE1\n";
81
	}
82
        exit;
83
  }
84
}
85
86
foreach (sort by_code keys %descriptions) {
87
  #print "res$_.value ".int($responses{$_})."\n";
88
  if (exists $responses{$_}) {
89
	print "res$_.value $responses{$_}\n";
90
  }else{
91
	print "res$_.value 0\n";
92
  }
93
}
94
95
sub by_code {
96
	return $a cmp $b;
97
}