fix(tools): enable anvil-get-server-screenshot to send screenshot to multiple hosts

main
Tsu-ba-me 2 years ago
parent d9e6061b6e
commit ffd41b1dfa
  1. 37
      tools/anvil-get-server-screenshot

@ -167,7 +167,9 @@ my $server_uuid = $anvil->data->{switches}{'server-uuid'};
my $resize_args = $anvil->data->{switches}{resize};
my $request_host_uuid = $anvil->data->{switches}{'request-host-uuid'};
my $job_uuid = $anvil->data->{switches}{'job-uuid'};
my $out_file_id = defined $anvil->data->{switches}{'out-file-id'} ? $anvil->data->{switches}{'out-file-id'} : "0";
my $out_file_id = $anvil->data->{switches}{'out-file-id'};
$out_file_id = ( (defined $out_file_id) && ($out_file_id ne "#!SET!#") ) ? "_".$out_file_id : "";
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
debug => $debug,
@ -181,34 +183,43 @@ if ($server_uuid)
{
my $encoded_image = get_server_screenshot({ debug => $debug, server_uuid => $server_uuid, resize_args => $resize_args });
if ($encoded_image eq "")
{
$anvil->Job->update_progress({ progress => 100, message => "message_0265" });
$anvil->nice_exit({ exit_code => 1 });
}
if ($request_host_uuid)
{
my $request_host_ip_address = get_remote_call_requirements({ debug => $debug, host_uuid => $request_host_uuid });
my $out_file_path = $anvil->data->{path}{directories}{tmp}."/".$server_uuid."_screenshot_".$out_file_id;
chomp $request_host_uuid;
foreach my $host_uuid ( split(/[,]/, $request_host_uuid) )
{
my $request_host_ip_address = get_remote_call_requirements({ debug => $debug, host_uuid => $host_uuid });
my $out_file_path = $anvil->data->{path}{directories}{tmp}."/".$server_uuid."_screenshot".$out_file_id;
my $remote_shell_call = $anvil->data->{path}{exe}{echo}." '".$encoded_image."' 1<>'".$out_file_path."' >'".$out_file_path."'";
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { request_host_ip_address => $request_host_ip_address } });
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
out_file_path => $out_file_path,
remote_shell_call => $remote_shell_call,
request_host_ip_address => $request_host_ip_address,
} });
remote_call({ debug => $debug, shell_call => $remote_shell_call, target => $request_host_ip_address });
if (length($encoded_image))
{
$anvil->Job->update_progress({ progress => 100, message => "message_0264" });
}
else
{
$anvil->Job->update_progress({ progress => 100, message => "message_0265" });
$anvil->nice_exit({ exit_code => 1 });
}
}
else
{
print($encoded_image);
}
$anvil->Job->update_progress({ progress => 100, message => "message_0264" });
}
else
{
$anvil->Job->update_progress({ progress => 100, message => "message_0266" });
$anvil->nice_exit({ exit_code => 1 });
}

Loading…
Cancel
Save