fix(scancore-agents): get screenshot of server(s) running on local node in scan-server

main
Tsu-ba-me 1 year ago
parent b549ff2c1f
commit dac247f66e
  1. 110
      scancore-agents/scan-server/scan-server

@ -88,12 +88,12 @@ collect_data($anvil);
# Look for migration times written out by ocf:alteeve:server. # Look for migration times written out by ocf:alteeve:server.
record_migration_times($anvil); record_migration_times($anvil);
# Check if we need to update the websocket stuff.
check_vnc($anvil);
# Check that there's a DRBD fence rule for each server. # Check that there's a DRBD fence rule for each server.
check_drbd_fence_rules($anvil); check_drbd_fence_rules($anvil);
# Get screenshot from every server that is alive.
get_screenshots($anvil);
# Shut down. # Shut down.
$anvil->ScanCore->agent_shutdown({agent => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
@ -169,72 +169,66 @@ sub check_drbd_fence_rules
return(0); return(0);
} }
# # Gets a screenshot for each server that is alive.
sub check_vnc sub get_screenshots
{ {
my ($anvil) = @_; my $anvil = shift;
my $parameters = shift;
my $debug = $parameters->{debug} // 3;
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid();
my $local_host_uuid = $anvil->Get->host_uuid();
my $query = "SELECT host_name FROM hosts WHERE host_type = 'striker';";
my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ });
my $count = @{$results};
### NOTE: In the interest of time, this table is not yet in the core schema. Later, when it is, this $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query, count => $count } });
### check can be removed.
# See if the 'vnc_pipes' table exists.
my $query = "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'vnc_pipes' AND table_schema = 'public';";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
my $count = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; return (1) if ($count == 0);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if ($count) # Start the CSV with the first element, then append.
my $striker_name_csv = $results->[0]->[0];
foreach my $row ( @{$results}[1 .. $#{$results}] )
{ {
# For each server running here, get the VNC port and record it. my $host_name = $row->[0];
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid;
foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}})
{
my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_name => $server_name,
server_uuid => $server_uuid,
server_state => $server_state,
}});
next if $server_state eq "paused"; $striker_name_csv = "$striker_name_csv,$host_name";
next if $server_state eq "shut off"; }
next if $server_state eq "crashed";
# Get the VNC port. Ignore the IP and the port number is +5900. $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { striker_name_csv => $striker_name_csv } });
my $shell_call = $anvil->data->{path}{exe}{setsid}." --wait ".$anvil->data->{path}{exe}{virsh}." vncdisplay --domain ".$server_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__}); foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}})
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { {
output => $output, my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid};
return_code => $return_code,
}});
foreach my $line (split/\n/, $output)
{
if ($line =~ /\d.*?:(\d+)$/)
{
my $port = 5900 + $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { port => $port }});
my ($variable_uuid) = $anvil->Database->insert_or_update_variables({ my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid};
file => $THIS_FILE, my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
line => __LINE__,
variable_name => "server::vnc_port", $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
variable_value => $port, server_host_uuid => $server_host_uuid,
variable_default => "", server_name => $server_name,
variable_description => "message_0255", server_state => $server_state,
variable_section => "servers", server_uuid => $server_uuid,
variable_source_uuid => $server_uuid, } });
variable_source_table => "servers",
}); next if ( ($server_host_uuid ne $local_host_uuid) || (not $server_state eq "running") );
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }});
} my ($syscall_output, $syscall_rcode) = $anvil->System->call({
} debug => $debug,
} line => __LINE__,
shell_call => $anvil->data->{path}{exe}{'anvil-get-server-screenshot'}." --server-uuid '$server_uuid' --request-host-name '$striker_name_csv' &",
source => $THIS_FILE,
});
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => {
syscall_output => $syscall_output,
syscall_rcode => $syscall_rcode,
}});
} }
return(0); return (0);
} }
# Look for migration times written out by ocf:alteeve:server. # Look for migration times written out by ocf:alteeve:server.

Loading…
Cancel
Save