Add ping_for_updates(), send the X-Percona-Toolkit-Tool header, and fix an error in pingback()

This commit is contained in:
Brian Fraser
2012-08-09 17:38:39 -03:00
parent 4a04837378
commit c7060a99a7
2 changed files with 26 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
use File::Basename ();
use Data::Dumper ();
sub Dumper {
@@ -44,6 +45,20 @@ eval {
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 {
my (%args) = @_;
my @required_args = qw(url);
@@ -90,13 +105,21 @@ sub pingback {
);
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
# it back to Percona.
my $client_response = encode_client_response(
my $client_content = encode_client_response(
items => $items,
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);
}

View File

@@ -68,7 +68,7 @@ sub test_pingback {
);
is(
$post,
$post->{content},
$args{post},
"$args{name} client response"
)