line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Livestatus::UNIX; |
2
|
4
|
|
|
4
|
|
94456
|
use parent 'Monitoring::Livestatus'; |
|
4
|
|
|
|
|
321
|
|
|
4
|
|
|
|
|
29
|
|
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
247
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
121
|
|
5
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
114
|
|
6
|
4
|
|
|
4
|
|
20
|
use IO::Socket::UNIX (); |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
127
|
|
7
|
4
|
|
|
4
|
|
25
|
use Carp qw/confess/; |
|
4
|
|
|
|
|
32
|
|
|
4
|
|
|
|
|
1867
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Monitoring::Livestatus::UNIX - connector with unix sockets |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Monitoring::Livestatus; |
16
|
|
|
|
|
|
|
my $nl = Monitoring::Livestatus::UNIX->new( '/var/lib/livestatus/livestatus.sock' ); |
17
|
|
|
|
|
|
|
my $hosts = $nl->selectall_arrayref("GET hosts"); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head2 new ( [ARGS] ) |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Creates an C object. C takes at least the socketpath. |
24
|
|
|
|
|
|
|
Arguments are the same as in C. |
25
|
|
|
|
|
|
|
If the constructor is only passed a single argument, it is assumed to |
26
|
|
|
|
|
|
|
be a the C specification. Use either socker OR server. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
10
|
|
|
10
|
1
|
713
|
my($class,@args) = @_; |
32
|
10
|
100
|
|
|
|
28
|
unshift(@args, "peer") if scalar @args == 1; |
33
|
10
|
|
|
|
|
31
|
my(%options) = @args; |
34
|
10
|
100
|
|
|
|
29
|
$options{'name'} = $options{'peer'} unless defined $options{'name'}; |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
21
|
$options{'backend'} = $class; |
37
|
10
|
|
|
|
|
40
|
my $self = Monitoring::Livestatus->new(%options); |
38
|
10
|
|
|
|
|
25
|
bless $self, $class; |
39
|
10
|
50
|
|
|
|
36
|
confess('not a scalar') if ref $self->{'peer'} ne ''; |
40
|
|
|
|
|
|
|
|
41
|
10
|
|
|
|
|
41
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
######################################## |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 METHODS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _open { |
52
|
0
|
|
|
0
|
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if(!-S $self->{'peer'}) { |
55
|
0
|
|
|
|
|
|
my $msg = "failed to open socket $self->{'peer'}: $!"; |
56
|
0
|
0
|
|
|
|
|
if($self->{'errors_are_fatal'}) { |
57
|
0
|
|
|
|
|
|
confess($msg); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorCode = 500; |
60
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorMessage = $msg; |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my $sock; |
64
|
0
|
|
|
|
|
|
eval { |
65
|
|
|
|
|
|
|
$sock = IO::Socket::UNIX->new( |
66
|
|
|
|
|
|
|
Peer => $self->{'peer'}, |
67
|
|
|
|
|
|
|
Type => IO::Socket::UNIX::SOCK_STREAM, |
68
|
0
|
|
|
|
|
|
Timeout => $self->{'connect_timeout'}, |
69
|
|
|
|
|
|
|
); |
70
|
0
|
0
|
0
|
|
|
|
if(!defined $sock || !$sock->connected()) { |
71
|
0
|
|
|
|
|
|
my $msg = "failed to connect to $self->{'peer'}: $!"; |
72
|
0
|
0
|
|
|
|
|
if($self->{'errors_are_fatal'}) { |
73
|
0
|
|
|
|
|
|
confess($msg); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorCode = 500; |
76
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorMessage = $msg; |
77
|
0
|
|
|
|
|
|
return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
if($@) { |
82
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorCode = 500; |
83
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorMessage = $@; |
84
|
0
|
|
|
|
|
|
return; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if(defined $self->{'query_timeout'}) { |
88
|
|
|
|
|
|
|
# set timeout |
89
|
0
|
|
|
|
|
|
$sock->timeout($self->{'query_timeout'}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return($sock); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
######################################## |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _close { |
99
|
0
|
|
|
0
|
|
|
my $self = shift; |
100
|
0
|
|
|
|
|
|
my $sock = shift; |
101
|
0
|
0
|
|
|
|
|
return unless defined $sock; |
102
|
0
|
|
|
|
|
|
return close($sock); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Sven Nierlein, 2009-present, |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Copyright (C) by Sven Nierlein |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
117
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |