line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Monitoring::Livestatus::UNIX; |
2
|
4
|
|
|
4
|
|
71789
|
use parent 'Monitoring::Livestatus'; |
|
4
|
|
|
|
|
268
|
|
|
4
|
|
|
|
|
26
|
|
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
204
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
79
|
|
5
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
124
|
|
6
|
4
|
|
|
4
|
|
21
|
use IO::Socket::UNIX (); |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
61
|
|
7
|
4
|
|
|
4
|
|
16
|
use Carp qw/confess croak/; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
1552
|
|
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
|
576
|
my($class,@args) = @_; |
32
|
10
|
100
|
|
|
|
27
|
unshift(@args, "peer") if scalar @args == 1; |
33
|
10
|
|
|
|
|
24
|
my(%options) = @args; |
34
|
10
|
100
|
|
|
|
38
|
$options{'name'} = $options{'peer'} unless defined $options{'name'}; |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
13
|
$options{'backend'} = $class; |
37
|
10
|
|
|
|
|
39
|
my $self = Monitoring::Livestatus->new(%options); |
38
|
10
|
|
|
|
|
22
|
bless $self, $class; |
39
|
10
|
50
|
|
|
|
30
|
confess('not a scalar') if ref $self->{'peer'} ne ''; |
40
|
|
|
|
|
|
|
|
41
|
10
|
|
|
|
|
32
|
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
|
|
|
|
|
|
croak($msg); |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorCode = 500; |
60
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorMessage = $msg; |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my $sock; |
64
|
0
|
|
|
|
|
|
my $remaining = alarm($self->{'connect_timeout'}); |
65
|
0
|
|
|
|
|
|
eval { |
66
|
0
|
|
|
0
|
|
|
local $SIG{'ALRM'} = sub { die("connection timeout"); }; |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$sock = IO::Socket::UNIX->new( |
68
|
0
|
|
|
|
|
|
Peer => $self->{'peer'}, |
69
|
|
|
|
|
|
|
Type => IO::Socket::UNIX::SOCK_STREAM, |
70
|
|
|
|
|
|
|
); |
71
|
0
|
0
|
0
|
|
|
|
if(!defined $sock || !$sock->connected()) { |
72
|
0
|
|
|
|
|
|
my $msg = "failed to connect to $self->{'peer'}: $!"; |
73
|
0
|
0
|
|
|
|
|
if($self->{'errors_are_fatal'}) { |
74
|
0
|
|
|
|
|
|
croak($msg); |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorCode = 500; |
77
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorMessage = $msg; |
78
|
0
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
}; |
81
|
0
|
|
|
|
|
|
alarm(0); |
82
|
0
|
0
|
|
|
|
|
alarm($remaining) if $remaining; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if($@) { |
85
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorCode = 500; |
86
|
0
|
|
|
|
|
|
$Monitoring::Livestatus::ErrorMessage = $@; |
87
|
0
|
|
|
|
|
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if(defined $self->{'query_timeout'}) { |
91
|
|
|
|
|
|
|
# set timeout |
92
|
0
|
|
|
|
|
|
$sock->timeout($self->{'query_timeout'}); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return($sock); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
######################################## |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _close { |
102
|
0
|
|
|
0
|
|
|
my $self = shift; |
103
|
0
|
|
|
|
|
|
my $sock = shift; |
104
|
0
|
0
|
|
|
|
|
return unless defined $sock; |
105
|
0
|
|
|
|
|
|
return close($sock); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 AUTHOR |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Sven Nierlein, 2009-present, |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright (C) by Sven Nierlein |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
120
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |