line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#vim: softtabstop-2 sw=2 : |
2
|
|
|
|
|
|
|
package Nagios::Passive::Base; |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
3652
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
146
|
|
5
|
4
|
|
|
4
|
|
21
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
394
|
|
6
|
4
|
|
|
4
|
|
24
|
use Fcntl qw/:DEFAULT :flock/; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
2221
|
|
7
|
4
|
|
|
4
|
|
1256
|
use Nagios::Plugin::Threshold; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Nagios::Plugin::Performance; |
9
|
|
|
|
|
|
|
Nagios::Plugin::Functions::_use_die(1); |
10
|
|
|
|
|
|
|
use overload '""' => 'to_string'; |
11
|
|
|
|
|
|
|
use Moo; |
12
|
|
|
|
|
|
|
use MooX::late; |
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
|
|
|
|
|
|
|
$_[0]->output( $_[0]->output . $_[1] ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'threshold' => ( |
41
|
|
|
|
|
|
|
is => 'ro', |
42
|
|
|
|
|
|
|
isa => 'Nagios::Plugin::Threshold', |
43
|
|
|
|
|
|
|
handles => [qw/set_thresholds/], |
44
|
|
|
|
|
|
|
lazy => 1, |
45
|
|
|
|
|
|
|
predicate => 'has_threshold', |
46
|
|
|
|
|
|
|
default => sub { Nagios::Plugin::Threshold->new }, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
has 'performance' => ( |
49
|
|
|
|
|
|
|
traits => ['Array'], |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
isa => 'ArrayRef[Nagios::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
|
|
|
|
|
|
|
croak("override this"); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub submit { |
65
|
|
|
|
|
|
|
croak("override this"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub add_perf { |
69
|
|
|
|
|
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
my $perf = Nagios::Plugin::Performance->new(@_); |
71
|
|
|
|
|
|
|
$self->_performance_add($perf); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub set_status { |
75
|
|
|
|
|
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
my $value = shift; |
77
|
|
|
|
|
|
|
unless($self->has_threshold) { |
78
|
|
|
|
|
|
|
croak("you have to call set_thresholds before calling set_status"); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
$self->return_code($self->threshold->get_status($value)) |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _status_code { |
84
|
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
my $r = $RETURN_CODES{$self->return_code}; |
86
|
|
|
|
|
|
|
return defined($r) ? $r : 'UNKNOWN'; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _quoted_output { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
my $output = $self->output; |
92
|
|
|
|
|
|
|
# remove trailing newlines and quote the remaining ones |
93
|
|
|
|
|
|
|
$output =~ s/[\r\n]*$//o; |
94
|
|
|
|
|
|
|
$output =~ s/\n/\\n/go; |
95
|
|
|
|
|
|
|
if($self->has_performance) { |
96
|
|
|
|
|
|
|
return $output . " | ".$self->_perf_string; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
return $output; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _perf_string { |
102
|
|
|
|
|
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
return "" unless($self->has_performance); |
104
|
|
|
|
|
|
|
return join (" ", map { $_->perfoutput } @{ $self->performance }); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
__END__ |