Finished anvil-watch-servers

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 1 year ago
parent 26f4446bf9
commit fd880e2fdf
  1. 5
      share/words.xml
  2. 199
      tools/anvil-watch-servers

@ -458,7 +458,7 @@ Failed to parse the XML in the new definition file. The error was:
Giving up.
</key>
<key name="error_0332">This must be run on a node active in the cluster hosting the server being managed. Exiting.</key>
<key name="error_0332">This must be run on a subnode active in the cluster hosting the server being managed. Exiting.</key>
<key name="error_0333">There are no DR hosts connected to this Anvil! node yet.</key>
<key name="error_0334">Failed to find an IP we can access the DR host: [#!variable!host_name!#]. Has it been configured? Is it running? Exiting.</key>
<key name="error_0335">Failed to access the DR host: [#!variable!host_name!#] using the IP: [#!variable!ip_address!#]. Is it running? Exiting.</key>
@ -750,6 +750,8 @@ The XML that failed sanity check was:
<key name="error_0475">[ Error ] - The requested size: [#!variable!requested_ram!#] is less than 640 KiB, this must be a mistake.</key>
<key name="error_0476">[ Error ] - The requested CPU: [#!variable!requested_cpu!#] is not valid. Valid options are '--cpu X', '--cpu Y,X' or '--cpu 'Y,X,Z' where 'X' is the number of cores per socket, 'Y' is the number of sockets and 'Z' is the number of threads per core.</key>
<key name="error_0477">[ Error ] - The requested number of cores: [#!variable!requested_cores!#] (sockets: [#!variable!new_sockets!], cores per socket: [#!variable!new_cores!#], threads per core: [#!variable!new_threads!#]).</key>
<key name="error_0478">[ Error ] - This program must be run on a subnode.</key>
<key name="error_0479">[ Error ] - This subnode is not in the cluster (failed to parse the CIB). Exiting.</key>
<!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which lines are translatable -->
@ -3281,6 +3283,7 @@ proceeding.
- Cores per Socket: [#!variable!old_cores!#] -> [#!variable!new_cores!#]
- Threads per Core: [#!variable!old_threads!#] -> [#!variable!new_threads!#]
- Total Cores: .... [#!variable!old_total_cores!#] -> [#!variable!new_total_cores!#]]]></key>
<key name="message_0382"><![CDATA[-=] Updated: #!variable!date!# - Press '<ctrl> + <c>' to exit]]></key>
<!-- Translate names (protocols, etc) -->
<key name="name_0001">Normal Password</key> <!-- none in mail-server -->

@ -66,7 +66,7 @@ if ($anvil->data->{switches}{watch})
else
{
# No databases available.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "log_0738"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "log_0738"});
}
sleep $interval;
}
@ -89,25 +89,13 @@ sub show_status
{
my ($anvil) = @_;
if ($anvil->data->{switches}{watch})
{
system('clear');
print $t->Tgoto("cm", 0, 0);
}
if ($anvil->data->{switches}{watch})
{
my $date = $anvil->Get->date_and_time();
print "-=] Updated: ".$date." - Press '<ctrl> + <c>' to exit\n";
}
### TODO: Add support for checking/monitoring DR hosts
# Get the node states
my $host_type = $anvil->Get->host_type();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_type => $host_type }});
if ($host_type ne "node")
{
print "This must be run on a subnode. Exiting.\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0478"});
$anvil->nice_exit({exit_code => 1});
}
@ -118,31 +106,36 @@ sub show_status
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ($problem)
{
print "This subnode is not in the cluster (failed to parse the CIB). Exiting.\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0479"});
$anvil->nice_exit({exit_code => 1});
}
# foreach my $server_name (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{data}{server}})
# {
# print "DRBD Fence for Server: [".$server_name."]\n";
# foreach my $node_name (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{data}{server}{$server_name}{drbd_fence_node}})
# {
# my $value = $anvil->data->{cib}{parsed}{data}{server}{$server_name}{drbd_fence_node}{$node_name}{value};
# print "- Node: [".$node_name."], value: [".$value."]\n";
# }
# }
# die;
# Load host information so that we can check for IPMI configs, if needed.
$anvil->Database->get_hosts();
$anvil->Database->get_anvils();
$anvil->Database->get_servers();
# It can take a second to collect the data, so we don't clear the screen until we're ready to
# display the new data
$anvil->data->{display}{status} = "";
show_servers($anvil);
print "\n";
$anvil->data->{display}{status} .= "\n";
show_nodes($anvil);
# Show the results.
if ($anvil->data->{switches}{watch})
{
system('clear');
print $t->Tgoto("cm", 0, 0);
}
if ($anvil->data->{switches}{watch})
{
my $date = $anvil->Get->date_and_time();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "message_0382", variables => { date => $date }});
}
print $anvil->data->{display}{status};
return(0);
}
@ -151,7 +144,6 @@ sub show_servers
my ($anvil) = @_;
# Show the server states
$anvil->data->{'say'}{server_name} = $anvil->Words->string({key => "header_0121"});
$anvil->data->{'say'}{server_status} = $anvil->Words->string({key => "header_0122"});
$anvil->data->{'say'}{resource_status} = $anvil->Words->string({key => "header_0123"});
@ -325,15 +317,142 @@ sub show_servers
$longest_boot_time = length($say_boot_time);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { longest_boot_time => $longest_boot_time }});
}
}
=cut
Servers:
+-------------+-----------------+-------------------+-------------+------------------+--------------+-----------+
| server name | <server status> | <resource status> | <host node> | <preferred host> | <dbrd fence> | Boot Time |
+-------------+-----------------+-------------------+-------------+------------------+--------------+-----------+
=cut
# Now look again to show the subnode states
my $server_name_divider = ""; for (1..$longest_server_name) { $server_name_divider .= "-"; }
my $server_status_divider = ""; for (1..$longest_server_status) { $server_status_divider .= "-"; }
my $resource_status_divider = ""; for (1..$longest_resource_status) { $resource_status_divider .= "-"; }
my $host_name_divider = ""; for (1..$longest_host_name) { $host_name_divider .= "-"; }
my $preferred_host_divider = ""; for (1..$longest_preferred_host) { $preferred_host_divider .= "-"; }
my $drbd_fence_divider = ""; for (1..$longest_drbd_fence) { $drbd_fence_divider .= "-"; }
my $boot_time_divider = ""; for (1..$longest_boot_time) { $boot_time_divider .= "-"; }
my $say_server_name_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{server_name}, width => $longest_server_name});
my $say_server_status_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{server_status}, width => $longest_server_status});
my $say_resource_status_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{resource_status}, width => $longest_resource_status});
my $say_host_name_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{host_name}, width => $longest_host_name});
my $say_preferred_host_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{preferred_host}, width => $longest_preferred_host});
my $say_drbd_fence_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{drbd_fence}, width => $longest_drbd_fence});
my $say_boot_time_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{boot_time}, width => $longest_boot_time});
my $divider_line = "+-".$server_name_divider."-+-".$server_status_divider."-+-".$resource_status_divider."-+-".$host_name_divider."-+-".$preferred_host_divider."-+-".$drbd_fence_divider."-+-".$boot_time_divider."-+\n";
$anvil->data->{display}{status} .= $divider_line;
$anvil->data->{display}{status} .= "| ".$say_server_name_header." | ".$say_server_status_header." | ".$say_resource_status_header." | ".$say_host_name_header." | ".$say_preferred_host_header." | ".$say_drbd_fence_header." | ".$say_boot_time_header." |\n";
$anvil->data->{display}{status} .= $divider_line;
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};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:server_name' => $server_name,
's2:server_uuid' => $server_uuid,
}});
my $server_user_stop = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_user_stop};
my $server_host_uuid = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid};
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
my $server_boot_time = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_boot_time};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:server_user_stop' => $server_user_stop,
's2:server_host_uuid' => $server_host_uuid,
's3:server_state' => $server_state,
's4:server_boot_time' => $server_boot_time,
}});
# Database/virsh status
next if $server_state eq "DELETED";
my $say_server_state = $anvil->data->{'say'}{unknown};
if ($server_state eq "running") { $say_server_state = $anvil->data->{'say'}{running}; }
elsif ($server_state eq "blocked") { $say_server_state = $anvil->data->{'say'}{blocked}; }
elsif ($server_state eq "paused") { $say_server_state = $anvil->data->{'say'}{paused}; }
elsif ($server_state eq "in shutdown") { $say_server_state = $anvil->data->{'say'}{shutting_down}; }
elsif ($server_state eq "shut off") { $say_server_state = $anvil->data->{'say'}{shut_off}; }
elsif ($server_state eq "crashed") { $say_server_state = $anvil->data->{'say'}{crashed}; }
elsif ($server_state eq "pmsuspended") { $say_server_state = $anvil->data->{'say'}{pm_suspended}; }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_state => $server_state }});
# pcs resource status
my $resource_status = "--";
my $is_failed = "--";
my $say_resource_status = $anvil->data->{'say'}{unknown};
if (exists $anvil->data->{cib}{parsed}{data}{server}{$server_name})
{
$resource_status = $anvil->data->{cib}{parsed}{data}{server}{$server_name}{status};
$is_failed = $anvil->data->{cib}{parsed}{data}{server}{$server_name}{failed};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
resource_status => $resource_status,
is_failed => $is_failed,
}});
if ($resource_status eq "started") { $say_resource_status = $anvil->data->{'say'}{started}; }
elsif ($resource_status eq "starting") { $say_resource_status = $anvil->data->{'say'}{starting}; }
elsif ($resource_status eq "migrating") { $say_resource_status = $anvil->data->{'say'}{migrating}; }
elsif ($resource_status eq "stopping") { $say_resource_status = $anvil->data->{'say'}{stopping}; }
elsif ($resource_status eq "stopped") { $say_resource_status = $anvil->data->{'say'}{stopped}; }
else { $say_resource_status = $resource_status; }
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { resource_status => $resource_status }});
# Host node.
my $say_host_name = "--";
if (($server_host_uuid) && ($server_host_uuid ne "NULL"))
{
$say_host_name = $anvil->data->{hosts}{host_uuid}{$server_host_uuid}{short_host_name};
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_host_name => $say_host_name }});
my $say_preferred_host = "";
my $preferred_host_score = 0;
if (exists $anvil->data->{cib}{parsed}{data}{location_constraint}{$server_name})
{
$say_preferred_host = $anvil->data->{cib}{parsed}{data}{location_constraint}{$server_name}{preferred_host};
$preferred_host_score = $anvil->data->{cib}{parsed}{data}{location_constraint}{$server_name}{node}{$say_preferred_host}{score};
$say_preferred_host .= " (".$preferred_host_score.")";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_preferred_host => $say_preferred_host }});
}
# DRBD fence
my $say_drbd_fence = "--";
foreach my $node_name (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{data}{server}{$server_name}{drbd_fence_node}})
{
my $value = $anvil->data->{cib}{parsed}{data}{server}{$server_name}{drbd_fence_node}{$node_name}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
node_name => $node_name,
value => $value,
}});
if ($value eq "1")
{
$say_drbd_fence .= $node_name.",";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_drbd_fence => $say_drbd_fence }});
}
}
$say_drbd_fence =~ s/,$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_drbd_fence => $say_drbd_fence }});
# Boot time
my $say_boot_time = "--";
if ($server_boot_time)
{
$say_boot_time = $anvil->Get->date_and_time({use_time => $server_boot_time});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_boot_time => $say_boot_time }});
$anvil->data->{display}{status} .= "| ";
$anvil->data->{display}{status} .= sprintf("%-${longest_server_name}s", $server_name)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_server_status}s", $say_server_state)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_resource_status}s", $say_resource_status)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_host_name}s", $say_host_name)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_preferred_host}s", $say_preferred_host)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_drbd_fence}s", $say_drbd_fence)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_boot_time}s", $say_boot_time)." |\n";
}
$anvil->data->{display}{status} .= $divider_line;
return(0);
}
@ -479,9 +598,9 @@ Subnode Status:
my $say_maintenance_mode_header = $anvil->Words->center_text({string => $anvil->data->{'say'}{maintenance_mode}, width => $longest_maintenance_mode});
my $divider_line = "+-".$subnode_divider."-+-".$host_status_divider."-+-".$pacemaker_status_divider."-+-".$maintenance_mode_divider."-+\n";
print $divider_line;
print "| ".$say_subnode_header." | ".$say_host_status_header." | ".$say_pacemaker_status_header." | ".$say_maintenance_mode_header." |\n";
print $divider_line;
$anvil->data->{display}{status} .= $divider_line;
$anvil->data->{display}{status} .= "| ".$say_subnode_header." | ".$say_host_status_header." | ".$say_pacemaker_status_header." | ".$say_maintenance_mode_header." |\n";
$anvil->data->{display}{status} .= $divider_line;
foreach my $node_name (sort {$a cmp $b} keys %{$anvil->data->{cib}{parsed}{data}{node}})
{
my $host_uuid = $anvil->Database->get_host_uuid_from_string({string => $node_name});
@ -547,14 +666,14 @@ Subnode Status:
say_maintenance_mode => $say_maintenance_mode,
}});
print "| ";
print sprintf("%-${longest_node_name}s", $node_name)." | ";
print sprintf("%-${longest_host_status}s", $say_host_status)." | ";
print sprintf("%-${longest_pacemaker_status}s", $say_pacemaker_status)." | ";
print sprintf("%-${longest_maintenance_mode}s", $say_maintenance_mode)." |\n";
$anvil->data->{display}{status} .= "| ";
$anvil->data->{display}{status} .= sprintf("%-${longest_node_name}s", $node_name)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_host_status}s", $say_host_status)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_pacemaker_status}s", $say_pacemaker_status)." | ";
$anvil->data->{display}{status} .= sprintf("%-${longest_maintenance_mode}s", $say_maintenance_mode)." |\n";
}
print $divider_line;
$anvil->data->{display}{status} .= $divider_line;
return(0);
}

Loading…
Cancel
Save