/usr/share/perl5/Monitoring/Livestatus/INET.pm is in libmonitoring-livestatus-perl 0.74-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | package Monitoring::Livestatus::INET;
use 5.000000;
use strict;
use warnings;
use IO::Socket::INET;
use Socket qw(IPPROTO_TCP TCP_NODELAY);
use Carp;
use base "Monitoring::Livestatus";
=head1 NAME
Monitoring::Livestatus::INET - connector with tcp sockets
=head1 SYNOPSIS
use Monitoring::Livestatus;
my $nl = Monitoring::Livestatus::INET->new( 'localhost:9999' );
my $hosts = $nl->selectall_arrayref("GET hosts");
=head1 CONSTRUCTOR
=head2 new ( [ARGS] )
Creates an C<Monitoring::Livestatus::INET> object. C<new> takes at least the server.
Arguments are the same as in C<Monitoring::Livestatus>.
If the constructor is only passed a single argument, it is assumed to
be a the C<server> specification. Use either socker OR server.
=cut
sub new {
my $class = shift;
unshift(@_, "peer") if scalar @_ == 1;
my(%options) = @_;
$options{'name'} = $options{'peer'} unless defined $options{'name'};
$options{'backend'} = $class;
my $self = Monitoring::Livestatus->new(%options);
bless $self, $class;
confess('not a scalar') if ref $self->{'peer'} ne '';
return $self;
}
########################################
=head1 METHODS
=cut
sub _open {
my $self = shift;
my $sock;
eval {
local $SIG{'ALRM'} = sub { die("connection timeout"); };
alarm($self->{'connect_timeout'});
$sock = IO::Socket::INET->new(
PeerAddr => $self->{'peer'},
Type => SOCK_STREAM,
Timeout => $self->{'connect_timeout'},
);
if(!defined $sock or !$sock->connected()) {
my $msg = "failed to connect to $self->{'peer'} :$!";
if($self->{'errors_are_fatal'}) {
croak($msg);
}
$Monitoring::Livestatus::ErrorCode = 500;
$Monitoring::Livestatus::ErrorMessage = $msg;
alarm(0);
return;
}
if(defined $self->{'query_timeout'}) {
# set timeout
$sock->timeout($self->{'query_timeout'});
}
setsockopt($sock, IPPROTO_TCP, TCP_NODELAY, 1);
};
alarm(0);
if($@) {
$Monitoring::Livestatus::ErrorCode = 500;
$Monitoring::Livestatus::ErrorMessage = $@;
return;
}
return($sock);
}
########################################
sub _close {
my $self = shift;
my $sock = shift;
return unless defined $sock;
return close($sock);
}
1;
=head1 AUTHOR
Sven Nierlein, E<lt>nierlein@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2009 by Sven Nierlein
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
__END__
|