Projet

Général

Profil

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

root / plugins / postfix / postfix_mailqueuelog_ @ a64e85b2

Historique | Voir | Annoter | Télécharger (5,18 ko)

1
#!/usr/bin/perl -w
2
# -*- perl -*-
3

    
4
=head1 NAME
5

    
6
postfix_mailqueuelog_ - detailed stats for postfix queue data
7

    
8
=head1 CONFIGURATION
9

    
10
Use the last part in the symlink to define which postfix you want to get stats from.
11

    
12
The user has to be set as root, else there might be some errors if
13
the postfix config is not correctly set witht he alternate directories
14

    
15
 [postfix_mailqueuelog_*]
16
 env.etcdir /etc/
17
 user root
18

    
19
=head2 DEFAULT CONFIGURATION
20

    
21
 [postfix_mailqueuelog_*]
22
 user root
23

    
24
=head1 AUTHOR
25

    
26
Written in 2010 by Clemens Schwaighofer (gullevek@gullevek.org), based on the HoSaNIC module written by me
27

    
28
=head1 LICENSE
29

    
30
GPLv2
31

    
32
=head1 MAGIC MARKERS
33

    
34
=begin comment
35

    
36
These magic markers are used by munin-node-configure when installing
37
munin-node.
38

    
39
=end comment
40

    
41
 #%# family=manual
42
 #%# capabilities=autoconf
43

    
44
=head1 RANDOM COMMENTS
45

    
46
Would be cool if someone ported this to Munin::Plugin state file.
47

    
48
=cut
49

    
50
# get the postfix queue number to look for
51
$0 =~ /postfix_mailqueuelog_([\w\d\-]+)$/;
52
my $postfix = $1;
53
#my $statefile = "$ENV{MUNIN_PLUGSTATE}/munin-plugin-".$postfix."_mailqueuelog.state";
54
my $sum = 0;
55
my $status = {};
56
my @status_list = ('crefused', 'ctimeout', 'rtimeout', 'refusedtalk', 'nohost', 'msrefused', 'noroute', 'usernotfound', 'err450', 'err452', 'err421', 'err421a', 'err4', 'lostc', 'active', 'other');
57
my $ETCDIR  = $ENV{'etcdir'}  || '/etc';
58

    
59
my $configdir = "$ETCDIR/$postfix/";
60

    
61
if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
62
{
63
    if (-d $ETCDIR)
64
    {
65
		if (-d $configdir)
66
		{
67
            if (-r $configdir)
68
            {
69
                print "yes\n";
70
                exit 0;
71
            }
72
            else
73
            {
74
                print "no (config dir '$configdir' not readable)\n";
75
            }
76
		}
77
		else
78
		{
79
		    print "no (config dir '$configdir' not found)\n";
80
		}
81
    }
82
    else
83
    {
84
        print "no (could not find etcdir '$ETCDIR')\n";
85
    }
86
    exit 0;
87
}
88

    
89
#if ( -f $statefile)
90
#{
91
#    open (IN, '<', $statefile) or die "Unable to open state-file: $!\n";
92
#    if (<IN> =~ /^sum:(\d+)/)
93
#    {
94
#		$sum = $1;
95
#    }
96
#    while (<IN>)
97
#    {
98
#    	if (/^([0-9a-z.\-]+):(\d+)$/)
99
#		{
100
#			$status->{$1} = $2;
101
#		}
102
#    }
103
#    close IN;
104
#}
105

    
106
if (! -d $configdir)
107
{
108
    print "sum.value U\n";
109
    foreach my $i (@status_list)
110
    {
111
    	print "r$i.value U\n";
112
    }
113
    exit 0;
114
}
115

    
116

    
117
parseLogfile($configdir);
118

    
119
if ($ARGV[0] and $ARGV[0] eq "config")
120
{
121
	# descriptions for the rrd file
122
	my %descriptions = (
123
		'crefused' => 'Connection refused',
124
		'ctimeout' => 'Connection timed out',
125
		'rtimeout' => 'Lost connection',
126
		'refusedtalk' => 'Host refused connection',
127
		'nohost' => 'Host not found',
128
		'msrefused' => 'Mail service refused',
129
		'noroute' => 'Route not found',
130
		'usernotfound' => 'User not found',
131
		'err450' => '450 mailbox not okay (REJECT)',
132
		'err452' => '452 mailbox is full',
133
		'err421' => '421 service not okay (REJECT)',
134
		'err421a' => '421 service not okay (REJECT, SB)',
135
		'err4' => 'General 4xx error',
136
		'lostc' => 'Lost connection',
137
		'active' => 'Active running',
138
		'other' => 'Other error'
139
	);
140

    
141

    
142
    print "graph_title Postfix mailqueue log for $postfix\n";
143
    print "graph_args --base 1000 -l 0\n"; # numbers not bytes
144
    print "graph_vlabel Mails in Queue log\n";
145
    print "graph_scale  no\n"; # so we do not print "micro, milli, kilo, etc"
146
#    print "graph_total  Total\n";
147
    print "graph_category postfix\n";
148
    foreach my $i (@status_list)
149
    {
150
		if ($descriptions{$i})
151
		{
152
			print "r$i.label ".$descriptions{$i}."\n";
153
			print "r$i.type GAUGE\n";
154
			print "r$i.draw ".(!$field ? 'AREA' : 'STACK')."\n";
155
			print "r$i.min 0\n";
156
			$field = 'AREA';
157
		}
158
    }
159
    print "sum.label Sum\n";
160
    print "sum.type GAUGE\n";
161
    print "sum.draw LINE2\n";
162
    print "sum.min 0\n";
163
    exit 0;
164
}
165

    
166
print "sum.value $sum\n";
167
foreach my $i (@status_list)
168
{
169
	print "r$i.value ".($status->{$i} ? $status->{$i} : 0)."\n";
170
}
171

    
172
#if(-l $statefile) {
173
#	die("$statefile is a symbolic link, refusing to touch it.");
174
#}				
175
#open (OUT, '>', $statefile) or die "Unable to open statefile: $!\n";
176
#print OUT "sum:$sum\n";
177
#foreach my $i (@status_list)
178
#{
179
#	print OUT "$i:".($status->{$i} ? $status->{$i} : 0)."\n";
180
#}
181
#close OUT;
182

    
183
sub parseLogfile 
184
{    
185
    my ($fname) = @_;
186

    
187
	# the search parts
188
	%search = (
189
		'crefused' => 'Connection refused',
190
		'ctimeout' => 'Connection timed out',
191
		'rtimeout' => 'read timeout',
192
		'refusedtalk' => 'refused to talk to me: 554',
193
		'nohost' => 'Host not found',
194
		'msrefused' => 'server refused mail service"',
195
		'noroute' => 'No route to host',
196
		'usernotfound' => 'address rejected',
197
		'err450' => ': 450 ',
198
		'err452' => ': 452 ',
199
		'err421' => ': 421 ',
200
		'err421a' => ': 421)',
201
		'err4' => 'said: 4',
202
		'lostc' => 'lost connection with',
203
	);
204

    
205
	my $command = "mailq -C $fname";
206

    
207
    open(FILE, "$command|") || die ("Cannot open $command: $!");
208
    while (<FILE>)
209
	{
210
		if (/^\w{10,}\*\s/o)
211
		{
212
			$status->{'active'} ++;
213
		}
214
	    elsif (/^\s*\(/o)
215
		{
216
			$set = 0;
217
			foreach $i (@status_list)
218
			{
219
				if ($search{$i} && index($_, $search{$i}) >= 0 && !$set)
220
				{
221
					$status->{$i} ++;
222
					$set = 1;
223
				}
224
			}
225
			if (!$set)
226
			{
227
				$status->{'other'} ++;
228
			}
229
        }
230
	}
231
	close(FILE) || die ("Cannot close $command: $!");
232

    
233
	foreach $i (keys %{$status})
234
	{
235
		$sum += $status->{$i};
236
	}
237
}
238

    
239
# vim:syntax=perl