From a74be604695750b04c6d183b6d6931c631291bd8 Mon Sep 17 00:00:00 2001 From: Digimer Date: Sun, 2 May 2021 23:35:37 -0400 Subject: [PATCH 1/3] * Fixed a bug where the log message for a changed CIB wasn't useful. Signed-off-by: Digimer --- scancore-agents/scan-cluster/scan-cluster | 14 +++++++++----- scancore-agents/scan-cluster/scan-cluster.xml | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scancore-agents/scan-cluster/scan-cluster b/scancore-agents/scan-cluster/scan-cluster index c28eb9cc..98ab2a01 100755 --- a/scancore-agents/scan-cluster/scan-cluster +++ b/scancore-agents/scan-cluster/scan-cluster @@ -19,6 +19,7 @@ use strict; use warnings; use Anvil::Tools; use Data::Dumper; +use Text::Diff; # Disable buffering $| = 1; @@ -193,7 +194,7 @@ WHERE UPDATE scan_cluster SET - scan_cluster_cib = ".$anvil->Database->quote($cluster_name).", + scan_cluster_cib = ".$anvil->Database->quote($cluster_cib).", modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." WHERE scan_cluster_uuid = ".$anvil->Database->quote($scan_cluster_uuid)." @@ -201,12 +202,15 @@ WHERE $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); + my $difference = diff \$old_cluster_cib, \$cluster_cib, { STYLE => 'Unified' }; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { difference => $difference }}); + my $variables = { - new_cluster_name => $cluster_name, - old_cluster_name => $old_cluster_name, + cluster_name => $cluster_name, + difference => $difference, }; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_cluster_alert_0002", variables => $variables}); - $anvil->Alert->register({debug => 2, alert_level => "notice", message => "scan_cluster_alert_0002", variables => $variables, set_by => $THIS_FILE}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_cluster_alert_0012", variables => $variables}); + $anvil->Alert->register({debug => 2, alert_level => "notice", message => "scan_cluster_alert_0012", variables => $variables, set_by => $THIS_FILE}); } } else diff --git a/scancore-agents/scan-cluster/scan-cluster.xml b/scancore-agents/scan-cluster/scan-cluster.xml index 1d875138..49c2b3e6 100644 --- a/scancore-agents/scan-cluster/scan-cluster.xml +++ b/scancore-agents/scan-cluster/scan-cluster.xml @@ -32,6 +32,11 @@ In Maintenance Mode: ..... [#!variable!maintenance_mode!#] The node: [#!variable!old_node_name!#] has been renamed to: [#!variable!new_node_name!#] The node: [#!variable!host_name!#] is no longer in the cluster. The node: [#!variable!host_name!#] is returning back into the cluster. + The Cluster CIB for the cluster: [#!variable!cluster_name!#] has changed. The difference is: +==== +#!variable!difference!# +==== + Starting: [#!variable!program!#]. From 3fb81c1a0a8b7a215e55eac578ce25ea15e90b7c Mon Sep 17 00:00:00 2001 From: Digimer Date: Tue, 4 May 2021 12:33:31 -0400 Subject: [PATCH 2/3] * Updated Convert->time() to silently return if the given time was '--'. * Added a new parameter to Database->connect() called 'no_resync' that, if set, prevents a resync check being performed. Updated ->resync_databases() to find a uuid_column where the table name ends in 'ies' and the UUID column is 'y_uuid'. Updated ->resync_databases() to not fire on updated table age anymore, and to trigger only if the number of rows differ in a given table by more than 10. * Updated Log->entry() to prefix a tool's name, when the new 'log::scan_agent' value is set. Also set this value in ScanCore->agent_startup(), to help differentiate log entries. * Fixed a bug in scancore's main loop where it logged the sleep message at the start of the run. Signed-off-by: Digimer --- Anvil/Tools/Convert.pm | 6 +++ Anvil/Tools/Database.pm | 107 ++++++++++++++++++++++++++-------------- Anvil/Tools/Log.pm | 4 ++ Anvil/Tools/ScanCore.pm | 10 +++- Anvil/Tools/System.pm | 5 +- notes | 5 +- tools/anvil-daemon | 28 +++++------ tools/scancore | 11 +++-- 8 files changed, 116 insertions(+), 60 deletions(-) diff --git a/Anvil/Tools/Convert.pm b/Anvil/Tools/Convert.pm index 35c63398..b1589a36 100644 --- a/Anvil/Tools/Convert.pm +++ b/Anvil/Tools/Convert.pm @@ -1340,6 +1340,12 @@ sub time translate => $translate, }}); + # If the 'time' is '--', return silently. + if ($time eq "--") + { + return("--"); + } + # Remote commas and verify we're left with a number. $time =~ s/,//g; if ($time =~ /^\d+\.\d+$/) diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 4c180f3e..5c41b07f 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -1102,6 +1102,10 @@ If set, the connection will be made only to the database server matching the UUI If set to C<< 1 >>, no attempt to ping a target before connection will happen, even if C<< database::::ping = 1 >> is set. +=head3 no_resync (optional, default 0) + +If set to C<< 1 >>, no checks will be made to resync the database. Generally this is only useful to scan agents (as ScanCore itself is better at detecting and resyncing). + =head3 source (optional) The C<< source >> parameter is used to check the special C<< updated >> table on all connected databases to see when that source (program name, usually) last updated a given database. If the date stamp is the same on all connected databases, nothing further happens. If one of the databases differ, however, a resync will be requested. @@ -1159,6 +1163,7 @@ sub connect my $check_if_configured = defined $parameter->{check_if_configured} ? $parameter->{check_if_configured} : 0; my $db_uuid = defined $parameter->{db_uuid} ? $parameter->{db_uuid} : ""; my $no_ping = defined $parameter->{no_ping} ? $parameter->{no_ping} : 0; + my $no_resync = defined $parameter->{no_resync} ? $parameter->{no_resync} : 0; my $source = defined $parameter->{source} ? $parameter->{source} : "core"; my $sql_file = defined $parameter->{sql_file} ? $parameter->{sql_file} : $anvil->data->{path}{sql}{'anvil.sql'}; my $tables = defined $parameter->{tables} ? $parameter->{tables} : ""; @@ -1167,6 +1172,7 @@ sub connect check_if_configured => $check_if_configured, db_uuid => $db_uuid, no_ping => $no_ping, + no_resync => $no_resync, source => $source, sql_file => $sql_file, tables => $tables, @@ -1717,8 +1723,11 @@ sub connect # For now, we just find which DBs are behind and let each agent deal with bringing their tables up to # date. - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::connections" => $anvil->data->{sys}{database}{connections} }}); - if ($anvil->data->{sys}{database}{connections} > 1) + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "sys::database::connections" => $anvil->data->{sys}{database}{connections}, + no_resync => $no_resync, + }}); + if (($anvil->data->{sys}{database}{connections} > 1) && (not $no_resync)) { # If we have a "last_db_count" and it's the same as the current number of connections, skip # checking for a resync. This is done because the databases change constantly so tables like @@ -14588,6 +14597,7 @@ sub resync_databases # We don't sync 'states' as it's transient and sometimes per-DB. next if $table eq "states"; next if $table eq "oui"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { table => $table }}); # If the 'schema' is 'public', there is no table in the history schema. If there is a host # column, the resync will be restricted to entries from this host uuid. @@ -14605,6 +14615,7 @@ sub resync_databases my $column1 = $table."_uuid"; my $column2 = ""; my $column3 = ""; + my $column4 = ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { column1 => $column1 }}); if ($table =~ /^(.*)s$/) { @@ -14616,8 +14627,17 @@ sub resync_databases $column3 = $1."_uuid"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { column3 => $column3 }}); } + if ($table =~ /^(.*)ies$/) + { + $column4 = $1."y_uuid"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { column4 => $column4 }}); + } my $query = "SELECT column_name FROM information_schema.columns WHERE table_catalog = ".$anvil->Database->quote($anvil->data->{sys}{database}{name})." AND table_schema = 'public' AND table_name = ".$anvil->Database->quote($table)." AND data_type = 'uuid' AND is_nullable = 'NO' AND column_name = ".$anvil->Database->quote($column1).";"; - if ($column3) + if ($column4) + { + $query = "SELECT column_name FROM information_schema.columns WHERE table_catalog = ".$anvil->Database->quote($anvil->data->{sys}{database}{name})." AND table_schema = 'public' AND table_name = ".$anvil->Database->quote($table)." AND data_type = 'uuid' AND is_nullable = 'NO' AND (column_name = ".$anvil->Database->quote($column1)." OR column_name = ".$anvil->Database->quote($column2)." OR column_name = ".$anvil->Database->quote($column3)." OR column_name = ".$anvil->Database->quote($column4).");"; + } + elsif ($column3) { $query = "SELECT column_name FROM information_schema.columns WHERE table_catalog = ".$anvil->Database->quote($anvil->data->{sys}{database}{name})." AND table_schema = 'public' AND table_name = ".$anvil->Database->quote($table)." AND data_type = 'uuid' AND is_nullable = 'NO' AND (column_name = ".$anvil->Database->quote($column1)." OR column_name = ".$anvil->Database->quote($column2)." OR column_name = ".$anvil->Database->quote($column3).");"; } @@ -14629,7 +14649,12 @@ sub resync_databases my $uuid_column = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; $uuid_column = "" if not defined $uuid_column; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid_column => $uuid_column }}); - next if not $uuid_column; + if (not $uuid_column) + { + # This is a problem + print "Did not find the UUID column for the table: [".$table."]\n"; + die; + } # Get all the columns in this table. $query = "SELECT column_name, is_nullable, data_type FROM information_schema.columns WHERE table_schema = ".$anvil->Database->quote($schema)." AND table_name = ".$anvil->Database->quote($table)." AND column_name != 'history_id';"; @@ -15000,7 +15025,7 @@ sub resync_databases } } } # foreach my $table - + # We're done with the table data, clear it. delete $anvil->data->{sys}{database}{table}; @@ -15850,47 +15875,57 @@ ORDER BY "sys::database::table::${table}::uuid::${uuid}::last_updated" => $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}, "sys::database::table::${table}::uuid::${uuid}::row_count" => $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}, }}); - if ($anvil->data->{sys}{database}{table}{$table}{last_updated} > $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}) + ### TODO: Use locking to check for resync so things don't change during checks +# if ($anvil->data->{sys}{database}{table}{$table}{last_updated} > $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}) +# { +# ### NOTE: This triggers often with just a few seconds difference, which is +# ### more likely caused by one database doing reads, something changes, +# ### and the next database is read. As such, we won't trigger unless +# ### the difference is more than 10 seconds. +# # Resync needed. +# my $difference = $anvil->data->{sys}{database}{table}{$table}{last_updated} - $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}; +# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { +# "s1:difference" => $anvil->Convert->add_commas({number => $difference }), +# "s2:sys::database::table::${table}::last_updated" => $anvil->data->{sys}{database}{table}{$table}{last_updated}, +# "s3:sys::database::table::${table}::uuid::${uuid}::last_updated" => $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}, +# }}); +# if ($difference > 10) +# { +# $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0106", variables => { +# seconds => $difference, +# table => $table, +# uuid => $uuid, +# host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}), +# }}); +# +# # Mark it as behind. +# $anvil->Database->_mark_database_as_behind({debug => $debug, uuid => $uuid}); +# last; +# } +# } +# elsif ($anvil->data->{sys}{database}{table}{$table}{row_count} > $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}) + if ($anvil->data->{sys}{database}{table}{$table}{row_count} > $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}) { - ### NOTE: This triggers often with just a few seconds difference, which is - ### more likely caused by one database being reads, something changes, - ### and the next database is read. As such, we won't trigger unless - ### the difference is more than 10 seconds. # Resync needed. - my $difference = $anvil->data->{sys}{database}{table}{$table}{last_updated} - $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "s1:difference" => $anvil->Convert->add_commas({number => $difference }), - "s2:sys::database::table::${table}::last_updated" => $anvil->data->{sys}{database}{table}{$table}{last_updated}, - "s3:sys::database::table::${table}::uuid::${uuid}::last_updated" => $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}, + my $difference = $anvil->Convert->add_commas({number => ($anvil->data->{sys}{database}{table}{$table}{row_count} - $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}) }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "s1:difference" => $difference, + "s2:sys::database::table::${table}::row_count" => $anvil->data->{sys}{database}{table}{$table}{row_count}, + "s3:sys::database::table::${table}::uuid::${uuid}::row_count" => $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}, }}); + + # To avoid resyncs triggered by the differences that might occur if the row + # count changed slightly between counting both/all DBs, we won't resync + # until there's at least 10 rows different. if ($difference > 10) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0106", variables => { - seconds => $difference, + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0219", variables => { + missing => $difference, table => $table, uuid => $uuid, host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}), }}); - - # Mark it as behind. - $anvil->Database->_mark_database_as_behind({debug => $debug, uuid => $uuid}); - last; } - } - elsif ($anvil->data->{sys}{database}{table}{$table}{row_count} > $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}) - { - # Resync needed. - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "sys::database::table::${table}::row_count" => $anvil->data->{sys}{database}{table}{$table}{row_count}, - "sys::database::table::${table}::uuid::${uuid}::row_count" => $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}, - }}); - my $difference = $anvil->Convert->add_commas({number => ($anvil->data->{sys}{database}{table}{$table}{row_count} - $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{row_count}) }); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0219", variables => { - missing => $difference, - table => $table, - uuid => $uuid, - host => $anvil->Get->host_name_from_uuid({host_uuid => $uuid}), - }}); # Mark it as behind. $anvil->Database->_mark_database_as_behind({debug => $debug, uuid => $uuid}); diff --git a/Anvil/Tools/Log.pm b/Anvil/Tools/Log.pm index 40deb729..81eb7e80 100644 --- a/Anvil/Tools/Log.pm +++ b/Anvil/Tools/Log.pm @@ -372,6 +372,10 @@ sub entry $job_uuid =~ s/^(\w+?)-.*$/$1/; $string .= "[".$job_uuid."]:"; } + if (exists $anvil->data->{'log'}{scan_agent}) + { + $string .= "[".$anvil->data->{'log'}{scan_agent}."]:"; + } if (($source) && ($line)) { $string .= $source.":".$line."; "; diff --git a/Anvil/Tools/ScanCore.pm b/Anvil/Tools/ScanCore.pm index 3dd15294..91a84b80 100644 --- a/Anvil/Tools/ScanCore.pm +++ b/Anvil/Tools/ScanCore.pm @@ -120,6 +120,9 @@ sub agent_startup tables => $tables, }}); + # Setting this will prepend messages coming grom the agent with the agent's name + $anvil->data->{'log'}{scan_agent} = $agent; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { tables => $tables }}); if ((not $tables) or (ref($tables) ne "ARRAY")) { @@ -151,7 +154,10 @@ sub agent_startup } # Connect to DBs. - $anvil->Database->connect({debug => $debug}); + $anvil->Database->connect({ + debug => $debug, + no_resync => 0, + }); $anvil->Log->entry({source => $agent, line => __LINE__, level => $debug, secure => 0, key => "log_0132"}); if (not $anvil->data->{sys}{database}{connections}) { @@ -1521,7 +1527,7 @@ sub post_scan_analysis_node }}); # If we're SyncSource, we can't withdraw, but we can pull servers. - if (not $am_syncsource) + if ($am_syncsource) { # Log that we won't shutdown $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0105"}); diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index 132b64d4..4c20ba9c 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -1495,10 +1495,11 @@ sub collect_ipmi_data } # Record how long it took. - my $sensor_read_time = $anvil->Convert->time({'time' => (time - $read_start_time)}); + my $sensor_read_time = (time - $read_start_time); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { sensor_read_time => $sensor_read_time }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_ipmitool_log_0003", variables => { host_name => $host_name, - 'time' => $sensor_read_time + 'time' => $anvil->Convert->time({'time' => $sensor_read_time}), }}); diff --git a/notes b/notes index 071a9f1e..54e28b9b 100644 --- a/notes +++ b/notes @@ -998,6 +998,10 @@ OS10(conf-range-eth1/1/15-1/1/24)# exit 1.2 - Delete the resource +==================================== + +$body = $cgi->param('POSTDATA') # gives you the body of the request as a string, which you can then process as JSON + ==================================== @@ -1009,7 +1013,6 @@ OS10(conf-range-eth1/1/15-1/1/24)# exit ausearch -c 'drbdsetup' --raw | audit2allow -M my-drbdsetup && semodule -X 300 -i my-drbdsetup.pp - May 02 13:35:21 zo-a01n02.zennioptical.com setroubleshoot[5333]: SELinux is preventing /usr/sbin/drbdsetup from create access on the netlink_generic_socket labeled drbd_t. For complete SELinux messages run: sealert -l 4079c288-db4a-4f44-a588-94f1dbfff269 May 02 13:35:21 zo-a01n02.zennioptical.com setroubleshoot[5333]: SELinux is preventing /usr/sbin/drbdsetup from create access on the netlink_generic_socket labeled drbd_t. If you believe that drbdsetup should be allowed create access on netlink_generic_socket labeled drbd_t by default. diff --git a/tools/anvil-daemon b/tools/anvil-daemon index d2d9443e..f82a7c82 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -86,7 +86,7 @@ if (($< != 0) && ($> != 0)) # 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({check_if_configured => 1}); -$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0132"}); # If I have no databases, sleep for a second and then exit (systemd will restart us). if (not $anvil->data->{sys}{database}{connections}) @@ -95,24 +95,24 @@ if (not $anvil->data->{sys}{database}{connections}) # dashboard, then just go into a loop waiting for a database to be configured. if ($anvil->Get->host_type eq "striker") { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0201"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0201"}); prep_database($anvil); sleep 1; # Try connecting again $anvil->Database->connect(); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0132"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0132"}); if (not $anvil->data->{sys}{database}{connections}) { # Still nothing, sleep and exit. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0003"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0003"}); $anvil->nice_exit({exit_code => 2}); } } else { # Wait until we have one. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0075"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, key => "error_0075"}); until($anvil->data->{sys}{database}{connections}) { @@ -120,10 +120,10 @@ if (not $anvil->data->{sys}{database}{connections}) $anvil->refresh(); $anvil->Database->connect({debug => 3, check_if_configured => 1}); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0132"}); if (not $anvil->data->{sys}{database}{connections}) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 0, level => 3, secure => 0, key => "log_0439"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 0, level => 3, key => "log_0439"}); } } } @@ -137,7 +137,7 @@ $anvil->data->{switches}{'no-start'} = 0; $anvil->data->{switches}{'startup-only'} = 0; $anvil->Get->switches; -$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }}); +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0115", variables => { program => $THIS_FILE }}); if ($anvil->data->{switches}{'refresh-json'}) { @@ -178,7 +178,7 @@ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list # Disconnect. We'll reconnect inside the loop $anvil->Database->disconnect(); -$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0203"}); +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0203"}); # This will prevent restarting while jobs are running. $anvil->data->{sys}{jobs_running} = 0; @@ -193,7 +193,7 @@ while(1) # Reload defaults, re-read the config and then connect to the database(s) $anvil->refresh(); $anvil->Database->connect({check_if_configured => $check_if_database_is_configured}); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0132"}); # Mark that we don't want to check the database now. $check_if_database_is_configured = 0; @@ -216,7 +216,7 @@ while(1) # network mapped and the interface used to talk to the databases went down. That's all we # can do though. update_state_file($anvil); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "log_0202"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "log_0202"}); } # Exit if 'run-once' selected. @@ -1075,7 +1075,7 @@ sub run_jobs if ((not $job_picked_up_by) && ($job_progress ne "100") && (not $anvil->data->{switches}{'no-start'})) { my $command = $job_command." --job-uuid ".$job_uuid; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0210", variables => { command => $command }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0210", variables => { command => $command }}); # Have we started this job recently? if (exists $anvil->data->{jobs}{$job_uuid}{started}) @@ -1086,7 +1086,7 @@ sub run_jobs if ($last_start < 60) { # Skip, Started too recently. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0578", variables => { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0578", variables => { command => $command, last_start => $last_start, }}); @@ -1142,7 +1142,7 @@ sub update_state_file { my ($anvil) = @_; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0480"}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0480"}); my ($states_output, $return_code) = $anvil->System->call({debug => 3, shell_call => $anvil->data->{path}{exe}{'anvil-update-states'}." -v", source => $THIS_FILE, line => __LINE__}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { diff --git a/tools/scancore b/tools/scancore index 8e7b6121..b6c0c9b5 100755 --- a/tools/scancore +++ b/tools/scancore @@ -65,7 +65,7 @@ $anvil->Storage->read_config(); # Read switches $anvil->data->{switches}{'run-once'} = ""; $anvil->Get->switches; -$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0115", variables => { program => $THIS_FILE }}); +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0115", variables => { program => $THIS_FILE }}); # Calculate my sum so that we can exit if it changes later. $anvil->Storage->record_md5sums(); @@ -105,11 +105,8 @@ while(1) if ((exists $anvil->data->{scancore}{timing}{run_interval}) && ($anvil->data->{scancore}{timing}{run_interval} =~ /^\d+$/)) { $run_interval = $anvil->data->{scancore}{timing}{run_interval}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { run_interval => $run_interval }}); } - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0249", variables => { - run_interval => $run_interval, - runtime => (time - $start_time), - }}); # If we're in maintenance mode, do nothing. my $maintenance_mode = $anvil->System->maintenance_mode(); @@ -163,6 +160,10 @@ while(1) cleanup_after_run($anvil); # Sleep until it's time to run again. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0249", variables => { + run_interval => $run_interval, + runtime => (time - $start_time), + }}); sleep($run_interval); # In case something has changed, exit. From f833c311ba2ca2a19a2c24ca7ba89b881366111c Mon Sep 17 00:00:00 2001 From: Digimer Date: Sat, 8 May 2021 02:02:46 -0400 Subject: [PATCH 3/3] * To address issues with scancore debugging, we needed a tool to purge old anvils and hosts from the database. The 'test.pl' in this commit contains the new logic that will be merged into tools/striker-purge-host shortly. * Created Database->find_host_uuid_columns() and ->_find_column() to create a list of tables and column names in the proper order to allow deletion of foreign keys to that deeply nested primary keys can be deleted. Specifically, this was meant for hosts -> host_uuid and anvils -> anvil_uuid, though it should work for other tables. * Updated html/jquery-ui-1.12.1/package.json to address CVE-2020-7729 * Fixed a bug in the temperature table's history procedure where temperature_weight wasn't being copied. * Updated anvil-provision-server to support '--anvil' that can take either the anvil-uuid or anvil-name. * Updated anvil-safe-stop to default the stop-reason to 'user'. Signed-off-by: Digimer --- Anvil/Tools/Database.pm | 170 +++++++++++++++++++- Anvil/Tools/Words.pm | 15 ++ html/jquery-ui-1.12.1/package.json | 4 +- notes | 59 ++++++- scancore-agents/scan-ipmitool/scan-ipmitool | 9 +- share/anvil.sql | 2 + share/words.xml | 9 ++ tools/anvil-delete-server | 1 + tools/anvil-provision-server | 21 +++ tools/anvil-safe-stop | 6 + tools/striker-purge-host | 4 + 11 files changed, 293 insertions(+), 7 deletions(-) diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 5c41b07f..084bab68 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -23,6 +23,7 @@ my $THIS_FILE = "Database.pm"; # configure_pgsql # connect # disconnect +# find_host_uuid_columns # get_alerts # get_anvils # get_bridges @@ -91,6 +92,7 @@ my $THIS_FILE = "Database.pm"; # update_host_status # write # _archive_table +# _find_column # _find_behind_database # _mark_database_as_behind # _test_access @@ -1723,7 +1725,7 @@ sub connect # For now, we just find which DBs are behind and let each agent deal with bringing their tables up to # date. - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::connections" => $anvil->data->{sys}{database}{connections}, no_resync => $no_resync, }}); @@ -1828,6 +1830,102 @@ sub disconnect } +=head2 find_host_uuid_columns + +This looks through all ScanCore agent schemas, then all core tables and looks for tables with columns that end in C<< X_host_uuid >>. These are stored in an array, ordered such that you can delete records for a given host without deleting primary keys before all foreign keys are gone. + +The array is stored in C<< sys::database::uuid_tables >>. Each array entry will be hash references with C<< table >> and C<< host_uuid_column >> keys containing the table name, and the C<< X_host_uuid >> column. + + ### NOTE: Don't sort the array! It's ordered for safe deletions. + $anvil->Database->find_host_uuid_columns(); + foreach my $hash_ref (@{$anvil->data->{sys}{database}{uuid_tables}}) + { + my $table = $hash_ref->{table}; + my $host_uuid_column = $hash_ref->{host_uuid_column}; + print "Table: [".$table."], host UUID column: [".$host_uuid_column."]\n"; + } + +The array reference is returned. + +Parameters; + +=head3 main_table (optional, default 'hosts') + +This is the "parent" table, generally the top table with no further foreign keys above it. + +=head3 search_column (optional, default 'host_uuid') + +This is the UUID column used as a suffix in the parent table to search for. + +=cut +sub find_host_uuid_columns +{ + 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 => "Database->find_host_uuid_columns()" }}); + + my $main_table = defined $parameter->{main_table} ? $parameter->{main_table} : "hosts"; + my $search_column = defined $parameter->{search_column} ? $parameter->{search_column} : "host_uuid"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + main_table => $main_table, + search_column => $search_column, + }}); + + $anvil->data->{sys}{database}{uuid_tables} = []; + + $anvil->ScanCore->_scan_directory({ + debug => $debug, + directory => $anvil->data->{path}{directories}{scan_agents}, + }); + foreach my $agent_name (sort {$a cmp $b} keys %{$anvil->data->{scancore}{agent}}) + { + my $sql_path = $anvil->data->{scancore}{agent}{$agent_name}.".sql"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + agent_name => $agent_name, + sql_path => $sql_path, + }}); + if (not -e $sql_path) + { + next; + } + my $tables = $anvil->Database->get_tables_from_schema({ + debug => $debug, + schema_file => $sql_path, + }); + foreach my $table (reverse @{$tables}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { table => $table }}); + $anvil->Database->_find_column({ + debug => $debug, + table => $table, + search_column => $search_column, + }); + } + } + + my $tables = $anvil->Database->get_tables_from_schema({debug => $debug, schema_file => $anvil->data->{path}{sql}{'anvil.sql'}}); + foreach my $table (reverse @{$tables}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { table => $table }}); + $anvil->Database->_find_column({ + debug => $debug, + table => $table, + search_column => $search_column, + }); + } + + # Manually push 'hosts' + push @{$anvil->data->{sys}{database}{uuid_tables}}, { + table => $main_table, + host_uuid_column => $search_column, + }; + + return($anvil->data->{sys}{database}{uuid_tables}); +} + + =head2 get_alerts This reads in alerts from the C<< alerts >> table. @@ -4525,12 +4623,29 @@ sub get_tables_from_schema $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $line =~ s/--.*?//; - next if $line =~ /CREATE TABLE history\./; + if ($line =~ /CREATE TABLE history\.(.*?) \(/) + { + my $table = $1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { table => $table }}); + + $anvil->data->{sys}{database}{history_table}{$table} = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "sys::database::history_table::${table}" => $anvil->data->{sys}{database}{history_table}{$table}, + }}); + } if ($line =~ /CREATE TABLE (.*?) \(/i) { my $table = $1; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { table => $table }}); push @{$tables}, $table; + + if (not exists $anvil->data->{sys}{database}{history_table}{$table}) + { + $anvil->data->{sys}{database}{history_table}{$table} = 0; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "sys::database::history_table::${table}" => $anvil->data->{sys}{database}{history_table}{$table}, + }}); + } } } @@ -15621,6 +15736,57 @@ COPY history.".$table." ("; } +=head2 _find_column + +This takes a table name and looks for a column that ends in C<< _host_uuid >> and, if found, stores it in the C<< sys::database::uuid_tables >> array. + +Parameters; + +=head3 table (required) + +This is the table being queried. + +=cut +sub _find_column +{ + 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 => "Database->_find_column()" }}); + + my $table = defined $parameter->{table} ? $parameter->{table} : ""; + my $search_column = defined $parameter->{search_column} ? $parameter->{search_column} : ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + table => $table, + search_column => $search_column, + }}); + + return('!!error!!') if not $table; + + my $query = "SELECT column_name FROM information_schema.columns WHERE table_catalog = ".$anvil->Database->quote($anvil->data->{sys}{database}{name})." AND table_schema = 'public' AND table_name = ".$anvil->Database->quote($table)." AND data_type = 'uuid' AND is_nullable = 'NO' AND column_name LIKE '\%_".$search_column."';"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); + my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); + my $count = @{$results}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + table => $table, + count => $count, + }}); + if ($count) + { + my $host_uuid_column = $results->[0]->[0]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { host_uuid_column => $host_uuid_column }}); + + push @{$anvil->data->{sys}{database}{uuid_tables}}, { + table => $table, + host_uuid_column => $host_uuid_column, + }; + } + + return(0); +} + + =head2 _find_behind_databases This returns the most up to date database ID, the time it was last updated and an array or DB IDs that are behind. diff --git a/Anvil/Tools/Words.pm b/Anvil/Tools/Words.pm index 5c5710d3..adc38e2d 100644 --- a/Anvil/Tools/Words.pm +++ b/Anvil/Tools/Words.pm @@ -501,6 +501,21 @@ sub parse_banged_string "s3:value" => $value, }}); + # We've built things to support unit translation, though it's not implemented + # (yet). This clears those up. + if ($value =~ /^name=(.*?):units=(.*)$/) + { + my $name = $1; + my $unit = $2; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "s1:name" => $name, + "s2:unit" => $unit, + }}); + + $value = $name; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { value => $value }}); + } + # Remove this pair $variable_string =~ s/^\Q$pair//; $variable_string =~ s/^,//; diff --git a/html/jquery-ui-1.12.1/package.json b/html/jquery-ui-1.12.1/package.json index e3c846e3..97ecb89b 100644 --- a/html/jquery-ui-1.12.1/package.json +++ b/html/jquery-ui-1.12.1/package.json @@ -50,7 +50,9 @@ "scripts": { "test": "grunt" }, - "dependencies": {}, + "dependencies": { + "grunt": ">=1.3.0" + }, "devDependencies": { "commitplease": "2.3.0", "grunt": "0.4.5", diff --git a/notes b/notes index 54e28b9b..82041059 100644 --- a/notes +++ b/notes @@ -7,6 +7,15 @@ TODO: ============ +# Dump +su - postgres -c "pg_dump anvil > /tmp/anvil.out" && mv /tmp/anvil.out /root/ +su - postgres -c "pg_dump --schema-only anvil > /tmp/anvil.out" && mv /tmp/anvil.out /root/ + +cp /root/anvil.out /; su - postgres -c "dropdb anvil" && su - postgres -c "createdb --owner admin anvil" && su - postgres -c "psql anvil < /anvil.out" +su postgres -c "psql anvil" + +============ + # ScanCore post-scan logic; Sole node: @@ -761,17 +770,63 @@ resource srv01-sql { } ================== +1. Battery, short = -, add + / - to cell icon + + + mediawiki on EL8 install notes (starting from a minimal install); dnf module reset php dnf module enable php:7.4 -dnf install httpd php php-mysqlnd php-gd php-xml mariadb-server mariadb php-mbstring php-json \ - vim postgresql-server postgresql-plperl bash-completion wget tar rsync mlocate php-pecl-apcu \ +dnf install httpd php php-gd php-xml php-mbstring php-json \ + vim bash-completion wget tar rsync mlocate php-pecl-apcu \ memcached php-pear icu php-intl php-pgsql bzip2 +### PostgreSQL +dnf install postgresql-server postgresql-plperl postgresql-setup --initdb systemctl start postgresql.service systemctl enable postgresql.service + +### MariaDB +dnf install php-mysqlnd php-gd php-xml mariadb-server mariadb +systemctl start mariadb +mysql_secure_installation +|Set root password? [Y/n] y +|New password: +|Re-enter new password: +|Password updated successfully! +|Remove anonymous users? [Y/n] y +|Disallow root login remotely? [Y/n] y +|Remove test database and access to it? [Y/n] y +|Reload privilege tables now? [Y/n] y +mysql -u root -p +### In mariadb +MariaDB [(none)]> CREATE DATABASE digimer_wiki; +MariaDB [(none)]> CREATE USER 'digimer'@'localhost' IDENTIFIED BY 'Initial1'; +MariaDB [(none)]> GRANT ALL PRIVILEGES ON digimer_wiki.* TO 'digimer'@'localhost'; +MariaDB [(none)]> FLUSH PRIVILEGES; +MariaDB [(none)]> SHOW DATABASES; ++--------------------+ +| Database | ++--------------------+ +| digimer_wiki | +| information_schema | +| mysql | +| performance_schema | ++--------------------+ +MariaDB [(none)]> SHOW GRANTS FOR 'digimer'@'localhost'; ++----------------------------------------------------------------------------------------------------------------+ +| Grants for digimer@localhost | ++----------------------------------------------------------------------------------------------------------------+ +| GRANT USAGE ON *.* TO `digimer`@`localhost` IDENTIFIED BY PASSWORD '*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | +| GRANT ALL PRIVILEGES ON `digimer_wiki`.* TO `digimer`@`localhost` | ++----------------------------------------------------------------------------------------------------------------+ +MariaDB [(none)]> exit +# Back to terminal +systemctl enable mariadb + +# Common systemctl start httpd.service systemctl enable httpd.service systemctl start memcached.service diff --git a/scancore-agents/scan-ipmitool/scan-ipmitool b/scancore-agents/scan-ipmitool/scan-ipmitool index 75fc01c0..27adcf16 100755 --- a/scancore-agents/scan-ipmitool/scan-ipmitool +++ b/scancore-agents/scan-ipmitool/scan-ipmitool @@ -2061,8 +2061,14 @@ sub find_ipmi_targets } } + ### NOTE: This is changed. Now that striker's directly call the targets to check temperature when + ### evaluating thermal boot conditions, we don't need to store this data. + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ipmi_targets => $ipmi_targets }}); + return($ipmi_targets); + # Which hosts we scan depends on if we're a Striker dashboard or not. If we are, we'll try to scan # all machines in all Anvil! systems. Otherwise, we only scan ourselves. +=cut if ($host_type ne "striker") { # We're not a dashboard, so we don't scan others. @@ -2180,7 +2186,6 @@ AND }}); } } - - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ipmi_targets => $ipmi_targets }}); +=cut return($ipmi_targets); } diff --git a/share/anvil.sql b/share/anvil.sql index 49c563f0..b1d097ed 100644 --- a/share/anvil.sql +++ b/share/anvil.sql @@ -1897,6 +1897,7 @@ BEGIN temperature_sensor_host, temperature_sensor_name, temperature_value_c, + temperature_weight, temperature_state, temperature_is, modified_date) @@ -1906,6 +1907,7 @@ BEGIN history_temperature.temperature_agent_name, history_temperature.temperature_sensor_host, history_temperature.temperature_sensor_name, + history_temperature.temperature_weight, history_temperature.temperature_value_c, history_temperature.temperature_state, history_temperature.temperature_is, diff --git a/share/words.xml b/share/words.xml index 51876571..cc1bc381 100644 --- a/share/words.xml +++ b/share/words.xml @@ -413,6 +413,8 @@ The attempt to start the servers appears to have failed. The return code '0' was This host is not in a cluster, or it's in the cluster but not ready yet. Either way, unable to check the config. Failed to find the install manifest for the: [#!variable!anvil_name!#] Anvil! system. Unable to check or update the fence configuration. Failed to parse the install manifest with UUID: [#!variable!manifest_uuid!#]. Unable to check or update the fence configuration. + The passed in Anvil! UUID: [#!variable!anvil_uuid!#] was not found in the database. + The passed in host UUID: [#!variable!host_uuid!#] was not found in the database. @@ -1911,6 +1913,13 @@ Are you sure that you want to delete the server: [#!variable!server_name!#]? [Ty One or more servers are migrating. While this is the case, ScanCore post-scan checks are not performed. Preventative live migration has completed. Preventative live migration has been disabled. We're healthier than our peer, but we will take no action. + ' or '--host '.]]> + + Are you sure that you want to completely purge: [#!variable!host_name!#] (UUID: [#!variable!host_uuid!#] from the Anvil! database(s)? + Are you sure that you want to completely purge the Anvil!: [#!variable!anvil_name!#] (UUID: [#!variable!anvil_uuid!#] along with the machines: + - Host name: [#!variable!host_name!#] (host UUID: [#!variable!host_uuid!#]: + Now purging: [#!variable!host_name!#] (host UUID: [#!variable!host_uuid!#]: + Purging the Anvil!: [#!variable!anvil_name!#] (UUID: [#!variable!anvil_uuid!#]: Saved the mail server information successfully! diff --git a/tools/anvil-delete-server b/tools/anvil-delete-server index 6610ab0d..1bf9597a 100755 --- a/tools/anvil-delete-server +++ b/tools/anvil-delete-server @@ -179,6 +179,7 @@ sub run_jobs # Make sure the server is flagged as DELETEd. $anvil->Database->get_servers(); my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_state => $server_state }}); if ($server_state ne "DELETED") { my $query = " diff --git a/tools/anvil-provision-server b/tools/anvil-provision-server index 3c9e6403..d8b7b745 100755 --- a/tools/anvil-provision-server +++ b/tools/anvil-provision-server @@ -32,6 +32,7 @@ my $anvil = Anvil::Tools->new(); # Read switches (target ([user@]host[:port]) and the file with the target's password. If the password is # passed directly, it will be used. Otherwise, the password will be read from the database. +$anvil->data->{switches}{anvil} = ""; $anvil->data->{switches}{'anvil-name'} = ""; $anvil->data->{switches}{'anvil-uuid'} = ""; $anvil->data->{switches}{os} = ""; @@ -45,6 +46,7 @@ $anvil->data->{switches}{'storage-size'} = ""; $anvil->Get->switches; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'switches::anvil' => $anvil->data->{switches}{anvil}, 'switches::anvil-name' => $anvil->data->{switches}{'anvil-name'}, 'switches::anvil-uuid' => $anvil->data->{switches}{'anvil-uuid'}, 'switches::os' => $anvil->data->{switches}{os}, @@ -1445,6 +1447,25 @@ sub interactive_question { my ($anvil) = @_; + # If 'switches::anvil' is set, see if it's a UUID and then set either 'anvil-uuid' or 'anvil-name'. + if (($anvil->data->{switches}{anvil}) && (not $anvil->data->{switches}{'anvil-uuid'}) && (not $anvil->data->{switches}{'anvil-name'})) + { + if ($anvil->Validate->uuid({uuid => $anvil->data->{switches}{anvil}})) + { + $anvil->data->{switches}{'anvil-uuid'} = $anvil->data->{switches}{anvil}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "new_server::anvil_uuid" => $anvil->data->{new_server}{anvil_uuid}, + }}); + } + else + { + $anvil->data->{switches}{'anvil-name'} = $anvil->data->{switches}{anvil}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "new_server::anvil_name" => $anvil->data->{new_server}{anvil_name}, + }}); + } + } + # Do we know or can we find the Anvil! UUID? $anvil->data->{new_server}{anvil_uuid} = $anvil->data->{switches}{'anvil-uuid'} ? $anvil->data->{switches}{'anvil-uuid'} : ""; $anvil->data->{new_server}{anvil_name} = $anvil->data->{switches}{'anvil-name'} ? $anvil->data->{switches}{'anvil-name'} : ""; diff --git a/tools/anvil-safe-stop b/tools/anvil-safe-stop index 9972c072..bb3c0d30 100755 --- a/tools/anvil-safe-stop +++ b/tools/anvil-safe-stop @@ -117,6 +117,12 @@ if (not $anvil->data->{sys}{anvil_uuid}) $anvil->nice_exit({exit_code => 1}); } +# If no stop-reason was set, set it to 'user' +if (not $anvil->data->{switches}{'stop-reason'}) +{ + $anvil->data->{switches}{'stop-reason'} = "user"; +} + # Migrate or stop the servers, if any servers are running here. process_servers($anvil); diff --git a/tools/striker-purge-host b/tools/striker-purge-host index c3d44bde..5c2648c0 100755 --- a/tools/striker-purge-host +++ b/tools/striker-purge-host @@ -64,6 +64,10 @@ sub purge # hosts without any further references. As each delete is done, delete it. Loop until all entries are # gone. + + + die; + # Load all the known tables in the DB. my $query = "SELECT schemaname||'.'||tablename AS table_name FROM pg_catalog.pg_tables WHERE schemaname = 'history' ORDER BY tablename ASC, schemaname ASC;"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});