diff --git a/bin/pt-archiver b/bin/pt-archiver index d08e95ed..b297def3 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -5373,15 +5373,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -5598,6 +5599,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -5634,7 +5675,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-config-diff b/bin/pt-config-diff index 7a340806..35b0134f 100755 --- a/bin/pt-config-diff +++ b/bin/pt-config-diff @@ -4711,15 +4711,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -4936,6 +4937,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -4972,7 +5013,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-deadlock-logger b/bin/pt-deadlock-logger index d2b09b78..4ed24bb3 100755 --- a/bin/pt-deadlock-logger +++ b/bin/pt-deadlock-logger @@ -3775,15 +3775,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -4000,6 +4001,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -4036,7 +4077,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-diskstats b/bin/pt-diskstats index 9773fd84..a1bb8252 100755 --- a/bin/pt-diskstats +++ b/bin/pt-diskstats @@ -4328,15 +4328,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -4553,6 +4554,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -4589,7 +4630,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-duplicate-key-checker b/bin/pt-duplicate-key-checker index d6586855..9cca3223 100755 --- a/bin/pt-duplicate-key-checker +++ b/bin/pt-duplicate-key-checker @@ -4379,15 +4379,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -4604,6 +4605,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -4640,7 +4681,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-find b/bin/pt-find index c1e4a940..e63870c9 100755 --- a/bin/pt-find +++ b/bin/pt-find @@ -3093,15 +3093,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -3318,6 +3319,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -3354,7 +3395,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-fk-error-logger b/bin/pt-fk-error-logger index 8ce7b713..e99aae70 100755 --- a/bin/pt-fk-error-logger +++ b/bin/pt-fk-error-logger @@ -3280,15 +3280,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -3505,6 +3506,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -3541,7 +3582,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index b3be48c7..f0566be2 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -4980,15 +4980,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -5205,6 +5206,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -5241,7 +5282,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-index-usage b/bin/pt-index-usage index 75239c1f..d34f34a4 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -5777,15 +5777,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -6002,6 +6003,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -6038,7 +6079,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-kill b/bin/pt-kill index 01154183..5e1fd437 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -6185,15 +6185,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -6410,6 +6411,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -6446,7 +6487,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 91184b0d..bbba173f 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -7413,15 +7413,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -7638,6 +7639,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -7674,7 +7715,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-query-digest b/bin/pt-query-digest index ba90a55f..4923c3cb 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -12446,15 +12446,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -12671,6 +12672,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -12707,7 +12748,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-slave-delay b/bin/pt-slave-delay index e79bd633..0ff73c59 100755 --- a/bin/pt-slave-delay +++ b/bin/pt-slave-delay @@ -3597,15 +3597,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -3822,6 +3823,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -3858,7 +3899,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-slave-restart b/bin/pt-slave-restart index f202ff2a..59cd6315 100755 --- a/bin/pt-slave-restart +++ b/bin/pt-slave-restart @@ -4306,15 +4306,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -4531,6 +4532,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -4567,7 +4608,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index c1f14786..67d4fccc 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -797,15 +797,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -1022,6 +1023,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -1058,7 +1099,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 93c06865..0817e384 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -9215,15 +9215,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -9440,6 +9441,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -9476,7 +9517,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-upgrade b/bin/pt-upgrade index c4753636..4e671878 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -4086,15 +4086,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -4311,6 +4312,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -4347,7 +4388,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/bin/pt-variable-advisor b/bin/pt-variable-advisor index ce80e9f2..e3aeb29e 100755 --- a/bin/pt-variable-advisor +++ b/bin/pt-variable-advisor @@ -4504,15 +4504,16 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -4729,6 +4730,46 @@ sub get_instance_id { } +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + + sub pingback { my (%args) = @_; my @required_args = qw(url instances); @@ -4765,7 +4806,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/lib/VersionCheck.pm b/lib/VersionCheck.pm index 0c126d11..b612dd04 100644 --- a/lib/VersionCheck.pm +++ b/lib/VersionCheck.pm @@ -48,6 +48,14 @@ eval { require HTTP::Micro; }; +my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; +my @vc_dirs = ( + '/etc/percona', + '/etc/percona-toolkit', + '/tmp', + "$home", +); + # Return the version check file used to keep track of # MySQL instance that have been checked and when. Some # systems use random tmp dirs; we don't want that else @@ -55,13 +63,6 @@ eval { # per system is the goal, so prefer global sys dirs first. { my $file = 'percona-version-check'; - my $home = $ENV{HOME} || $ENV{HOMEPATH} || $ENV{USERPROFILE} || '.'; - my @vc_dirs = ( - '/etc/percona', - '/etc/percona-toolkit', - '/tmp', - "$home", - ); sub version_check_file { foreach my $dir ( @vc_dirs ) { @@ -326,6 +327,49 @@ sub get_instance_id { return $name, $id; } + +# This function has been implemented solely to be able to count individual +# Toolkit users for statistics. It uses a random UUID, no client info is +# being gathered nor stored +sub get_uuid { + my $uuid_file = '/.percona-toolkit.uuid'; + foreach my $dir (@vc_dirs) { + my $filename = $dir.$uuid_file; + my $uuid=_read_uuid($filename); + return $uuid if $uuid; + } + + my $filename = $ENV{"HOME"} . $uuid_file; + my $uuid = _generate_uuid(); + + open(my $fh, '>', $filename) or die "Could not open file '$filename' $!"; + print $fh $uuid; + close $fh; + + return $uuid; +} + +sub _generate_uuid { + return sprintf+($}="%04x")."$}-$}-$}-$}-".$}x3,map rand 65537,0..7; +} + +sub _read_uuid { + my $filename = shift; + my $fh; + + eval { + open($fh, '<:encoding(UTF-8)', $filename); + }; + return if ($EVAL_ERROR); + + my $uuid; + eval { $uuid = <$fh>; }; + return if ($EVAL_ERROR); + + chomp $uuid; + return $uuid; +} + # ############################################################################# # Protocol handlers # ############################################################################# @@ -387,7 +431,7 @@ sub pingback { my $client_content = encode_client_response( items => $items, versions => $versions, - general_id => md5_hex( hostname() ), + general_id => get_uuid(), ); my $client_response = { diff --git a/t/lib/VersionCheck.t b/t/lib/VersionCheck.t index ba9881a5..30436a68 100644 --- a/t/lib/VersionCheck.t +++ b/t/lib/VersionCheck.t @@ -201,7 +201,7 @@ is_deeply( # Former Pingback tests # ############################################################################# -my $general_id = md5_hex( hostname() ); +my $general_id = VersionCheck::get_uuid(); my $master_id; # the instance ID, _not_ 12345 etc. my $slave1_id; # the instance ID, _not_ 12346 etc. my ($mysql_ver, $mysql_distro); @@ -679,6 +679,22 @@ foreach my $tool ( @vc_tools ) { ); } +my $should_remove_uuid_file; +my $home_uuid_file = $ENV{"HOME"} . "/.percona-toolkit.uuid"; + +if ( ! -e $home_uuid_file ) { + $should_remove_uuid_file = 1; +} + +my $uuid = VersionCheck::get_uuid(); +is ( + length($uuid), + 36, + "Have a valid UUID4", +); + +unlink $home_uuid_file if $should_remove_uuid_file; + # ############################################################################# # Done. # #############################################################################