line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nagios::Status::ServiceStatus; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25602
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
5
|
1
|
|
|
1
|
|
1219
|
use Nagios::Status::Service; |
|
1
|
|
|
|
|
1190
|
|
|
1
|
|
|
|
|
785
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Nagios::Status::ServiceStatus - Nagios 3.0 Class to maintain Services' Status. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.01 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Import the Module |
23
|
|
|
|
|
|
|
use Nagios::Status::ServiceStatus |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Instantiate the ServiceStatus Object |
26
|
|
|
|
|
|
|
my $status = Nagios::Status::ServiceStatus->new($nagios_status_log_path); |
27
|
|
|
|
|
|
|
# OR |
28
|
|
|
|
|
|
|
my $status = Nagios::Status::ServiceStatus->new($nagios_status_log_path, $serv1, $serv2, ...); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Get services that are up. |
31
|
|
|
|
|
|
|
my $ok = $status->check_ok; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Get services that are down. |
34
|
|
|
|
|
|
|
my $warning = $status->check_warning; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Get services that are unreachable. |
37
|
|
|
|
|
|
|
my $unknown = $status->check_unknown; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Get services that are critical. |
40
|
|
|
|
|
|
|
my $critical = $status->check_critical; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This module is an object oriented approach to Nagios 3.0 status services. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 OBJECT CREATION METHOD |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over 4 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item new |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $status = Nagios::Status::ServiceStatus->new($nagios_status_log_path [, $serv1 .. $servN]); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This class constructs a C object. It requires one parameter. A file |
55
|
|
|
|
|
|
|
path containing the path to the Nagios status.log file. There is an optional parameter. An array |
56
|
|
|
|
|
|
|
of host names can be specified, whereby only those domains will be populated. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=back |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
63
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $self = { |
66
|
|
|
|
|
|
|
status_log => shift, |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->{ok} = (); |
70
|
0
|
|
|
|
|
|
$self->{warning} = (); |
71
|
0
|
|
|
|
|
|
$self->{unknown} = (); |
72
|
0
|
|
|
|
|
|
$self->{critical} = (); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
bless $self, $class; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my (@services) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if (@services) { |
79
|
0
|
|
|
|
|
|
$self->_populate_services(\@services); |
80
|
|
|
|
|
|
|
} else { |
81
|
0
|
|
|
|
|
|
$self->_populate_all; |
82
|
|
|
|
|
|
|
} # if/else |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self; |
85
|
|
|
|
|
|
|
} # new |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _populate_services { |
88
|
0
|
|
|
0
|
|
|
my ($self, $services) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
foreach (@$services) { |
91
|
0
|
|
|
|
|
|
my $service = Nagios::Status::Service->new($self->{status_log}, $_); |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if (defined $service) { |
94
|
0
|
0
|
|
|
|
|
if ($service->is_warning) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
push @{ $self->{warning} }, $service; |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} elsif ($service->is_unknown) { |
97
|
0
|
|
|
|
|
|
push @{ $self->{unknown} }, $service; |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} elsif ($service->is_critical) { |
99
|
0
|
|
|
|
|
|
push @{ $self->{critical} }, $service; |
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
|
push @{ $self->{ok} }, $service; |
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} # if/elsif/else |
103
|
|
|
|
|
|
|
} else { |
104
|
0
|
|
|
|
|
|
$Nagios::Status::ServiceStatus::errstr = "Service not found: $_"; |
105
|
|
|
|
|
|
|
} # if/else |
106
|
|
|
|
|
|
|
} # foreach |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return; |
109
|
|
|
|
|
|
|
} # _populate_services |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _populate_all { |
112
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
open(STATUS, $self->{status_log}) or croak "Could not open Nagios status log: $!"; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $found = 0; |
117
|
0
|
|
|
|
|
|
my $service = Nagios::Status::Service->new($self->{status_log}); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
while(my $line = ) { |
120
|
0
|
0
|
|
|
|
|
if ($line =~ /^servicestatus\s*{/) { |
121
|
0
|
|
|
|
|
|
$found = 1; |
122
|
0
|
|
|
|
|
|
next; |
123
|
|
|
|
|
|
|
} # if |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
0
|
|
|
|
if ($found and $line =~ /}/) { |
126
|
0
|
0
|
|
|
|
|
if ($service->is_warning) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
push @{ $self->{warning} }, $service; |
|
0
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} elsif ($service->is_unknown) { |
129
|
0
|
|
|
|
|
|
push @{ $self->{unknown} }, $service; |
|
0
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} elsif ($service->is_critical) { |
131
|
0
|
|
|
|
|
|
push @{ $self->{critical} }, $service; |
|
0
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} else { |
133
|
0
|
|
|
|
|
|
push @{ $self->{ok} }, $service; |
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} # if/elsif/else |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
$service = Nagios::Status::Service->new($self->{status_log}); |
137
|
0
|
|
|
|
|
|
$found = 0; |
138
|
|
|
|
|
|
|
} # if |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if (!$found) { |
141
|
0
|
|
|
|
|
|
next; |
142
|
|
|
|
|
|
|
} else { |
143
|
0
|
|
|
|
|
|
$service->set_attribute($line); |
144
|
|
|
|
|
|
|
} # if/else |
145
|
|
|
|
|
|
|
} # while |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
close(STATUS); |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return; |
150
|
|
|
|
|
|
|
} # _populate_all |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=pod |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 METHODS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over 4 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item check_ok |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $servs_ok = $status->check_ok; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
This method takes no parameters. It returns an array reference |
163
|
|
|
|
|
|
|
to all services found to be OK. Otherwise, it returns undefined. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub check_ok { |
168
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
169
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
if ($self->{ok}) { |
171
|
0
|
|
|
|
|
|
return $self->{ok}; |
172
|
|
|
|
|
|
|
} else { |
173
|
0
|
|
|
|
|
|
return undef; |
174
|
|
|
|
|
|
|
} # if/else |
175
|
|
|
|
|
|
|
} # check_ok |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=pod |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item check_warning |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
my $servs_warning = $status->check_warning; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This method takes no parameters. It returns an array reference |
184
|
|
|
|
|
|
|
to all services found to be WARNING. Otherwise, it returns undefined. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub check_warning { |
189
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
190
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
|
if ($self->{warning}) { |
192
|
0
|
|
|
|
|
|
return $self->{warning}; |
193
|
|
|
|
|
|
|
} else { |
194
|
0
|
|
|
|
|
|
return undef; |
195
|
|
|
|
|
|
|
} # if/else |
196
|
|
|
|
|
|
|
} # check_warning |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=pod |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item check_unknown |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
my $servs_unknown = $status->check_unknown; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This method takes no parameters. It returns an array reference |
205
|
|
|
|
|
|
|
to all services found to be UNKNOWN. Otherwise, it returns undefined. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub check_unknown { |
210
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
211
|
|
|
|
|
|
|
|
212
|
0
|
0
|
|
|
|
|
if ($self->{unknown}) { |
213
|
0
|
|
|
|
|
|
return $self->{unknown}; |
214
|
|
|
|
|
|
|
} else { |
215
|
0
|
|
|
|
|
|
return undef; |
216
|
|
|
|
|
|
|
} # if/else |
217
|
|
|
|
|
|
|
} # check_unknown |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=pod |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item check_critical |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
my $servs_critical = $status->check_critical; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
This method takes no parameters. It returns an array reference |
226
|
|
|
|
|
|
|
to all services found to be CRITICAL. Otherwise, it returns undefined. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=back |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub check_critical { |
233
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
234
|
|
|
|
|
|
|
|
235
|
0
|
0
|
|
|
|
|
if ($self->{critical}) { |
236
|
0
|
|
|
|
|
|
return $self->{critical}; |
237
|
|
|
|
|
|
|
} else { |
238
|
0
|
|
|
|
|
|
return undef; |
239
|
|
|
|
|
|
|
} # if/else |
240
|
|
|
|
|
|
|
} # check_critical |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 AUTHOR |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Roy Crowder, C<< >> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 SEE ALSO |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
L, |
249
|
|
|
|
|
|
|
L, |
250
|
|
|
|
|
|
|
L |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 BUGS |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
255
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
256
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 SUPPORT |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
perldoc Nagios::Status::ServiceStatus |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
You can also look for information at: |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=over 4 |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
L |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
L |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=item * CPAN Ratings |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
L |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * Search CPAN |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
L |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=back |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
Copyright 2009 WorldSpice Technologies, all rights reserved. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
292
|
|
|
|
|
|
|
under the same terms as Perl itself. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=cut |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
1; # End of Nagios::Status::ServiceStatus |