line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nagios::Passive::ResultPath; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2639
|
use strict; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
99
|
|
4
|
3
|
|
|
3
|
|
19
|
use Carp; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
200
|
|
5
|
3
|
|
|
3
|
|
1391
|
use File::Temp; |
|
3
|
|
|
|
|
83126
|
|
|
3
|
|
|
|
|
415
|
|
6
|
3
|
|
|
3
|
|
33
|
use Fcntl qw/:DEFAULT :flock/; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
1387
|
|
7
|
3
|
|
|
3
|
|
649
|
use Moo; |
|
3
|
|
|
|
|
12498
|
|
|
3
|
|
|
|
|
31
|
|
8
|
3
|
|
|
3
|
|
4269
|
use MooX::late; |
|
3
|
|
|
|
|
27923
|
|
|
3
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
extends 'Nagios::Passive::Base'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'checkresults_dir' => ( is => 'ro', isa => 'Str | Undef', required => 1); |
13
|
|
|
|
|
|
|
has 'check_type' => ( is => 'rw', isa => 'Int', default => 1); |
14
|
|
|
|
|
|
|
has 'check_options' => ( is => 'rw', isa => 'Int', default => 0); |
15
|
|
|
|
|
|
|
has 'scheduled_check' => ( is => 'rw', isa => 'Int', default => 0); |
16
|
|
|
|
|
|
|
has 'latency' => ( is => 'rw', isa => 'Num', default => 0); |
17
|
|
|
|
|
|
|
has 'start_time' => ( is => 'rw', isa => 'Num', default=>sub { time . ".0" }); |
18
|
|
|
|
|
|
|
has 'finish_time' => ( is => 'rw', isa => 'Num', default=>sub { time . ".0" }); |
19
|
|
|
|
|
|
|
has 'early_timeout' => ( is => 'rw', isa => 'Int', default=>0); |
20
|
|
|
|
|
|
|
has 'exited_ok' => ( is => 'rw', isa => 'Int', default=>1); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
with 'Nagios::Passive::Role::Tempfile'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub BUILD { |
25
|
4
|
|
|
4
|
0
|
14401
|
my $self = shift; |
26
|
4
|
|
|
|
|
23
|
my $cd = $self->checkresults_dir; |
27
|
4
|
100
|
100
|
|
|
291
|
if(defined $cd and ! -d $cd) { |
28
|
1
|
|
|
|
|
259
|
croak("$cd is not a directory") |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _to_string { |
33
|
3
|
|
|
3
|
|
8
|
my $self = shift; |
34
|
3
|
|
|
|
|
12
|
my $string = ""; |
35
|
3
|
|
|
|
|
11
|
$string.="### Nagios Service Check Result ###\n"; |
36
|
3
|
|
|
|
|
79
|
$string.=sprintf "# Time: %s\n",scalar localtime $self->time; |
37
|
3
|
|
|
|
|
138
|
$string.=sprintf "host_name=%s\n", $self->host_name; |
38
|
3
|
100
|
|
|
|
95
|
if(defined($self->service_description)) { |
39
|
1
|
|
|
|
|
30
|
$string.=sprintf "service_description=%s\n", $self->service_description; |
40
|
|
|
|
|
|
|
} |
41
|
3
|
|
|
|
|
90
|
$string.=sprintf "check_type=%d\n", $self->check_type; |
42
|
3
|
|
|
|
|
91
|
$string.=sprintf "check_options=%d\n", $self->check_options; |
43
|
3
|
|
|
|
|
85
|
$string.=sprintf "scheduled_check=%d\n", $self->scheduled_check; |
44
|
3
|
|
|
|
|
89
|
$string.=sprintf "latency=%f\n", $self->latency; |
45
|
3
|
|
|
|
|
105
|
$string.=sprintf "start_time=%f\n", $self->start_time; |
46
|
3
|
|
|
|
|
98
|
$string.=sprintf "finish_time=%f\n", $self->finish_time; |
47
|
3
|
|
|
|
|
94
|
$string.=sprintf "early_timeout=%d\n", $self->early_timeout; |
48
|
3
|
|
|
|
|
87
|
$string.=sprintf "exited_ok=%d\n", $self->exited_ok; |
49
|
3
|
|
|
|
|
101
|
$string.=sprintf "return_code=%d\n", $self->return_code; |
50
|
3
|
|
|
|
|
94
|
$string.=sprintf "output=%s %s - %s\n", $self->check_name, |
51
|
|
|
|
|
|
|
$self->_status_code, $self->_quoted_output; |
52
|
3
|
|
|
|
|
80
|
return $string; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub to_string { |
56
|
1
|
|
|
1
|
0
|
1090
|
my $self = shift; |
57
|
1
|
|
|
|
|
3
|
my $string = ""; |
58
|
1
|
|
|
|
|
7
|
$string.="### Active Check Result File ###\n"; |
59
|
1
|
|
|
|
|
28
|
$string.=sprintf "file_time=%d\n\n",$self->time; |
60
|
1
|
|
|
|
|
15
|
$string.=$self->_to_string; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub submit { |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
0
|
|
|
|
|
if(! defined $self->checkresults_dir) { |
66
|
0
|
|
|
|
|
|
croak( |
67
|
|
|
|
|
|
|
"checkresults_dir is not set, you can either set it ". |
68
|
|
|
|
|
|
|
"or use that object with Nagios::Passive::BulkResult" |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
my $fh = $self->tempfile; |
72
|
0
|
|
|
|
|
|
my $output = $self->to_string; |
73
|
0
|
0
|
|
|
|
|
print $fh $output or croak($!); |
74
|
0
|
0
|
|
|
|
|
close($fh) or croak($!); |
75
|
0
|
|
|
|
|
|
$self->_touch_file; |
76
|
0
|
|
|
|
|
|
return $fh->filename; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |