| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Nagios::Monitoring::Plugin; |
|
3
|
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
115129
|
use Nagios::Monitoring::Plugin::Functions qw(:codes %ERRORS %STATUS_TEXT @STATUS_CODES); |
|
|
5
|
|
|
|
|
18
|
|
|
|
5
|
|
|
|
|
1302
|
|
|
5
|
5
|
|
|
5
|
|
31
|
use Params::Validate qw(:all); |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
912
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
30
|
use strict; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
119
|
|
|
8
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
194
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
27
|
use Carp; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
349
|
|
|
11
|
5
|
|
|
5
|
|
36
|
use base qw(Class::Accessor::Fast); |
|
|
5
|
|
|
|
|
19
|
|
|
|
5
|
|
|
|
|
4875
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Nagios::Monitoring::Plugin->mk_accessors(qw( |
|
14
|
|
|
|
|
|
|
shortname |
|
15
|
|
|
|
|
|
|
perfdata |
|
16
|
|
|
|
|
|
|
messages |
|
17
|
|
|
|
|
|
|
opts |
|
18
|
|
|
|
|
|
|
threshold |
|
19
|
|
|
|
|
|
|
)); |
|
20
|
|
|
|
|
|
|
|
|
21
|
5
|
|
|
5
|
|
18015
|
use Exporter; |
|
|
5
|
|
|
|
|
14
|
|
|
|
5
|
|
|
|
|
6653
|
|
|
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 $Nagios::Monitoring::Plugin::Functions::VERSION too |
|
29
|
|
|
|
|
|
|
our $VERSION = "0.50"; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
|
32
|
24
|
|
|
24
|
0
|
15619
|
my $class = shift; |
|
33
|
|
|
|
|
|
|
# my %args = @_; |
|
34
|
|
|
|
|
|
|
|
|
35
|
24
|
|
|
|
|
753
|
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
|
|
|
|
|
178
|
my $shortname = Nagios::Monitoring::Plugin::Functions::get_shortname(\%args); |
|
50
|
24
|
100
|
|
|
|
80
|
delete $args{shortname} if (exists $args{shortname}); |
|
51
|
24
|
|
|
|
|
141
|
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
|
|
|
|
|
51
|
bless $self, $class; |
|
63
|
24
|
100
|
|
|
|
64
|
if (exists $args{usage}) { |
|
64
|
1
|
|
|
|
|
954
|
require Nagios::Monitoring::Plugin::Getopt; |
|
65
|
1
|
|
|
|
|
14
|
$self->opts( new Nagios::Monitoring::Plugin::Getopt(%args) ); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
24
|
|
|
|
|
104
|
return $self; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub add_perfdata { |
|
71
|
2
|
|
|
2
|
1
|
44
|
my ($self, %args) = @_; |
|
72
|
2
|
|
|
|
|
1139
|
require Nagios::Monitoring::Plugin::Performance; |
|
73
|
2
|
|
|
|
|
17
|
my $perf = Nagios::Monitoring::Plugin::Performance->new(%args); |
|
74
|
2
|
|
|
|
|
30
|
push @{$self->perfdata}, $perf; |
|
|
2
|
|
|
|
|
8
|
|
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
sub all_perfoutput { |
|
77
|
56
|
|
|
56
|
0
|
333
|
my $self = shift; |
|
78
|
56
|
|
|
|
|
64
|
return join(" ", map {$_->perfoutput} (@{$self->perfdata})); |
|
|
27
|
|
|
|
|
134
|
|
|
|
56
|
|
|
|
|
125
|
|
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub set_thresholds { |
|
82
|
6
|
|
|
6
|
1
|
450
|
my $self = shift; |
|
83
|
6
|
|
|
|
|
1792
|
require Nagios::Monitoring::Plugin::Threshold; |
|
84
|
6
|
|
|
|
|
30
|
return $self->threshold( Nagios::Monitoring::Plugin::Threshold->set_thresholds(@_)); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# NP::Functions wrappers |
|
88
|
|
|
|
|
|
|
sub nagios_exit { |
|
89
|
19
|
|
|
19
|
1
|
3987
|
my $self = shift; |
|
90
|
19
|
|
|
|
|
72
|
Nagios::Monitoring::Plugin::Functions::nagios_exit(@_, { plugin => $self }); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
sub nagios_die { |
|
93
|
23
|
|
|
23
|
1
|
6872
|
my $self = shift; |
|
94
|
23
|
|
|
|
|
85
|
Nagios::Monitoring::Plugin::Functions::nagios_die(@_, { plugin => $self }); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
sub die { |
|
97
|
6
|
|
|
6
|
1
|
11
|
my $self = shift; |
|
98
|
6
|
|
|
|
|
33
|
Nagios::Monitoring::Plugin::Functions::nagios_die(@_, { plugin => $self }); |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
sub max_state { |
|
101
|
0
|
|
|
0
|
1
|
0
|
Nagios::Monitoring::Plugin::Functions::max_state(@_); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
sub max_state_alt { |
|
104
|
0
|
|
|
0
|
1
|
0
|
Nagios::Monitoring::Plugin::Functions::max_state_alt(@_); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# top level interface to Nagios::Monitoring::Plugin::Threshold |
|
108
|
|
|
|
|
|
|
sub check_threshold { |
|
109
|
20
|
|
|
20
|
1
|
1782
|
my $self = shift; |
|
110
|
|
|
|
|
|
|
|
|
111
|
20
|
|
|
|
|
31
|
my %args; |
|
112
|
|
|
|
|
|
|
|
|
113
|
20
|
100
|
66
|
|
|
107
|
if ( $#_ == 0 && (! ref $_[0] || ref $_[0] eq "ARRAY" )) { # one positional param |
|
|
|
|
66
|
|
|
|
|
|
114
|
14
|
|
|
|
|
39
|
%args = (check => shift); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
else { |
|
117
|
6
|
|
|
|
|
343
|
%args = validate ( @_, { # named params |
|
118
|
|
|
|
|
|
|
check => 1, |
|
119
|
|
|
|
|
|
|
warning => 0, |
|
120
|
|
|
|
|
|
|
critical => 0, |
|
121
|
|
|
|
|
|
|
} ); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# in order of preference, get warning and critical from |
|
125
|
|
|
|
|
|
|
# 1. explicit arguments to check_threshold |
|
126
|
|
|
|
|
|
|
# 2. previously explicitly set threshold object |
|
127
|
|
|
|
|
|
|
# 3. implicit options from Getopts object |
|
128
|
19
|
100
|
66
|
|
|
147
|
if ( exists $args{warning} || exists $args{critical} ) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$self->set_thresholds( |
|
130
|
|
|
|
|
|
|
warning => $args{warning}, |
|
131
|
|
|
|
|
|
|
critical => $args{critical}, |
|
132
|
3
|
|
|
|
|
12
|
); |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
elsif ( defined $self->threshold ) { |
|
135
|
|
|
|
|
|
|
# noop |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
elsif ( defined $self->opts ) { |
|
138
|
1
|
|
|
|
|
18
|
$self->set_thresholds( |
|
139
|
|
|
|
|
|
|
warning => $self->opts->warning, |
|
140
|
|
|
|
|
|
|
critical => $self->opts->critical, |
|
141
|
|
|
|
|
|
|
); |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
else { |
|
144
|
4
|
|
|
|
|
52
|
return UNKNOWN; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
15
|
|
|
|
|
163
|
return $self->threshold->get_status($args{check}); |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# top level interface to my Nagios::Monitoring::Plugin::Getopt object |
|
151
|
|
|
|
|
|
|
sub add_arg { |
|
152
|
3
|
|
|
3
|
1
|
813
|
my $self = shift; |
|
153
|
3
|
50
|
|
|
|
10
|
$self->opts->arg(@_) if $self->_check_for_opts; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
sub getopts { |
|
156
|
2
|
|
|
2
|
1
|
579
|
my $self = shift; |
|
157
|
2
|
50
|
|
|
|
7
|
$self->opts->getopts(@_) if $self->_check_for_opts; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub _check_for_opts { |
|
161
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
|
162
|
5
|
100
|
|
|
|
18
|
croak |
|
163
|
|
|
|
|
|
|
"You have to supply a 'usage' param to Nagios::Monitoring::Plugin::new() if you want to use Getopts from your Nagios::Monitoring::Plugin object." |
|
164
|
|
|
|
|
|
|
unless ref $self->opts() eq 'Nagios::Monitoring::Plugin::Getopt'; |
|
165
|
3
|
|
|
|
|
31
|
return $self; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
171
|
|
|
|
|
|
|
# NP::Functions::check_messages helpers and wrappers |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub add_message { |
|
174
|
18
|
|
|
18
|
1
|
1217
|
my $self = shift; |
|
175
|
18
|
|
|
|
|
33
|
my ($code, @messages) = @_; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
croak "Invalid error code '$code'" |
|
178
|
18
|
100
|
100
|
|
|
339
|
unless defined($ERRORS{uc $code}) || defined($STATUS_TEXT{$code}); |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Store messages using strings rather than numeric codes |
|
181
|
16
|
100
|
|
|
|
35
|
$code = $STATUS_TEXT{$code} if $STATUS_TEXT{$code}; |
|
182
|
16
|
|
|
|
|
24
|
$code = lc $code; |
|
183
|
16
|
100
|
100
|
|
|
231
|
croak "Error code '$code' not supported by add_message" |
|
184
|
|
|
|
|
|
|
if $code eq 'unknown' || $code eq 'dependent'; |
|
185
|
|
|
|
|
|
|
|
|
186
|
14
|
50
|
|
|
|
36
|
$self->messages($code, []) unless $self->messages->{$code}; |
|
187
|
14
|
|
|
|
|
68
|
push @{$self->messages->{$code}}, @messages; |
|
|
14
|
|
|
|
|
30
|
|
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub check_messages { |
|
191
|
30
|
|
|
30
|
1
|
14887
|
my $self = shift; |
|
192
|
30
|
|
|
|
|
81
|
my %args = @_; |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# Add object messages to any passed in as args |
|
195
|
30
|
|
|
|
|
50
|
for my $code (qw(critical warning ok)) { |
|
196
|
90
|
|
50
|
|
|
215
|
my $messages = $self->messages->{$code} || []; |
|
197
|
90
|
100
|
|
|
|
515
|
if ($args{$code}) { |
|
198
|
48
|
100
|
|
|
|
113
|
unless (ref $args{$code} eq 'ARRAY') { |
|
199
|
4
|
50
|
|
|
|
9
|
if ($code eq 'ok') { |
|
200
|
4
|
|
|
|
|
12
|
$args{$code} = [ $args{$code} ]; |
|
201
|
|
|
|
|
|
|
} else { |
|
202
|
0
|
|
|
|
|
0
|
croak "Invalid argument '$code'" |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
} |
|
205
|
48
|
|
|
|
|
50
|
push @{$args{$code}}, @$messages; |
|
|
48
|
|
|
|
|
108
|
|
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
else { |
|
208
|
42
|
|
|
|
|
85
|
$args{$code} = $messages; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
30
|
|
|
|
|
115
|
Nagios::Monitoring::Plugin::Functions::check_messages(%args); |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# ------------------------------------------------------------------------- |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
1; |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
#vim:et:sw=4 |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
__END__ |