changeset 3 | ec3c5514cd94 |
parent 2 | e5c47baa6743 |
2:e5c47baa6743 | 3:ec3c5514cd94 |
---|---|
1 #! /usr/bin/perl |
1 #! /usr/bin/perl |
2 # $Id$ |
2 # $Id$ |
3 # $URL$ |
3 # $URL$ |
4 my $USAGE = <<'#'; |
|
5 Usage: $ME --init <user> |
|
6 $ME {-w|--warning rate} {-c|--crit rate} |
|
7 |
|
8 rate is in mails/h |
|
9 |
|
10 # |
|
4 |
11 |
5 use strict; |
12 use strict; |
6 use warnings; |
13 use warnings; |
7 use File::Basename; |
14 use File::Basename; |
8 use Getopt::Long; |
15 use Getopt::Long; |
26 autoreply => "local", |
33 autoreply => "local", |
27 smtp => "remote", |
34 smtp => "remote", |
28 ); |
35 ); |
29 |
36 |
30 my %opt = (init => undef, |
37 my %opt = (init => undef, |
38 cleanup => undef, |
|
31 warn => undef, |
39 warn => undef, |
32 crit => undef, |
40 crit => undef, |
41 help => undef, |
|
33 update => 1, |
42 update => 1, |
34 ); |
43 ); |
35 |
44 |
36 my %exim; |
45 my %exim; |
37 my %state = (time => 0, |
46 my %state = (time => 0, |
43 out => { local => 0, remote => 0 }, |
52 out => { local => 0, remote => 0 }, |
44 }, |
53 }, |
45 ); |
54 ); |
46 |
55 |
47 sub init(); |
56 sub init(); |
57 sub cleanup(); |
|
48 |
58 |
49 MAIN: { |
59 MAIN: { |
50 |
60 |
51 GetOptions("init=s" => \$opt{init}, |
61 GetOptions("init=s" => \$opt{init}, |
52 "warn=s" => \$opt{warn}, # rate mails/h |
62 "warn=s" => \$opt{warn}, # rate mails/h |
53 "crit=s" => \$opt{crit}, # rate mails/h |
63 "crit=s" => \$opt{crit}, # rate mails/h |
54 "update!" => \$opt{update}, |
64 "update!" => \$opt{update}, |
65 "cleanup"=> \$opt{cleanup}, |
|
66 "help" => \$opt{help}, |
|
55 ) or die "Bad Usage\n"; |
67 ) or die "Bad Usage\n"; |
56 |
68 |
69 if ($opt{help}) { |
|
70 print eval qq{"$USAGE"}; |
|
71 exit 0; |
|
72 } |
|
73 |
|
57 $opt{init} and do { init(); exit }; |
74 $opt{init} and do { init(); exit }; |
75 $opt{cleanup} and do { cleanup(); exit }; |
|
58 |
76 |
59 # read the exim (cache) file and the status |
77 # read the exim (cache) file and the status |
60 die "$0: $CACHE_FILE not found ($!). Try $0 --help\n" |
78 die "$0: $CACHE_FILE not found ($!). Try $0 --help\n" |
61 if not -r $CACHE_FILE; |
79 if not -r $CACHE_FILE; |
62 die "$0: $STATE_FILE not found ($!). Try $0 --help\n" |
80 die "$0: $STATE_FILE not found ($!). Try $0 --help\n" |
183 |
201 |
184 exit 0; |
202 exit 0; |
185 |
203 |
186 } |
204 } |
187 |
205 |
206 sub cleanup() { |
|
207 unlink $STATE_FILE, $CACHE_FILE; |
|
208 foreach ($STATE_FILE, $CACHE_FILE) { |
|
209 while ("/" ne ($_ = dirname($_))) { |
|
210 rmdir; |
|
211 } |
|
212 } |
|
213 } |
|
214 |
|
188 sub init() { |
215 sub init() { |
189 |
216 |
190 # noch sind wir root (hoffentlich) |
217 # noch sind wir root (hoffentlich) |
191 -d $STATE_DIR or do { |
218 -d $STATE_DIR or do { |
192 require File::Path; |
219 require File::Path; |
230 |
257 |
231 } |
258 } |
232 |
259 |
233 __END__ |
260 __END__ |
234 |
261 |
235 my $FILE = "/var/log/exim4/mainlog"; |
|
236 my $STATUS = "/var/run/nagios3/$ME/%s"; |
|
237 |
|
238 sub unkn(@) { print "UNKNOWN @_\n"; exit 3 } |
|
239 sub crit(@) { print "CRIT @_\n"; exit 2 } |
|
240 sub warn(@) { print "WARN @_\n"; exit 1 } |
|
241 sub ok(@) { print "OK @_\n"; exit 0 } |
|
242 |
|
243 open(my $log, $FILE) or critical("file $FILE not found"); |
|
244 |
|
245 __END__ |
|
246 # vim:sts=4 sw=4 aw ai sm: |
262 # vim:sts=4 sw=4 aw ai sm: |