Merge pull request #179 from ClusterLabs/anvil-tools-dev

Anvil tools dev
main
Digimer 3 years ago committed by GitHub
commit 789ac6e8ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      Anvil/Tools.pm
  2. 15
      Anvil/Tools/Database.pm
  3. 115
      Anvil/Tools/ScanCore.pm
  4. 2
      Anvil/Tools/Server.pm
  5. 5
      Anvil/Tools/Striker.pm
  6. 11
      anvil.conf
  7. 14
      scancore-agents/scan-apc-pdu/scan-apc-pdu
  8. 18
      scancore-agents/scan-apc-ups/scan-apc-ups
  9. 13
      scancore-agents/scan-cluster/scan-cluster
  10. 14
      scancore-agents/scan-drbd/scan-drbd
  11. 12
      scancore-agents/scan-filesystems/scan-filesystems
  12. 12
      scancore-agents/scan-hardware/scan-hardware
  13. 14
      scancore-agents/scan-hpacucli/scan-hpacucli
  14. 14
      scancore-agents/scan-ipmitool/scan-ipmitool
  15. 12
      scancore-agents/scan-lvm/scan-lvm
  16. 24
      scancore-agents/scan-network/scan-network
  17. 12
      scancore-agents/scan-server/scan-server
  18. 7
      scancore-agents/scan-storcli/scan-storcli
  19. 24
      share/words.xml
  20. 6
      tools/anvil-join-anvil
  21. 14
      tools/anvil-parse-fence-agents
  22. 179
      tools/anvil-update-definition
  23. 9
      tools/scancore

@ -1092,6 +1092,7 @@ sub _set_paths
status => "/var/www/html/status", status => "/var/www/html/status",
syslinux => "/usr/share/syslinux", syslinux => "/usr/share/syslinux",
tftpboot => "/var/lib/tftpboot", tftpboot => "/var/lib/tftpboot",
temp => "/tmp/anvil",
tools => "/usr/sbin", tools => "/usr/sbin",
units => "/usr/lib/systemd/system", units => "/usr/lib/systemd/system",
}, },

@ -1732,7 +1732,7 @@ sub connect
# } # }
} }
# Make sure my host UUID is valod # Make sure my host UUID is valid
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::host_uuid" => $anvil->data->{sys}{host_uuid} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::host_uuid" => $anvil->data->{sys}{host_uuid} }});
if ($anvil->data->{sys}{host_uuid} !~ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/) if ($anvil->data->{sys}{host_uuid} !~ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/)
{ {
@ -1753,6 +1753,19 @@ sub connect
return($anvil->data->{sys}{database}{connections}); return($anvil->data->{sys}{database}{connections});
} }
if (exists $anvil->data->{'log'}{scan_agent})
{
my $agent = $anvil->data->{'log'}{scan_agent};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { agent => $agent }});
if (exists $anvil->data->{scan_agent}{$agent}{last_db_count})
{
$anvil->data->{sys}{database}{last_db_count} = $anvil->data->{scan_agent}{$agent}{last_db_count};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"sys::database::last_db_count" => $anvil->data->{sys}{database}{last_db_count},
}});
}
}
# If we have a previous count and the new count is higher, resync. # If we have a previous count and the new count is higher, resync.
if (exists $anvil->data->{sys}{database}{last_db_count}) if (exists $anvil->data->{sys}{database}{last_db_count})
{ {

@ -15,6 +15,7 @@ our $VERSION = "3.0.0";
my $THIS_FILE = "ScanCore.pm"; my $THIS_FILE = "ScanCore.pm";
### Methods; ### Methods;
# agent_shutdown
# agent_startup # agent_startup
# call_scan_agents # call_scan_agents
# check_health # check_health
@ -88,6 +89,57 @@ sub parent
############################################################################################################# #############################################################################################################
=head2 agent_shutdown
This method handles recording run data to the agent's data file.
Parameters;
=head3 agent (required)
This is the name of the scan agent. Usually this can be set as C<< $THIS_FILE >>.
=cut
sub agent_shutdown
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "ScanCore->agent_shutdown()" }});
my $agent = defined $parameter->{agent} ? $parameter->{agent} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
agent => $agent,
}});
# Setting this will prepend messages coming grom the agent with the agent's name
$anvil->data->{'log'}{scan_agent} = $agent;
# If this agent ran before, it should have recorded how many databases it last connected to. Read
# that, if so.
my $data_file = $anvil->data->{path}{directories}{temp}."/".$agent.".data";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { data_file => $data_file }});
my $file_body = "last_run:".time."\n";
$file_body .= "last_db_count:".$anvil->data->{sys}{database}{connections}."\n";
my $error = $anvil->Storage->write_file({
debug => $debug,
file => $data_file,
body => $file_body,
overwrite => 1,
backup => 0,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { error => $error }});
# Mark that we ran.
$anvil->Database->insert_or_update_updated({updated_by => $agent});
$anvil->nice_exit({exit_code => 0});
return(0);
}
=head2 agent_startup =head2 agent_startup
This method handles connecting to the databases, loading the agent's schema, resync'ing database tables if needed and reading in the words files. This method handles connecting to the databases, loading the agent's schema, resync'ing database tables if needed and reading in the words files.
@ -126,9 +178,68 @@ sub agent_startup
tables => $tables, tables => $tables,
}}); }});
# Adjust the log level, if required.
if ((exists $anvil->data->{scancore}{$agent}{log_level}) && ($anvil->data->{scancore}{$agent}{log_level} =~ /^\d+$/))
{
$anvil->Log->level({set => $anvil->data->{scancore}{$agent}{log_level}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"scancore::${agent}::log_level" => $anvil->data->{scan_agent}{$agent}{log_level},
}});
}
if ((exists $anvil->data->{scancore}{$agent}{log_secure}) && ($anvil->data->{scancore}{$agent}{log_secure} =~ /^\d+$/))
{
$anvil->Log->secure({set => $anvil->data->{scancore}{$agent}{log_secure}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"scancore::${agent}::log_level" => $anvil->data->{scan_agent}{$agent}{log_secure},
}});
}
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{$agent}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "log_0646", variables => { program => $THIS_FILE }});
$anvil->nice_exit({exit_code => 0});
}
# Setting this will prepend messages coming grom the agent with the agent's name # Setting this will prepend messages coming grom the agent with the agent's name
$anvil->data->{'log'}{scan_agent} = $agent; $anvil->data->{'log'}{scan_agent} = $agent;
# If this agent ran before, it should have recorded how many databases it last connected to. Read
# that, if so.
my $data_file = $anvil->data->{path}{directories}{temp}."/".$agent.".data";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { data_file => $data_file }});
$anvil->data->{scan_agent}{$agent}{last_run} = "";
$anvil->data->{scan_agent}{$agent}{last_db_count} = 0;
if (-f $data_file)
{
my $file_body = $anvil->Storage->read_file({
debug => $debug,
file => $data_file,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { file_body => $file_body }});
foreach my $line (split/\n/, $file_body)
{
if ($line =~ /^last_run:(\d+)/)
{
$anvil->data->{scan_agent}{$agent}{last_run} = $1;
$anvil->data->{scan_agent}{$agent}{time_since_last_run} = time - $anvil->data->{scan_agent}{$agent}{last_run};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"scan_agent::${agent}::last_run" => $anvil->data->{scan_agent}{$agent}{last_run},
"scan_agent::${agent}::time_since_last_run" => $anvil->data->{scan_agent}{$agent}{time_since_last_run},
}});
}
if ($line =~ /^last_db_count:(\d+)/)
{
$anvil->data->{scan_agent}{$agent}{last_db_count} = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"scan_agent::${agent}::last_db_count" => $anvil->data->{scan_agent}{$agent}{last_db_count},
}});
}
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { tables => $tables }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { tables => $tables }});
if ((not $tables) or (ref($tables) ne "ARRAY")) if ((not $tables) or (ref($tables) ne "ARRAY"))
{ {
@ -160,7 +271,7 @@ sub agent_startup
} }
# Connect to DBs. # Connect to DBs.
$anvil->Database->connect({debug => $debug}); $anvil->Database->connect({debug => 2});
$anvil->Log->entry({source => $agent, line => __LINE__, level => $debug, secure => 0, key => "log_0132"}); $anvil->Log->entry({source => $agent, line => __LINE__, level => $debug, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections}) if (not $anvil->data->{sys}{database}{connections})
{ {
@ -232,7 +343,7 @@ sub call_scan_agents
$anvil->ScanCore->_scan_directory({directory => $anvil->data->{path}{directories}{scan_agents}}); $anvil->ScanCore->_scan_directory({directory => $anvil->data->{path}{directories}{scan_agents}});
# Now loop through the agents I found and call them. # Now loop through the agents I found and call them.
my $timeout = 60; my $timeout = 30;
if ((exists $anvil->data->{scancore}{timing}{agent_runtime}) && ($anvil->data->{scancore}{timing}{agent_runtime} =~ /^\d+$/)) if ((exists $anvil->data->{scancore}{timing}{agent_runtime}) && ($anvil->data->{scancore}{timing}{agent_runtime} =~ /^\d+$/))
{ {
$timeout = $anvil->data->{scancore}{timing}{agent_runtime}; $timeout = $anvil->data->{scancore}{timing}{agent_runtime};

@ -1032,7 +1032,7 @@ WHERE
{ {
$live_migrate = "--live"; $live_migrate = "--live";
} }
my $target_ip = $anvil->Convert->host_name_to_ip({debug => $debug, host_name => $target}); my $target_ip = $anvil->Convert->host_name_to_ip({debug => $debug, host_name => $target});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
target_ip => $target_ip, target_ip => $target_ip,
live_migrate => $live_migrate, live_migrate => $live_migrate,

@ -440,7 +440,10 @@ sub get_fence_data
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Striker->get_fence_data()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Striker->get_fence_data()" }});
my $parsed_xml = ""; my $parsed_xml = "";
my $xml_body = $anvil->Storage->read_file({file => $anvil->data->{path}{data}{fences_unified_metadata}}); my $xml_body = $anvil->Storage->read_file({
debug => $debug,
file => $anvil->data->{path}{data}{fences_unified_metadata},
});
# Globally replace \fI (opening underline) with '[' and \fP (closing underline) with ']'. # Globally replace \fI (opening underline) with '[' and \fP (closing underline) with ']'.
$xml_body =~ s/\\fI/[/gs; $xml_body =~ s/\\fI/[/gs;

@ -193,3 +193,14 @@ sys::manage::firewall = 1
# This is the "short list" of servers shown when provisioning a new server. To see the full list of options, # This is the "short list" of servers shown when provisioning a new server. To see the full list of options,
# run '/usr/bin/osinfo-query os' on any machine in the Anvil!. # run '/usr/bin/osinfo-query os' on any machine in the Anvil!.
#sys::servers::os_short_list = debian10,fedora32,freebsd12.1,gentoo,macosx10.7,msdos6.22,openbsd6.7,opensuse15.2,rhel5.11,rhel6.10,rhel7.9,rhel8.3,sles12sp5,solaris11,ubuntu20.04,win10,win2k16,win2k19 #sys::servers::os_short_list = debian10,fedora32,freebsd12.1,gentoo,macosx10.7,msdos6.22,openbsd6.7,opensuse15.2,rhel5.11,rhel6.10,rhel7.9,rhel8.3,sles12sp5,solaris11,ubuntu20.04,win10,win2k16,win2k19
### Scan agent options
# All scan agent configurations have the format 'scancore::<agent_name>::<variable>'.
# An agent can be disabled on a given machine by setting the 'disable' variable.
#scancore::scan-network::disable = 1
# Logging can be set on a per-agent basis with:
#scancore::scan-network::log_level = 2
#scancore::scan-network::log_secure = 1

@ -170,13 +170,6 @@ if (($host_type ne "striker") && (not $anvil->data->{switches}{force}))
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-apc-pdu'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -212,11 +205,8 @@ gather_pdu_data($anvil);
# Look for changes. # Look for changes.
find_changes($anvil); find_changes($anvil);
# Update the database # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
# Clean up and go away.
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################

@ -197,13 +197,6 @@ if (($host_type ne "striker") && (not $anvil->data->{switches}{force}))
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-apc-ups'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -239,15 +232,8 @@ gather_ups_data($anvil);
# Look for changes. # Look for changes.
find_changes($anvil); find_changes($anvil);
# Update the database # Shut down.
my $updated_uuid = $anvil->Database->insert_or_update_updated({ $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
debug => 2,
updated_by => $THIS_FILE,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { updated_uuid => $updated_uuid }});
# Clean up and go away.
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################

@ -56,13 +56,6 @@ $anvil->Storage->read_config();
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-cluster'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -106,11 +99,9 @@ check_config($anvil);
# Check the fence delay # Check the fence delay
check_fence_delay($anvil); check_fence_delay($anvil);
# Check that the location constraint is sensible. # Shut down.
$anvil->Cluster->check_server_constraints(); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #

@ -59,13 +59,6 @@ $anvil->Storage->read_config();
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-drbd'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
@ -103,11 +96,8 @@ find_changes($anvil);
check_config($anvil); check_config($anvil);
# Update the database # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
# Clean up and go away.
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################

@ -58,13 +58,6 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-filesystems'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -92,10 +85,9 @@ read_last_scan($anvil);
# Loog for changes # Loog for changes
find_changes($anvil); find_changes($anvil);
# Mark that we ran. # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #

@ -59,13 +59,6 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print'
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-hardware'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -96,10 +89,9 @@ find_changes($anvil);
# Finally, process health weights. # Finally, process health weights.
process_health($anvil); process_health($anvil);
# Mark that we ran. # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #

@ -165,13 +165,6 @@ $anvil->data->{switches}{force} = 0;
$anvil->data->{switches}{purge} = 0; $anvil->data->{switches}{purge} = 0;
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-hpacucli'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -212,11 +205,8 @@ process_temperatures($anvil);
# Finally, process health weights. # Finally, process health weights.
process_health($anvil); process_health($anvil);
# Update the database # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
# Clean up and go away.
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################

@ -205,13 +205,6 @@ $anvil->data->{switches}{force} = 0;
$anvil->data->{switches}{purge} = 0; $anvil->data->{switches}{purge} = 0;
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-ipmitool'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -248,11 +241,8 @@ find_changes($anvil);
# Finally, process health weights. # Finally, process health weights.
process_health($anvil); process_health($anvil);
# Update the database # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
# Clean up and go away.
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################

@ -57,13 +57,6 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-lvm'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -91,10 +84,9 @@ read_last_scan($anvil);
# Loog for changes # Loog for changes
find_changes($anvil); find_changes($anvil);
# Mark that we ran. # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #

@ -51,14 +51,6 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print'
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-hardware'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "log_0646", variables => { program => $THIS_FILE }});
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -90,10 +82,9 @@ find_changes($anvil);
# Finally, process health weights. # Finally, process health weights.
process_health($anvil); process_health($anvil);
# Mark that we ran. # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #
@ -212,8 +203,12 @@ sub collect_data
$speed =~ s/\n$//; $speed =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface, interface => $interface,
speed => $speed,
mac_address => $mac_address, mac_address => $mac_address,
link_state => $link_state,
mtu => $mtu,
duplex => $duplex,
operational => $operational,
speed => $speed,
}}); }});
# These are variables that will be needed if this is a bond interface. # These are variables that will be needed if this is a bond interface.
@ -475,6 +470,11 @@ sub collect_data
"cache::new_file" => $anvil->data->{cache}{new_file}, "cache::new_file" => $anvil->data->{cache}{new_file},
}}); }});
} }
if (($interface =~ /^vnet/) && ($operational ne "up"))
{
#die;
}
} }
} }
closedir(DIRECTORY); closedir(DIRECTORY);

@ -58,13 +58,6 @@ $anvil->Storage->read_config();
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# If we're disabled and '--force' wasn't used, exit.
if (($anvil->data->{scancore}{'scan-server'}{disable}) && (not $anvil->data->{switches}{force}))
{
# Exit.
$anvil->nice_exit({exit_code => 0});
}
# Handle start-up tasks # Handle start-up tasks
my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE}); my $problem = $anvil->ScanCore->agent_startup({agent => $THIS_FILE});
if ($problem) if ($problem)
@ -94,10 +87,9 @@ record_migration_times($anvil);
# Check if we need to update the websocket stuff. # Check if we need to update the websocket stuff.
check_vnc($anvil); check_vnc($anvil);
# Mark that we ran. # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #

@ -260,11 +260,8 @@ process_temperatures($anvil);
# Finally, process health weights. # Finally, process health weights.
process_health($anvil); process_health($anvil);
# Update the database # Shut down.
$anvil->Database->insert_or_update_updated({updated_by => $THIS_FILE}); $anvil->ScanCore->agent_shutdown({agent => $THIS_FILE});
# Clean up and go away.
$anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################

@ -434,6 +434,19 @@ The attempt to start the servers appears to have failed. The return code '0' was
<key name="error_0320">The Anvil! UUID: [#!variable!anvil_uuid!#] is not valid or was not found in the database.</key> <key name="error_0320">The Anvil! UUID: [#!variable!anvil_uuid!#] is not valid or was not found in the database.</key>
<key name="error_0321">There are no Anvil! systems yet in the database, nothing to do.</key> <key name="error_0321">There are no Anvil! systems yet in the database, nothing to do.</key>
<key name="error_0322">There are no servers yet in the database, nothing to do.</key> <key name="error_0322">There are no servers yet in the database, nothing to do.</key>
<key name="error_0323">You need to specify the updated definition file with '--file /path/to/definition.xml'.</key>
<key name="error_0324">You definition file: [#!variable!file!#] doesn't exist or couldn't be read.</key>
<key name="error_0325">The server name was not found in the new definition file.</key>
<key name="error_0326">The server UUID was not found (or is not valid) in the new definition file.</key>
<key name="error_0327">
Failed to parse the XML in the new definition file. The error was:
====
#!variable!error!#
====
</key>
<key name="error_0328"><![CDATA[Failed to parse the assigned memory from the definition file. Expected the memory defined as '<memory unit='XiB'>Y</memory>'.]]></key>
<key name="error_0329">The server UUID: [#!variable!server_uuid!#] in the definition file wasn't found in the database, unable to update.</key>
<key name="error_0330">The new definition has changed the server's name from: [#!variable!current_name!#] to: [#!variable!new_name!#]. Changing the server's name must be done with the 'anvil-rename-server' tool.</key>
<!-- Files templates --> <!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which lines are translatable --> <!-- NOTE: Translating these files requires an understanding of which lines are translatable -->
@ -2876,6 +2889,17 @@ Read UUID: .... [#!variable!read_uuid!#]
<key name="warning_0125">[ Warning ] - Asked to check server location constraints, but this is not a node.</key> <key name="warning_0125">[ Warning ] - Asked to check server location constraints, but this is not a node.</key>
<key name="warning_0126">[ Warning ] - Asked to check server location constraints, but this node is not in a cluster.</key> <key name="warning_0126">[ Warning ] - Asked to check server location constraints, but this node is not in a cluster.</key>
<key name="warning_0127">[ Warning ] - Asked to check server location constraints, but this node is not fully in the cluster yet.</key> <key name="warning_0127">[ Warning ] - Asked to check server location constraints, but this node is not fully in the cluster yet.</key>
<key name="warning_0128">[ Warning ] - Failed to parse the fence agent: [#!variable!agent!#]'s XML metadata:
========
#!variable!metadata!#
========
The error was:
========
#!variable!error!#
========
</key>
<!-- The entries below here are not sequential, but use a key to find the entry. --> <!-- The entries below here are not sequential, but use a key to find the entry. -->
<!-- Run 'striker-parse-os-list to find new entries. --> <!-- Run 'striker-parse-os-list to find new entries. -->

@ -538,7 +538,7 @@ sub configure_pacemaker
}}); }});
$pcs_add_command = $anvil->data->{path}{exe}{pcs}." stonith create ".$ipmi_stonith_name." ".$fence_agent." pcmk_host_list=\"".$node_name."\" "; $pcs_add_command = $anvil->data->{path}{exe}{pcs}." stonith create ".$ipmi_stonith_name." ".$fence_agent." pcmk_host_list=\"".$node_name."\" ";
my $switches = $anvil->System->parse_arguments({arguments => $arguments}); my $switches = $anvil->System->parse_arguments({debug => 2, arguments => $arguments});
foreach my $switch (sort {$a cmp $b} keys %{$switches}) foreach my $switch (sort {$a cmp $b} keys %{$switches})
{ {
# Ignore 'delay', we handle that in Cluster->set_delay(); Also, # Ignore 'delay', we handle that in Cluster->set_delay(); Also,
@ -546,7 +546,7 @@ sub configure_pacemaker
my $value = $switches->{$switch}; my $value = $switches->{$switch};
$value =~ s/"/\\"/g; $value =~ s/"/\\"/g;
$value =~ s/#!SET!#/true/g; $value =~ s/#!SET!#/true/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
switch => $switch, switch => $switch,
value => $value, value => $value,
}}); }});
@ -556,7 +556,7 @@ sub configure_pacemaker
# Find the argument=value version. # Find the argument=value version.
my $argument = $anvil->data->{fence_data}{$fence_agent}{switch}{$switch}{name}; my $argument = $anvil->data->{fence_data}{$fence_agent}{switch}{$switch}{name};
$pcs_add_command .= $argument."=\"".$value."\" "; $pcs_add_command .= $argument."=\"".$value."\" ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
argument => $argument, argument => $argument,
value => $argument =~ /passw/ ? $anvil->Log->is_secure($value) : $value, value => $argument =~ /passw/ ? $anvil->Log->is_secure($value) : $value,
pcs_add_command => $pcs_add_command =~ /passw/ ? $anvil->Log->is_secure($pcs_add_command) : $pcs_add_command, pcs_add_command => $pcs_add_command =~ /passw/ ? $anvil->Log->is_secure($pcs_add_command) : $pcs_add_command,

@ -147,6 +147,20 @@ sub unify_metadata
metadata => $metadata, metadata => $metadata,
return_code => $return_code, return_code => $return_code,
}}); }});
# Test that the metadata is valid XML.
local $@;
my $dom = eval { XML::LibXML->load_xml(string => $metadata); };
if ($@)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "warning_0128", variables => {
agent => $fence_agent_file,
metadata => $metadata,
error => $@,
}});
return(1);
}
if ($metadata =~ /<\?xml version="1.0" \?>/gs) if ($metadata =~ /<\?xml version="1.0" \?>/gs)
{ {
$metadata =~ s/<\?xml version="1.0" \?>/<agent name="$fence_agent_file">/gs; $metadata =~ s/<\?xml version="1.0" \?>/<agent name="$fence_agent_file">/gs;

@ -0,0 +1,179 @@
#!/usr/bin/perl
#
# This program will manage servers; Changing RAM, CPU cores, Growing virtual disks, adding virtual disks,
# inserting and ejecting ISO images into virtual optical media.
#
# Exit codes;
# 0 = Normal exit.
# 1 = No database connection.
#
# TODO:
#
use strict;
use warnings;
use Anvil::Tools;
require POSIX;
use Term::Cap;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
if (($running_directory =~ /^\./) && ($ENV{PWD}))
{
$running_directory =~ s/^\./$ENV{PWD}/;
}
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $anvil = Anvil::Tools->new();
$anvil->data->{switches}{file} = "";
$anvil->Get->switches;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::file' => $anvil->data->{switches}{file},
}});
# Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks
# is to setup the database server.
$anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, update the job, sleep for a bit and then exit. The daemon will pick it up and try
# again after we exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0305"});
$anvil->nice_exit({exit_code => 1});
}
# Does the file exist?
if (not $anvil->data->{switches}{file})
{
# Not defined.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0323"});
$anvil->nice_exit({exit_code => 1});
}
elsif ((not -e $anvil->data->{switches}{file}) or (not -r $anvil->data->{switches}{file}))
{
# Not found or can't be read.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0324", variables => {
file => $anvil->data->{switches}{file},
}});
$anvil->nice_exit({exit_code => 1});
}
validate_and_update($anvil);
$anvil->nice_exit({exit_code => 0});
#############################################################################################################
# Functions #
#############################################################################################################
sub validate_and_update
{
my ($anvil) = @_;
# Can we parse the definition?
my $new_definition = $anvil->Storage->read_file({file => $anvil->data->{switches}{file}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_definition => $new_definition }});
# Pull the server name and uuid out.
my $server_name = "";
my $server_uuid = "";
foreach my $line (split/\n/, $new_definition)
{
if ($line =~ /<name>(.*?)<\/name>/)
{
$server_name = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_name => $server_name }});
}
if ($line =~ /<uuid>(.*?)<\/uuid>/)
{
$server_uuid = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_uuid => $server_uuid }});
}
}
# If I didn't find the server name or UUID, there's a problem.
if ($server_name eq "")
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0325"});
$anvil->nice_exit({exit_code => 1});
}
if (($server_uuid eq "") or (not $anvil->Validate->uuid({uuid => $server_uuid})))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0326"});
$anvil->nice_exit({exit_code => 1});
}
local $@;
my $dom = eval { XML::LibXML->load_xml(string => $new_definition); };
if ($@)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0327", variables => { error => $@ }});
$anvil->nice_exit({exit_code => 1});
}
# Find out how much memory being allocated.
my $memory = 0;
foreach my $memory ($dom->findnodes('/domain/memory'))
{
my $units = $memory->{unit};
my $value = $memory->to_literal();
$memory = $anvil->Convert->human_readable_to_bytes({size => $value, type => $units});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
units => $units,
value => $value,
memory => $memory." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $memory}).")",
}});
}
if (not $memory)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0328"});
$anvil->nice_exit({exit_code => 1});
}
# Do we know about this server yet?
$anvil->Database->get_servers();
if (not exists $anvil->data->{servers}{server_uuid}{$server_uuid})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0329", variables => { server_uuid => $server_uuid }});
$anvil->nice_exit({exit_code => 1});
}
# We can't update the server name with this tool.
if ($server_name ne $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0330", variables => {
current_name => $current_name.
new_name => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name},
}});
$anvil->nice_exit({exit_code => 1});
}
# Still here? Update! Has the assigned RAM changed?
my $configured_ram = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_configured_ram};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
configured_ram => $configured_ram." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $configured_ram}).")",
}});
if ($memory != $configured_ram)
{
# Update the configured RAM value.
my $query = "
UPDATE
servers
SET
server_configured_ram = ".$anvil->Database->quote($memory).",
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid).",
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
return(0);
}

@ -128,7 +128,7 @@ while(1)
if ($anvil->data->{sys}{database}{connections}) if ($anvil->data->{sys}{database}{connections})
{ {
# Run the normal tasks # Run the normal tasks
$anvil->ScanCore->call_scan_agents({debug => 2}); $anvil->ScanCore->call_scan_agents();
# Do post-scan analysis. # Do post-scan analysis.
$anvil->ScanCore->post_scan_analysis({debug => 2}); $anvil->ScanCore->post_scan_analysis({debug => 2});
@ -224,6 +224,7 @@ sub exit_if_sums_changed
sub prepare_for_run sub prepare_for_run
{ {
my ($anvil) = @_; my ($anvil) = @_;
# Reload defaults, re-read the config and then connect to the database(s) # Reload defaults, re-read the config and then connect to the database(s)
$anvil->_set_paths(); $anvil->_set_paths();
$anvil->_set_defaults(); $anvil->_set_defaults();
@ -332,7 +333,7 @@ sub startup_tasks
foreach my $scan_agent (sort {$a cmp $b} keys %{$anvil->data->{scancore}{agent}}) foreach my $scan_agent (sort {$a cmp $b} keys %{$anvil->data->{scancore}{agent}})
{ {
my $schema_file = $anvil->data->{path}{directories}{scan_agents}."/".$scan_agent."/".$scan_agent.".sql"; my $schema_file = $anvil->data->{path}{directories}{scan_agents}."/".$scan_agent."/".$scan_agent.".sql";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
scan_agent => $scan_agent, scan_agent => $scan_agent,
schema_file => $schema_file, schema_file => $schema_file,
}}); }});
@ -342,7 +343,7 @@ sub startup_tasks
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { tables => $tables }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { tables => $tables }});
my $table_count = @{$tables}; my $table_count = @{$tables};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { table_count => $table_count }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { table_count => $table_count }});
# It's possible that some agents don't have a database (or use core database tables only) # It's possible that some agents don't have a database (or use core database tables only)
if (@{$tables} > 0) if (@{$tables} > 0)
@ -386,7 +387,7 @@ sub startup_tasks
if ($host_type eq "node") if ($host_type eq "node")
{ {
my $uptime = $anvil->Get->uptime; my $uptime = $anvil->Get->uptime;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uptime => $uptime }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uptime => $uptime }});
if ($uptime < 600) if ($uptime < 600)
{ {
# Run it as a background task # Run it as a background task

Loading…
Cancel
Save