line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#vim: softtabstop-2 sw=2 : |
2
|
|
|
|
|
|
|
package Nagios::Passive::Base; |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
3442
|
use strict; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
149
|
|
5
|
5
|
|
|
5
|
|
29
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
331
|
|
6
|
5
|
|
|
5
|
|
36
|
use Fcntl qw/:DEFAULT :flock/; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
1927
|
|
7
|
5
|
|
|
5
|
|
2203
|
use Monitoring::Plugin::Threshold; |
|
5
|
|
|
|
|
190791
|
|
|
5
|
|
|
|
|
47
|
|
8
|
5
|
|
|
5
|
|
3432
|
use Monitoring::Plugin::Performance; |
|
5
|
|
|
|
|
9626
|
|
|
5
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
Monitoring::Plugin::Functions::_use_die(1); |
10
|
5
|
|
|
5
|
|
310
|
use overload '""' => 'to_string'; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
50
|
|
11
|
5
|
|
|
5
|
|
880
|
use Moo; |
|
5
|
|
|
|
|
8174
|
|
|
5
|
|
|
|
|
61
|
|
12
|
5
|
|
|
5
|
|
4264
|
use MooX::late; |
|
5
|
|
|
|
|
17947
|
|
|
5
|
|
|
|
|
85
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %RETURN_CODES = ( |
15
|
|
|
|
|
|
|
0 => 'OK', |
16
|
|
|
|
|
|
|
1 => 'WARNING', |
17
|
|
|
|
|
|
|
2 => 'CRITICAL', |
18
|
|
|
|
|
|
|
3 => 'UNKNOWN', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'check_name' => ( is => 'rw', isa => 'Str', required => 1); |
22
|
|
|
|
|
|
|
has 'host_name' => ( is => 'rw', isa => 'Str', required => 1); |
23
|
|
|
|
|
|
|
has 'service_description' => ( is => 'rw', isa => 'Str'); |
24
|
|
|
|
|
|
|
has 'time' => ( is => 'rw', isa => 'Int', default => sub { time }); |
25
|
|
|
|
|
|
|
has 'return_code' => ( is => 'rw', isa => 'Int', default => 0); |
26
|
|
|
|
|
|
|
has 'output' => ( |
27
|
|
|
|
|
|
|
is => 'rw', |
28
|
|
|
|
|
|
|
isa => 'Str', |
29
|
|
|
|
|
|
|
# traits => ['String'], |
30
|
|
|
|
|
|
|
default => '', |
31
|
|
|
|
|
|
|
# handles => { |
32
|
|
|
|
|
|
|
# add_output => 'append', |
33
|
|
|
|
|
|
|
# }, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add_output { |
37
|
2
|
|
|
2
|
0
|
1352
|
$_[0]->output( $_[0]->output . $_[1] ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'threshold' => ( |
41
|
|
|
|
|
|
|
is => 'ro', |
42
|
|
|
|
|
|
|
isa => 'Monitoring::Plugin::Threshold', |
43
|
|
|
|
|
|
|
handles => [qw/set_thresholds/], |
44
|
|
|
|
|
|
|
lazy => 1, |
45
|
|
|
|
|
|
|
predicate => 'has_threshold', |
46
|
|
|
|
|
|
|
default => sub { Monitoring::Plugin::Threshold->new }, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
has 'performance' => ( |
49
|
|
|
|
|
|
|
traits => ['Array'], |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
isa => 'ArrayRef[Monitoring::Plugin::Performance]', |
52
|
|
|
|
|
|
|
default => sub { [] }, |
53
|
|
|
|
|
|
|
lazy => 1, |
54
|
|
|
|
|
|
|
predicate => 'has_performance', |
55
|
|
|
|
|
|
|
handles => { |
56
|
|
|
|
|
|
|
_performance_add => 'push', |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub to_string { |
61
|
0
|
|
|
0
|
0
|
0
|
croak("override this"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub submit { |
65
|
0
|
|
|
0
|
0
|
0
|
croak("override this"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_perf { |
69
|
4
|
|
|
4
|
0
|
2374
|
my $self = shift; |
70
|
4
|
|
|
|
|
36
|
my $perf = Monitoring::Plugin::Performance->new(@_); |
71
|
4
|
|
|
|
|
226
|
$self->_performance_add($perf); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub set_status { |
75
|
8
|
|
|
8
|
0
|
11968
|
my $self = shift; |
76
|
8
|
|
|
|
|
21
|
my $value = shift; |
77
|
8
|
100
|
|
|
|
44
|
unless($self->has_threshold) { |
78
|
2
|
|
|
|
|
541
|
croak("you have to call set_thresholds before calling set_status"); |
79
|
|
|
|
|
|
|
} |
80
|
6
|
|
|
|
|
166
|
$self->return_code($self->threshold->get_status($value)) |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _status_code { |
84
|
9
|
|
|
9
|
|
570
|
my $self = shift; |
85
|
9
|
|
|
|
|
162
|
my $r = $RETURN_CODES{$self->return_code}; |
86
|
9
|
50
|
|
|
|
109
|
return defined($r) ? $r : 'UNKNOWN'; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _quoted_output { |
90
|
13
|
|
|
13
|
|
1277
|
my $self = shift; |
91
|
13
|
|
|
|
|
285
|
my $output = $self->output; |
92
|
|
|
|
|
|
|
# remove trailing newlines and quote the remaining ones |
93
|
13
|
|
|
|
|
157
|
$output =~ s/[\r\n]*$//o; |
94
|
13
|
|
|
|
|
47
|
$output =~ s/\n/\\n/go; |
95
|
13
|
100
|
|
|
|
98
|
if($self->has_performance) { |
96
|
6
|
|
|
|
|
26
|
return $output . " | ".$self->_perf_string; |
97
|
|
|
|
|
|
|
} |
98
|
7
|
|
|
|
|
77
|
return $output; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _perf_string { |
102
|
8
|
|
|
8
|
|
2137
|
my $self = shift; |
103
|
8
|
50
|
|
|
|
39
|
return "" unless($self->has_performance); |
104
|
8
|
|
|
|
|
21
|
return join (" ", map { $_->perfoutput } @{ $self->performance }); |
|
16
|
|
|
|
|
1009
|
|
|
8
|
|
|
|
|
216
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
__END__ |