| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Nagios::Plugin::POP3; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
26779
|
$Nagios::Plugin::POP3::VERSION = '1.001'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Nagios plugin for checking POP3 Servers |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
10
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
32
|
|
|
10
|
1
|
|
|
1
|
|
1030
|
use Nagios::Plugin; |
|
|
1
|
|
|
|
|
260828
|
|
|
|
1
|
|
|
|
|
62
|
|
|
11
|
1
|
|
|
1
|
|
1069
|
use Mail::POP3Client; |
|
|
1
|
|
|
|
|
94204
|
|
|
|
1
|
|
|
|
|
591
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub run { |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
|
my $p = Nagios::Plugin->new( |
|
19
|
|
|
|
|
|
|
usage => <
|
|
20
|
|
|
|
|
|
|
Usage: %s [ -v|--verbose ] [-h|--host=] [-u|--user=] [-p|--password=] [--count] [--delete] |
|
21
|
|
|
|
|
|
|
[ -c|--critical= ] |
|
22
|
|
|
|
|
|
|
[ -w|--warning= ] |
|
23
|
|
|
|
|
|
|
END_USAGE |
|
24
|
|
|
|
|
|
|
version => $Nagios::Plugin::POP3VERSION, |
|
25
|
|
|
|
|
|
|
blurb => q{Nagios plugin for POP3 mailboxes}, |
|
26
|
|
|
|
|
|
|
extra => <
|
|
27
|
|
|
|
|
|
|
Currently only two POP3 mailbox actions are supported: count and delete |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Count - Counts the number of messages on the server. The messages are not modified. |
|
30
|
|
|
|
|
|
|
Delete - Deletes all messages on the server (and returns then number deleted) |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
THRESHOLDs for -w and -c are specified 'min:max' or 'min:' or ':max' |
|
33
|
|
|
|
|
|
|
(or 'max'). If specified '\@min:max', a warning status will be generated |
|
34
|
|
|
|
|
|
|
if the count *is* inside the specified range. |
|
35
|
|
|
|
|
|
|
END_EXTRA |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$p->add_arg( |
|
39
|
|
|
|
|
|
|
spec => 'warning|w=s', |
|
40
|
|
|
|
|
|
|
help => <
|
|
41
|
|
|
|
|
|
|
-w, --warning=INTEGER:INTEGER |
|
42
|
|
|
|
|
|
|
Minimum and maximum number of allowable result, outside of which a |
|
43
|
|
|
|
|
|
|
warning will be generated. If omitted, no warning is generated. |
|
44
|
|
|
|
|
|
|
END_HELP |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$p->add_arg( |
|
48
|
|
|
|
|
|
|
spec => 'critical|c=s', |
|
49
|
|
|
|
|
|
|
help => <
|
|
50
|
|
|
|
|
|
|
-c, --critical=INTEGER:INTEGER |
|
51
|
|
|
|
|
|
|
Minimum and maximum number of the generated result, outside of |
|
52
|
|
|
|
|
|
|
which a critical will be generated. |
|
53
|
|
|
|
|
|
|
END_HELP |
|
54
|
|
|
|
|
|
|
); |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$p->add_arg( |
|
57
|
|
|
|
|
|
|
spec => 'host|h=s', |
|
58
|
|
|
|
|
|
|
default => 'localhost.localdomain', |
|
59
|
|
|
|
|
|
|
help => <
|
|
60
|
|
|
|
|
|
|
-h, --host |
|
61
|
|
|
|
|
|
|
POP3 Host (defaults to localhost.localdomain) |
|
62
|
|
|
|
|
|
|
END_HELP |
|
63
|
|
|
|
|
|
|
); |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$p->add_arg( |
|
66
|
|
|
|
|
|
|
spec => 'username|u=s', |
|
67
|
|
|
|
|
|
|
help => <
|
|
68
|
|
|
|
|
|
|
-u, --username |
|
69
|
|
|
|
|
|
|
POP3 Username |
|
70
|
|
|
|
|
|
|
END_HELP |
|
71
|
|
|
|
|
|
|
); |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$p->add_arg( |
|
74
|
|
|
|
|
|
|
spec => 'password|p=s', |
|
75
|
|
|
|
|
|
|
help => <
|
|
76
|
|
|
|
|
|
|
-p, --password |
|
77
|
|
|
|
|
|
|
POP3 password |
|
78
|
|
|
|
|
|
|
END_HELP |
|
79
|
|
|
|
|
|
|
); |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$p->add_arg( |
|
82
|
|
|
|
|
|
|
spec => 'count', |
|
83
|
|
|
|
|
|
|
help => <
|
|
84
|
|
|
|
|
|
|
--count |
|
85
|
|
|
|
|
|
|
Count the number of messages on the server. The messages on the server are not modified. |
|
86
|
|
|
|
|
|
|
This is the default action. |
|
87
|
|
|
|
|
|
|
END_HELP |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$p->add_arg( |
|
91
|
|
|
|
|
|
|
spec => 'delete', |
|
92
|
|
|
|
|
|
|
help => <
|
|
93
|
|
|
|
|
|
|
--delete |
|
94
|
|
|
|
|
|
|
Delete all messages on the server. Counts how many messages were deleted. |
|
95
|
|
|
|
|
|
|
END_HELP |
|
96
|
|
|
|
|
|
|
); |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Parse arguments and process standard ones (e.g. usage, help, version) |
|
99
|
0
|
|
|
|
|
|
$p->getopts; |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
0
|
0
|
|
|
|
if ( !defined $p->opts->warning && !defined $p->opts->critical ) { |
|
102
|
0
|
|
|
|
|
|
$p->nagios_die("You need to specify a threshold argument"); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $pop = new Mail::POP3Client( |
|
106
|
|
|
|
|
|
|
USER => $p->opts->username, |
|
107
|
|
|
|
|
|
|
PASSWORD => $p->opts->password, |
|
108
|
|
|
|
|
|
|
HOST => $p->opts->host, |
|
109
|
|
|
|
|
|
|
); |
|
110
|
0
|
|
|
|
|
|
my $count = $pop->Count; |
|
111
|
0
|
0
|
|
|
|
|
$p->nagios_die( "Error connecting to server: " . $p->opts->host ) if $count < 0; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
for my $i ( 1 .. $count ) { |
|
114
|
0
|
0
|
|
|
|
|
$pop->Delete($i) if $p->opts->delete,; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
0
|
|
|
|
|
|
$pop->Close(); |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
$p->nagios_exit( |
|
|
|
0
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
return_code => $p->check_threshold($count), |
|
120
|
|
|
|
|
|
|
message => ( $p->opts->delete ? 'Deleted ' : 'Counted ' ) . "$count message" . ( $count == 1 ? "\n" : "s\n" ), |
|
121
|
|
|
|
|
|
|
); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |