diff --git a/lib/Pingback.pm b/lib/Pingback.pm index 84eec7a6..25eda721 100644 --- a/lib/Pingback.pm +++ b/lib/Pingback.pm @@ -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); } diff --git a/t/lib/Pingback.t b/t/lib/Pingback.t index 9c13bdc3..ab956da6 100644 --- a/t/lib/Pingback.t +++ b/t/lib/Pingback.t @@ -68,7 +68,7 @@ sub test_pingback { ); is( - $post, + $post->{content}, $args{post}, "$args{name} client response" )