| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Monitoring::Plugin; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
130945
|
use Monitoring::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
1398
|
|
|
4
|
6
|
|
|
6
|
|
38
|
use Params::Validate qw(:all); |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
982
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
152
|
use 5.006; |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
191
|
|
|
7
|
6
|
|
|
6
|
|
27
|
use strict; |
|
|
6
|
|
|
|
|
25
|
|
|
|
6
|
|
|
|
|
209
|
|
|
8
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
237
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
28
|
use Carp; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
451
|
|
|
11
|
6
|
|
|
6
|
|
41
|
use base qw(Class::Accessor::Fast); |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
3990
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Monitoring::Plugin->mk_accessors(qw( |
|
14
|
|
|
|
|
|
|
shortname |
|
15
|
|
|
|
|
|
|
perfdata |
|
16
|
|
|
|
|
|
|
messages |
|
17
|
|
|
|
|
|
|
opts |
|
18
|
|
|
|
|
|
|
threshold |
|
19
|
|
|
|
|
|
|
)); |
|
20
|
|
|
|
|
|
|
|
|
21
|
6
|
|
|
6
|
|
16993
|
use Exporter; |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
7520
|
|
|
22
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
23
|
|
|
|
|
|
|
our @EXPORT = (@STATUS_CODES); |
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = qw(%ERRORS %STATUS_TEXT); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# CPAN stupidly won't index this module without a literal $VERSION here, |
|
27
|
|
|
|
|
|
|
# so we're forced to duplicate it explicitly |
|
28
|
|
|
|
|
|
|
# Make sure you update $Monitoring::Plugin::Functions::VERSION too |
|
29
|
|
|
|
|
|
|
our $VERSION = "0.38"; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
|
32
|
24
|
|
|
24
|
0
|
22867
|
my $class = shift; |
|
33
|
|
|
|
|
|
|
# my %args = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
24
|
|
|
|
|
732
|
my %args = validate( @_, |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
|
|
|
|
|
|
shortname => 0, |
|
38
|
|
|
|
|
|
|
usage => 0, |
|
39
|
|
|
|
|
|
|
version => 0, |
|
40
|
|
|
|
|
|
|
url => 0, |
|
41
|
|
|
|
|
|
|
plugin => 0, |
|
42
|
|
|
|
|
|
|
blurb => 0, |
|
43
|
|
|
|
|
|
|
extra => 0, |
|
44
|
|
|
|
|
|
|
license => 0, |
|
45
|
|
|
|
|
|
|
timeout => 0 |
|
46
|
|
|
|
|
|
|
}, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
24
|
|
|
|
|
189
|
my $shortname = Monitoring::Plugin::Functions::get_shortname(\%args); |
|
50
|
24
|
100
|
|
|
|
90
|
delete $args{shortname} if (exists $args{shortname}); |
|
51
|
24
|
|
|
|
|
212
|
my $self = { |
|
52
|
|
|
|
|
|
|
shortname => $shortname, |
|
53
|
|
|
|
|
|
|
perfdata => [], # to be added later |
|
54
|
|
|
|
|
|
|
messages => { |
|
55
|
|
|
|
|
|
|
warning => [], |
|
56
|
|
|
|
|
|
|
critical => [], |
|
57
|
|
|
|
|
|
|
ok => [] |
|
58
|
|
|
|
|
|
|
}, |
|
59
|
|
|
|
|
|
|
opts => undef, # see below |
|
60
|
|
|
|
|
|
|
threshold => undef, # defined later |
|
61
|
|
|
|
|
|
|
}; |
|
62
|
24
|
|
|
|
|
74
|
bless $self, $class; |
|
63
|
24
|
100
|
|
|
|
74
|
if (exists $args{usage}) { |
|
64
|
1
|
|
|
|
|
639
|
require Monitoring::Plugin::Getopt; |
|
65
|
1
|
|
|
|
|
16
|
$self->opts( new Monitoring::Plugin::Getopt(%args) ); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
24
|
|
|
|
|
118
|
return $self; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub add_perfdata { |
|
71
|
2
|
|
|
2
|
1
|
51
|
my ($self, %args) = @_; |
|
72
|
2
|
|
|
|
|
411
|
require Monitoring::Plugin::Performance; |
|
73
|
2
|
|
|
|
|
9
|
my $perf = Monitoring::Plugin::Performance->new(%args); |
|
74
|
2
|
|
|
|
|
19
|
push @{$self->perfdata}, $perf; |
|
|
2
|
|
|
|
|
5
|
|
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
sub all_perfoutput { |
|
77
|
56
|
|
|
56
|
0
|
478
|
my $self = shift; |
|
78
|
56
|
|
|
|
|
101
|
return join(" ", map {$_->perfoutput} (@{$self->perfdata})); |
|
|
27
|
|
|
|
|
80
|
|
|
|
56
|
|
|
|
|
129
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub set_thresholds { |
|
82
|
6
|
|
|
6
|
1
|
435
|
my $self = shift; |
|
83
|
6
|
|
|
|
|
1101
|
require Monitoring::Plugin::Threshold; |
|
84
|
6
|
|
|
|
|
20
|
return $self->threshold( Monitoring::Plugin::Threshold->set_thresholds(@_)); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# MP::Functions wrappers |
|
88
|
|
|
|
|
|
|
sub plugin_exit { |
|
89
|
19
|
|
|
19
|
1
|
10622
|
my $self = shift; |
|
90
|
19
|
|
|
|
|
154
|
Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self }); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
sub plugin_die { |
|
93
|
23
|
|
|
23
|
1
|
14685
|
my $self = shift; |
|
94
|
23
|
|
|
|
|
197
|
Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self }); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
sub nagios_exit { |
|
97
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
98
|
0
|
|
|
|
|
0
|
Monitoring::Plugin::Functions::plugin_exit(@_, { plugin => $self }); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
sub nagios_die { |
|
101
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
102
|
0
|
|
|
|
|
0
|
Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self }); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
sub die { |
|
105
|
6
|
|
|
6
|
1
|
12
|
my $self = shift; |
|
106
|
6
|
|
|
|
|
20
|
Monitoring::Plugin::Functions::plugin_die(@_, { plugin => $self }); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
sub max_state { |
|
109
|
0
|
|
|
0
|
1
|
0
|
Monitoring::Plugin::Functions::max_state(@_); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
sub max_state_alt { |
|
112
|
0
|
|
|
0
|
1
|
0
|
Monitoring::Plugin::Functions::max_state_alt(@_); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# top level interface to Monitoring::Plugin::Threshold |
|
116
|
|
|
|
|
|
|
sub check_threshold { |
|
117
|
20
|
|
|
20
|
1
|
2197
|
my $self = shift; |
|
118
|
|
|
|
|
|
|
|
|
119
|
20
|
|
|
|
|
22
|
my %args; |
|
120
|
|
|
|
|
|
|
|
|
121
|
20
|
100
|
66
|
|
|
112
|
if ( $#_ == 0 && (! ref $_[0] || ref $_[0] eq "ARRAY" )) { # one positional param |
|
|
|
|
66
|
|
|
|
|
|
122
|
14
|
|
|
|
|
34
|
%args = (check => shift); |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
else { |
|
125
|
6
|
|
|
|
|
309
|
%args = validate ( @_, { # named params |
|
126
|
|
|
|
|
|
|
check => 1, |
|
127
|
|
|
|
|
|
|
warning => 0, |
|
128
|
|
|
|
|
|
|
critical => 0, |
|
129
|
|
|
|
|
|
|
} ); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# in order of preference, get warning and critical from |
|
133
|
|
|
|
|
|
|
# 1. explicit arguments to check_threshold |
|
134
|
|
|
|
|
|
|
# 2. previously explicitly set threshold object |
|
135
|
|
|
|
|
|
|
# 3. implicit options from Getopts object |
|
136
|
19
|
100
|
66
|
|
|
114
|
if ( exists $args{warning} || exists $args{critical} ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
137
|
3
|
|
|
|
|
16
|
$self->set_thresholds( |
|
138
|
|
|
|
|
|
|
warning => $args{warning}, |
|
139
|
|
|
|
|
|
|
critical => $args{critical}, |
|
140
|
|
|
|
|
|
|
); |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
elsif ( defined $self->threshold ) { |
|
143
|
|
|
|
|
|
|
# noop |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
elsif ( defined $self->opts ) { |
|
146
|
1
|
|
|
|
|
23
|
$self->set_thresholds( |
|
147
|
|
|
|
|
|
|
warning => $self->opts->warning, |
|
148
|
|
|
|
|
|
|
critical => $self->opts->critical, |
|
149
|
|
|
|
|
|
|
); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
else { |
|
152
|
4
|
|
|
|
|
37
|
return UNKNOWN; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
15
|
|
|
|
|
134
|
return $self->threshold->get_status($args{check}); |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# top level interface to my Monitoring::Plugin::Getopt object |
|
159
|
|
|
|
|
|
|
sub add_arg { |
|
160
|
3
|
|
|
3
|
1
|
1069
|
my $self = shift; |
|
161
|
3
|
50
|
|
|
|
9
|
$self->opts->arg(@_) if $self->_check_for_opts; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
sub getopts { |
|
164
|
2
|
|
|
2
|
1
|
600
|
my $self = shift; |
|
165
|
2
|
50
|
|
|
|
6
|
$self->opts->getopts(@_) if $self->_check_for_opts; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _check_for_opts { |
|
169
|
5
|
|
|
5
|
|
5
|
my $self = shift; |
|
170
|
5
|
100
|
|
|
|
14
|
croak |
|
171
|
|
|
|
|
|
|
"You have to supply a 'usage' param to Monitoring::Plugin::new() if you want to use Getopts from your Monitoring::Plugin object." |
|
172
|
|
|
|
|
|
|
unless ref $self->opts() eq 'Monitoring::Plugin::Getopt'; |
|
173
|
3
|
|
|
|
|
23
|
return $self; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
179
|
|
|
|
|
|
|
# MP::Functions::check_messages helpers and wrappers |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub add_message { |
|
182
|
18
|
|
|
18
|
1
|
1233
|
my $self = shift; |
|
183
|
18
|
|
|
|
|
42
|
my ($code, @messages) = @_; |
|
184
|
|
|
|
|
|
|
|
|
185
|
18
|
100
|
100
|
|
|
718
|
croak "Invalid error code '$code'" |
|
186
|
|
|
|
|
|
|
unless defined($ERRORS{uc $code}) || defined($STATUS_TEXT{$code}); |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# Store messages using strings rather than numeric codes |
|
189
|
16
|
100
|
|
|
|
47
|
$code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code}; |
|
190
|
16
|
|
|
|
|
29
|
$code = lc $code; |
|
191
|
16
|
100
|
100
|
|
|
345
|
croak "Error code '$code' not supported by add_message" |
|
192
|
|
|
|
|
|
|
if $code eq 'unknown' || $code eq 'dependent'; |
|
193
|
|
|
|
|
|
|
|
|
194
|
14
|
50
|
|
|
|
49
|
$self->messages($code, []) unless $self->messages->{$code}; |
|
195
|
14
|
|
|
|
|
93
|
push @{$self->messages->{$code}}, @messages; |
|
|
14
|
|
|
|
|
35
|
|
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub check_messages { |
|
199
|
30
|
|
|
30
|
1
|
18563
|
my $self = shift; |
|
200
|
30
|
|
|
|
|
107
|
my %args = @_; |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# Add object messages to any passed in as args |
|
203
|
30
|
|
|
|
|
66
|
for my $code (qw(critical warning ok)) { |
|
204
|
90
|
|
50
|
|
|
208
|
my $messages = $self->messages->{$code} || []; |
|
205
|
90
|
100
|
|
|
|
543
|
if ($args{$code}) { |
|
206
|
48
|
100
|
|
|
|
121
|
unless (ref $args{$code} eq 'ARRAY') { |
|
207
|
4
|
50
|
|
|
|
15
|
if ($code eq 'ok') { |
|
208
|
4
|
|
|
|
|
18
|
$args{$code} = [ $args{$code} ]; |
|
209
|
|
|
|
|
|
|
} else { |
|
210
|
0
|
|
|
|
|
0
|
croak "Invalid argument '$code'" |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
} |
|
213
|
48
|
|
|
|
|
50
|
push @{$args{$code}}, @$messages; |
|
|
48
|
|
|
|
|
130
|
|
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
else { |
|
216
|
42
|
|
|
|
|
114
|
$args{$code} = $messages; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
30
|
|
|
|
|
156
|
Monitoring::Plugin::Functions::check_messages(%args); |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1; |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
#vim:et:sw=4 |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
__END__ |