mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 21:51:21 +00:00
Add ping_for_updates(), send the X-Percona-Toolkit-Tool header, and fix an error in pingback()
This commit is contained in:
@@ -28,6 +28,7 @@ use English qw(-no_match_vars);
|
|||||||
|
|
||||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||||
|
|
||||||
|
use File::Basename ();
|
||||||
use Data::Dumper ();
|
use Data::Dumper ();
|
||||||
|
|
||||||
sub Dumper {
|
sub Dumper {
|
||||||
@@ -44,6 +45,20 @@ eval {
|
|||||||
require VersionCheck;
|
require VersionCheck;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sub ping_for_updates {
|
||||||
|
my (%args) = @_;
|
||||||
|
my $advice = "";
|
||||||
|
my $response = pingback(%args);
|
||||||
|
|
||||||
|
PTDEBUG && _d('Server response:', Dumper($response));
|
||||||
|
if ( $response && $response->{success} ) {
|
||||||
|
$advice = $response->{content};
|
||||||
|
$advice =~ s/\r\n/\n/g; # Normalize linefeeds
|
||||||
|
}
|
||||||
|
|
||||||
|
return $advice;
|
||||||
|
}
|
||||||
|
|
||||||
sub pingback {
|
sub pingback {
|
||||||
my (%args) = @_;
|
my (%args) = @_;
|
||||||
my @required_args = qw(url);
|
my @required_args = qw(url);
|
||||||
@@ -90,13 +105,21 @@ sub pingback {
|
|||||||
);
|
);
|
||||||
return unless scalar keys %$versions;
|
return unless scalar keys %$versions;
|
||||||
|
|
||||||
# Join the items and whatever veersions are available and re-encode
|
# Join the items and whatever versions are available and re-encode
|
||||||
# them in same simple plaintext item-per-line protocol, and send
|
# them in same simple plaintext item-per-line protocol, and send
|
||||||
# it back to Percona.
|
# it back to Percona.
|
||||||
my $client_response = encode_client_response(
|
my $client_content = encode_client_response(
|
||||||
items => $items,
|
items => $items,
|
||||||
versions => $versions,
|
versions => $versions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
my $client_response = {
|
||||||
|
headers => { "X-Percona-Toolkit-Tool" => File::Basename::basename($0) },
|
||||||
|
content => $client_content,
|
||||||
|
};
|
||||||
|
|
||||||
|
PTDEBUG && _d('Sending back to the server:', Dumper($response));
|
||||||
|
|
||||||
return $ua->request('POST', $url, $client_response);
|
return $ua->request('POST', $url, $client_response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,7 +68,7 @@ sub test_pingback {
|
|||||||
);
|
);
|
||||||
|
|
||||||
is(
|
is(
|
||||||
$post,
|
$post->{content},
|
||||||
$args{post},
|
$args{post},
|
||||||
"$args{name} client response"
|
"$args{name} client response"
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user