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
|
package FusionInventory::Agent::Target::Server;
use strict;
use warnings;
use base 'FusionInventory::Agent::Target';
use English qw(-no_match_vars);
use URI;
my $count = 0;
sub new {
my ($class, %params) = @_;
die "no url parameter" unless $params{url};
my $self = $class->SUPER::new(%params);
$self->{url} = _getCanonicalURL($params{url});
# compute storage subdirectory from url
my $subdir = $self->{url};
$subdir =~ s/\//_/g;
$subdir =~ s/:/../g if $OSNAME eq 'MSWin32';
$self->_init(
id => 'server' . $count++,
vardir => $params{basevardir} . '/' . $subdir
);
return $self;
}
sub _getCanonicalURL {
my ($string) = @_;
my $url = URI->new($string);
my $scheme = $url->scheme();
if (!$scheme) {
# this is likely a bare hostname
# as parsing relies on scheme, host and path have to be set explicitely
$url->scheme('http');
$url->host($string);
$url->path('ocsinventory');
} else {
die "invalid protocol for URL: $string"
if $scheme ne 'http' && $scheme ne 'https';
# complete path if needed
$url->path('ocsinventory') if !$url->path();
}
return $url;
}
sub getUrl {
my ($self) = @_;
return $self->{url};
}
sub _getName {
my ($self) = @_;
return $self->{url};
}
sub _getType {
my ($self) = @_;
return 'server';
}
1;
__END__
=head1 NAME
FusionInventory::Agent::Target::Server - Server target
=head1 DESCRIPTION
This is a target for sending execution result to a server.
=head1 METHODS
=head2 new(%params)
The constructor. The following parameters are allowed, in addition to those
from the base class C<FusionInventory::Agent::Target>, as keys of the %params
hash:
=over
=item I<url>
the server URL (mandatory)
=back
=head2 getUrl()
Return the server URL for this target.
|