Merge pull request #85 from ClusterLabs/scancore-debugging

* Fixed a bug where the log message for a changed CIB wasn't useful.
main
digimer-bot 4 years ago committed by GitHub
commit 95159d4492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      Anvil/Tools/Convert.pm
  2. 273
      Anvil/Tools/Database.pm
  3. 4
      Anvil/Tools/Log.pm
  4. 10
      Anvil/Tools/ScanCore.pm
  5. 5
      Anvil/Tools/System.pm
  6. 15
      Anvil/Tools/Words.pm
  7. 4
      html/jquery-ui-1.12.1/package.json
  8. 64
      notes
  9. 14
      scancore-agents/scan-cluster/scan-cluster
  10. 5
      scancore-agents/scan-cluster/scan-cluster.xml
  11. 9
      scancore-agents/scan-ipmitool/scan-ipmitool
  12. 2
      share/anvil.sql
  13. 9
      share/words.xml
  14. 28
      tools/anvil-daemon
  15. 1
      tools/anvil-delete-server
  16. 21
      tools/anvil-provision-server
  17. 6
      tools/anvil-safe-stop
  18. 11
      tools/scancore
  19. 4
      tools/striker-purge-host

@ -1340,6 +1340,12 @@ sub time
translate => $translate, translate => $translate,
}}); }});
# If the 'time' is '--', return silently.
if ($time eq "--")
{
return("--");
}
# Remote commas and verify we're left with a number. # Remote commas and verify we're left with a number.
$time =~ s/,//g; $time =~ s/,//g;
if ($time =~ /^\d+\.\d+$/) if ($time =~ /^\d+\.\d+$/)

@ -23,6 +23,7 @@ my $THIS_FILE = "Database.pm";
# configure_pgsql # configure_pgsql
# connect # connect
# disconnect # disconnect
# find_host_uuid_columns
# get_alerts # get_alerts
# get_anvils # get_anvils
# get_bridges # get_bridges
@ -91,6 +92,7 @@ my $THIS_FILE = "Database.pm";
# update_host_status # update_host_status
# write # write
# _archive_table # _archive_table
# _find_column
# _find_behind_database # _find_behind_database
# _mark_database_as_behind # _mark_database_as_behind
# _test_access # _test_access
@ -1102,6 +1104,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::<uuid>::ping = 1 >> is set. If set to C<< 1 >>, no attempt to ping a target before connection will happen, even if C<< database::<uuid>::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) =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. 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 +1165,7 @@ sub connect
my $check_if_configured = defined $parameter->{check_if_configured} ? $parameter->{check_if_configured} : 0; 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 $db_uuid = defined $parameter->{db_uuid} ? $parameter->{db_uuid} : "";
my $no_ping = defined $parameter->{no_ping} ? $parameter->{no_ping} : 0; 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 $source = defined $parameter->{source} ? $parameter->{source} : "core";
my $sql_file = defined $parameter->{sql_file} ? $parameter->{sql_file} : $anvil->data->{path}{sql}{'anvil.sql'}; my $sql_file = defined $parameter->{sql_file} ? $parameter->{sql_file} : $anvil->data->{path}{sql}{'anvil.sql'};
my $tables = defined $parameter->{tables} ? $parameter->{tables} : ""; my $tables = defined $parameter->{tables} ? $parameter->{tables} : "";
@ -1167,6 +1174,7 @@ sub connect
check_if_configured => $check_if_configured, check_if_configured => $check_if_configured,
db_uuid => $db_uuid, db_uuid => $db_uuid,
no_ping => $no_ping, no_ping => $no_ping,
no_resync => $no_resync,
source => $source, source => $source,
sql_file => $sql_file, sql_file => $sql_file,
tables => $tables, tables => $tables,
@ -1717,8 +1725,11 @@ sub connect
# For now, we just find which DBs are behind and let each agent deal with bringing their tables up to # For now, we just find which DBs are behind and let each agent deal with bringing their tables up to
# date. # date.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::connections" => $anvil->data->{sys}{database}{connections} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
if ($anvil->data->{sys}{database}{connections} > 1) "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 # 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 # checking for a resync. This is done because the databases change constantly so tables like
@ -1819,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 =head2 get_alerts
This reads in alerts from the C<< alerts >> table. This reads in alerts from the C<< alerts >> table.
@ -4516,12 +4623,29 @@ sub get_tables_from_schema
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
$line =~ s/--.*?//; $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) if ($line =~ /CREATE TABLE (.*?) \(/i)
{ {
my $table = $1; my $table = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { table => $table }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { table => $table }});
push @{$tables}, $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},
}});
}
} }
} }
@ -14588,6 +14712,7 @@ sub resync_databases
# We don't sync 'states' as it's transient and sometimes per-DB. # We don't sync 'states' as it's transient and sometimes per-DB.
next if $table eq "states"; next if $table eq "states";
next if $table eq "oui"; 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 # 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. # column, the resync will be restricted to entries from this host uuid.
@ -14605,6 +14730,7 @@ sub resync_databases
my $column1 = $table."_uuid"; my $column1 = $table."_uuid";
my $column2 = ""; my $column2 = "";
my $column3 = ""; my $column3 = "";
my $column4 = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { column1 => $column1 }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { column1 => $column1 }});
if ($table =~ /^(.*)s$/) if ($table =~ /^(.*)s$/)
{ {
@ -14616,8 +14742,17 @@ sub resync_databases
$column3 = $1."_uuid"; $column3 = $1."_uuid";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { column3 => $column3 }}); $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).";"; 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).");"; $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 +14764,12 @@ sub resync_databases
my $uuid_column = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; my $uuid_column = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$uuid_column = "" if not defined $uuid_column; $uuid_column = "" if not defined $uuid_column;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid_column => $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. # 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';"; $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';";
@ -15596,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 =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. This returns the most up to date database ID, the time it was last updated and an array or DB IDs that are behind.
@ -15850,47 +16041,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}::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}, "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. # Resync needed.
my $difference = $anvil->data->{sys}{database}{table}{$table}{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 => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:difference" => $anvil->Convert->add_commas({number => $difference }), "s1:difference" => $difference,
"s2:sys::database::table::${table}::last_updated" => $anvil->data->{sys}{database}{table}{$table}{last_updated}, "s2:sys::database::table::${table}::row_count" => $anvil->data->{sys}{database}{table}{$table}{row_count},
"s3:sys::database::table::${table}::uuid::${uuid}::last_updated" => $anvil->data->{sys}{database}{table}{$table}{uuid}{$uuid}{last_updated}, "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) if ($difference > 10)
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0106", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "log_0219", variables => {
seconds => $difference, missing => $difference,
table => $table, table => $table,
uuid => $uuid, uuid => $uuid,
host => $anvil->Get->host_name_from_uuid({host_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. # Mark it as behind.
$anvil->Database->_mark_database_as_behind({debug => $debug, uuid => $uuid}); $anvil->Database->_mark_database_as_behind({debug => $debug, uuid => $uuid});

@ -372,6 +372,10 @@ sub entry
$job_uuid =~ s/^(\w+?)-.*$/$1/; $job_uuid =~ s/^(\w+?)-.*$/$1/;
$string .= "[".$job_uuid."]:"; $string .= "[".$job_uuid."]:";
} }
if (exists $anvil->data->{'log'}{scan_agent})
{
$string .= "[".$anvil->data->{'log'}{scan_agent}."]:";
}
if (($source) && ($line)) if (($source) && ($line))
{ {
$string .= $source.":".$line."; "; $string .= $source.":".$line."; ";

@ -120,6 +120,9 @@ sub agent_startup
tables => $tables, 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 }}); $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"))
{ {
@ -151,7 +154,10 @@ sub agent_startup
} }
# Connect to DBs. # 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"}); $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})
{ {
@ -1521,7 +1527,7 @@ sub post_scan_analysis_node
}}); }});
# If we're SyncSource, we can't withdraw, but we can pull servers. # 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 # Log that we won't shutdown
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0105"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0105"});

@ -1495,10 +1495,11 @@ sub collect_ipmi_data
} }
# Record how long it took. # 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 => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_ipmitool_log_0003", variables => {
host_name => $host_name, host_name => $host_name,
'time' => $sensor_read_time 'time' => $anvil->Convert->time({'time' => $sensor_read_time}),
}}); }});

@ -501,6 +501,21 @@ sub parse_banged_string
"s3:value" => $value, "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 # Remove this pair
$variable_string =~ s/^\Q$pair//; $variable_string =~ s/^\Q$pair//;
$variable_string =~ s/^,//; $variable_string =~ s/^,//;

@ -50,7 +50,9 @@
"scripts": { "scripts": {
"test": "grunt" "test": "grunt"
}, },
"dependencies": {}, "dependencies": {
"grunt": ">=1.3.0"
},
"devDependencies": { "devDependencies": {
"commitplease": "2.3.0", "commitplease": "2.3.0",
"grunt": "0.4.5", "grunt": "0.4.5",

64
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; # ScanCore post-scan logic;
Sole node: 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); mediawiki on EL8 install notes (starting from a minimal install);
dnf module reset php dnf module reset php
dnf module enable php:7.4 dnf module enable php:7.4
dnf install httpd php php-mysqlnd php-gd php-xml mariadb-server mariadb php-mbstring php-json \ dnf install httpd php php-gd php-xml php-mbstring php-json \
vim postgresql-server postgresql-plperl bash-completion wget tar rsync mlocate php-pecl-apcu \ vim bash-completion wget tar rsync mlocate php-pecl-apcu \
memcached php-pear icu php-intl php-pgsql bzip2 memcached php-pear icu php-intl php-pgsql bzip2
### PostgreSQL
dnf install postgresql-server postgresql-plperl
postgresql-setup --initdb postgresql-setup --initdb
systemctl start postgresql.service systemctl start postgresql.service
systemctl enable 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 start httpd.service
systemctl enable httpd.service systemctl enable httpd.service
systemctl start memcached.service systemctl start memcached.service
@ -998,6 +1053,10 @@ OS10(conf-range-eth1/1/15-1/1/24)# exit
1.2 - Delete the resource 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 +1068,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 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. 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. 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. If you believe that drbdsetup should be allowed create access on netlink_generic_socket labeled drbd_t by default.

@ -19,6 +19,7 @@ use strict;
use warnings; use warnings;
use Anvil::Tools; use Anvil::Tools;
use Data::Dumper; use Data::Dumper;
use Text::Diff;
# Disable buffering # Disable buffering
$| = 1; $| = 1;
@ -193,7 +194,7 @@ WHERE
UPDATE UPDATE
scan_cluster scan_cluster
SET 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})." modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE WHERE
scan_cluster_uuid = ".$anvil->Database->quote($scan_cluster_uuid)." 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->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $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 = { my $variables = {
new_cluster_name => $cluster_name, cluster_name => $cluster_name,
old_cluster_name => $old_cluster_name, difference => $difference,
}; };
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_cluster_alert_0002", variables => $variables}); $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_0002", variables => $variables, set_by => $THIS_FILE}); $anvil->Alert->register({debug => 2, alert_level => "notice", message => "scan_cluster_alert_0012", variables => $variables, set_by => $THIS_FILE});
} }
} }
else else

@ -32,6 +32,11 @@ In Maintenance Mode: ..... [#!variable!maintenance_mode!#]
<key name="scan_cluster_alert_0009">The node: [#!variable!old_node_name!#] has been renamed to: [#!variable!new_node_name!#]</key> <key name="scan_cluster_alert_0009">The node: [#!variable!old_node_name!#] has been renamed to: [#!variable!new_node_name!#]</key>
<key name="scan_cluster_alert_0010">The node: [#!variable!host_name!#] is no longer in the cluster.</key> <key name="scan_cluster_alert_0010">The node: [#!variable!host_name!#] is no longer in the cluster.</key>
<key name="scan_cluster_alert_0011">The node: [#!variable!host_name!#] is returning back into the cluster.</key> <key name="scan_cluster_alert_0011">The node: [#!variable!host_name!#] is returning back into the cluster.</key>
<key name="scan_cluster_alert_0012">The Cluster CIB for the cluster: [#!variable!cluster_name!#] has changed. The difference is:
====
#!variable!difference!#
====
</key>
<!-- Log entries --> <!-- Log entries -->
<key name="scan_cluster_log_0001">Starting: [#!variable!program!#].</key> <key name="scan_cluster_log_0001">Starting: [#!variable!program!#].</key>

@ -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 # 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. # all machines in all Anvil! systems. Otherwise, we only scan ourselves.
=cut
if ($host_type ne "striker") if ($host_type ne "striker")
{ {
# We're not a dashboard, so we don't scan others. # We're not a dashboard, so we don't scan others.
@ -2180,7 +2186,6 @@ AND
}}); }});
} }
} }
=cut
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ipmi_targets => $ipmi_targets }});
return($ipmi_targets); return($ipmi_targets);
} }

@ -1897,6 +1897,7 @@ BEGIN
temperature_sensor_host, temperature_sensor_host,
temperature_sensor_name, temperature_sensor_name,
temperature_value_c, temperature_value_c,
temperature_weight,
temperature_state, temperature_state,
temperature_is, temperature_is,
modified_date) modified_date)
@ -1906,6 +1907,7 @@ BEGIN
history_temperature.temperature_agent_name, history_temperature.temperature_agent_name,
history_temperature.temperature_sensor_host, history_temperature.temperature_sensor_host,
history_temperature.temperature_sensor_name, history_temperature.temperature_sensor_name,
history_temperature.temperature_weight,
history_temperature.temperature_value_c, history_temperature.temperature_value_c,
history_temperature.temperature_state, history_temperature.temperature_state,
history_temperature.temperature_is, history_temperature.temperature_is,

@ -413,6 +413,8 @@ The attempt to start the servers appears to have failed. The return code '0' was
<key name="error_0299">This host is not in a cluster, or it's in the cluster but not ready yet. Either way, unable to check the config.</key> <key name="error_0299">This host is not in a cluster, or it's in the cluster but not ready yet. Either way, unable to check the config.</key>
<key name="error_0300">Failed to find the install manifest for the: [#!variable!anvil_name!#] Anvil! system. Unable to check or update the fence configuration.</key> <key name="error_0300">Failed to find the install manifest for the: [#!variable!anvil_name!#] Anvil! system. Unable to check or update the fence configuration.</key>
<key name="error_0301">Failed to parse the install manifest with UUID: [#!variable!manifest_uuid!#]. Unable to check or update the fence configuration.</key> <key name="error_0301">Failed to parse the install manifest with UUID: [#!variable!manifest_uuid!#]. Unable to check or update the fence configuration.</key>
<key name="error_0302">The passed in Anvil! UUID: [#!variable!anvil_uuid!#] was not found in the database.</key>
<key name="error_0303">The passed in host UUID: [#!variable!host_uuid!#] was not found in the database.</key>
<!-- Files templates --> <!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which likes are translatable --> <!-- NOTE: Translating these files requires an understanding of which likes are translatable -->
@ -1911,6 +1913,13 @@ Are you sure that you want to delete the server: [#!variable!server_name!#]? [Ty
<key name="message_0237">One or more servers are migrating. While this is the case, ScanCore post-scan checks are not performed.</key> <key name="message_0237">One or more servers are migrating. While this is the case, ScanCore post-scan checks are not performed.</key>
<key name="message_0238">Preventative live migration has completed.</key> <key name="message_0238">Preventative live migration has completed.</key>
<key name="message_0239">Preventative live migration has been disabled. We're healthier than our peer, but we will take no action.</key> <key name="message_0239">Preventative live migration has been disabled. We're healthier than our peer, but we will take no action.</key>
<key name="message_0240"><![CDATA[Please specify the Anvil! or host you want to purge. Use '--anvil <name_or_uuid>' or '--host <name_or_uuid>'.]]></key>
<key name="message_0241"><![CDATA[Used '-y' or '--yes', proceeding automatically.]]></key>
<key name="message_0242">Are you sure that you want to completely purge: [#!variable!host_name!#] (UUID: [#!variable!host_uuid!#] from the Anvil! database(s)?</key>
<key name="message_0243">Are you sure that you want to completely purge the Anvil!: [#!variable!anvil_name!#] (UUID: [#!variable!anvil_uuid!#] along with the machines:</key>
<key name="message_0244">- Host name: [#!variable!host_name!#] (host UUID: [#!variable!host_uuid!#]:</key>
<key name="message_0245">Now purging: [#!variable!host_name!#] (host UUID: [#!variable!host_uuid!#]:</key>
<key name="message_0246">Purging the Anvil!: [#!variable!anvil_name!#] (UUID: [#!variable!anvil_uuid!#]:</key>
<!-- Success messages shown to the user --> <!-- Success messages shown to the user -->
<key name="ok_0001">Saved the mail server information successfully!</key> <key name="ok_0001">Saved the mail server information successfully!</key>

@ -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 # 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. # is to setup the database server.
$anvil->Database->connect({check_if_configured => 1}); $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 I have no databases, sleep for a second and then exit (systemd will restart us).
if (not $anvil->data->{sys}{database}{connections}) 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. # dashboard, then just go into a loop waiting for a database to be configured.
if ($anvil->Get->host_type eq "striker") 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); prep_database($anvil);
sleep 1; sleep 1;
# Try connecting again # Try connecting again
$anvil->Database->connect(); $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}) if (not $anvil->data->{sys}{database}{connections})
{ {
# Still nothing, sleep and exit. # 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}); $anvil->nice_exit({exit_code => 2});
} }
} }
else else
{ {
# Wait until we have one. # 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}) until($anvil->data->{sys}{database}{connections})
{ {
@ -120,10 +120,10 @@ if (not $anvil->data->{sys}{database}{connections})
$anvil->refresh(); $anvil->refresh();
$anvil->Database->connect({debug => 3, check_if_configured => 1}); $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}) 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->data->{switches}{'startup-only'} = 0;
$anvil->Get->switches; $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'}) 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 # Disconnect. We'll reconnect inside the loop
$anvil->Database->disconnect(); $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. # This will prevent restarting while jobs are running.
$anvil->data->{sys}{jobs_running} = 0; $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) # Reload defaults, re-read the config and then connect to the database(s)
$anvil->refresh(); $anvil->refresh();
$anvil->Database->connect({check_if_configured => $check_if_database_is_configured}); $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. # Mark that we don't want to check the database now.
$check_if_database_is_configured = 0; $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 # network mapped and the interface used to talk to the databases went down. That's all we
# can do though. # can do though.
update_state_file($anvil); 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. # 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'})) if ((not $job_picked_up_by) && ($job_progress ne "100") && (not $anvil->data->{switches}{'no-start'}))
{ {
my $command = $job_command." --job-uuid ".$job_uuid; 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? # Have we started this job recently?
if (exists $anvil->data->{jobs}{$job_uuid}{started}) if (exists $anvil->data->{jobs}{$job_uuid}{started})
@ -1086,7 +1086,7 @@ sub run_jobs
if ($last_start < 60) if ($last_start < 60)
{ {
# Skip, Started too recently. # 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, command => $command,
last_start => $last_start, last_start => $last_start,
}}); }});
@ -1142,7 +1142,7 @@ sub update_state_file
{ {
my ($anvil) = @_; 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__}); 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 => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {

@ -179,6 +179,7 @@ sub run_jobs
# Make sure the server is flagged as DELETEd. # Make sure the server is flagged as DELETEd.
$anvil->Database->get_servers(); $anvil->Database->get_servers();
my $server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state}; 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") if ($server_state ne "DELETED")
{ {
my $query = " my $query = "

@ -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 # 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. # 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-name'} = "";
$anvil->data->{switches}{'anvil-uuid'} = ""; $anvil->data->{switches}{'anvil-uuid'} = "";
$anvil->data->{switches}{os} = ""; $anvil->data->{switches}{os} = "";
@ -45,6 +46,7 @@ $anvil->data->{switches}{'storage-size'} = "";
$anvil->Get->switches; $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->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 => { $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-name' => $anvil->data->{switches}{'anvil-name'},
'switches::anvil-uuid' => $anvil->data->{switches}{'anvil-uuid'}, 'switches::anvil-uuid' => $anvil->data->{switches}{'anvil-uuid'},
'switches::os' => $anvil->data->{switches}{os}, 'switches::os' => $anvil->data->{switches}{os},
@ -1445,6 +1447,25 @@ sub interactive_question
{ {
my ($anvil) = @_; 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? # 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_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'} : ""; $anvil->data->{new_server}{anvil_name} = $anvil->data->{switches}{'anvil-name'} ? $anvil->data->{switches}{'anvil-name'} : "";

@ -117,6 +117,12 @@ if (not $anvil->data->{sys}{anvil_uuid})
$anvil->nice_exit({exit_code => 1}); $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. # Migrate or stop the servers, if any servers are running here.
process_servers($anvil); process_servers($anvil);

@ -65,7 +65,7 @@ $anvil->Storage->read_config();
# Read switches # Read switches
$anvil->data->{switches}{'run-once'} = ""; $anvil->data->{switches}{'run-once'} = "";
$anvil->Get->switches; $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. # Calculate my sum so that we can exit if it changes later.
$anvil->Storage->record_md5sums(); $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+$/)) if ((exists $anvil->data->{scancore}{timing}{run_interval}) && ($anvil->data->{scancore}{timing}{run_interval} =~ /^\d+$/))
{ {
$run_interval = $anvil->data->{scancore}{timing}{run_interval}; $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. # If we're in maintenance mode, do nothing.
my $maintenance_mode = $anvil->System->maintenance_mode(); my $maintenance_mode = $anvil->System->maintenance_mode();
@ -163,6 +160,10 @@ while(1)
cleanup_after_run($anvil); cleanup_after_run($anvil);
# Sleep until it's time to run again. # 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); sleep($run_interval);
# In case something has changed, exit. # In case something has changed, exit.

@ -64,6 +64,10 @@ sub purge
# hosts without any further references. As each delete is done, delete it. Loop until all entries are # hosts without any further references. As each delete is done, delete it. Loop until all entries are
# gone. # gone.
die;
# Load all the known tables in the DB. # 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;"; 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 }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});

Loading…
Cancel
Save