Created 'striker-db-status' that reports the status of the databases to external tools. It's basic, but it works.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent 3fd0db15bf
commit 513ce3b74e
  1. 26
      Anvil/Tools/Database.pm
  2. 62
      tools/striker-db-status

@ -1498,6 +1498,11 @@ sub connect
} }
} }
# This stores data used by striker-db-status
$anvil->data->{db_status}{$uuid}{access} = 0;
$anvil->data->{db_status}{$uuid}{active} = 0;
$anvil->data->{db_status}{$uuid}{details} = "";
# Connect! # Connect!
my $dbh = ""; my $dbh = "";
### NOTE: The Database->write() method, when passed an array, will automatically disable ### NOTE: The Database->write() method, when passed an array, will automatically disable
@ -1529,6 +1534,11 @@ sub connect
name => $name, name => $name,
}}); }});
$anvil->data->{db_status}{$uuid}{details} = "error=".$@;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"db_status::${uuid}::details" => $anvil->data->{db_status}{$uuid}{details},
}});
push @{$failed_connections}, $uuid; push @{$failed_connections}, $uuid;
my $message_key = "log_0065"; my $message_key = "log_0065";
my $variables = { dbi_error => $DBI::errstr }; my $variables = { dbi_error => $DBI::errstr };
@ -1588,6 +1598,11 @@ sub connect
"cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid}, "cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid},
}}); }});
$anvil->data->{db_status}{$uuid}{access} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"db_status::${uuid}::access" => $anvil->data->{db_status}{$uuid}{access},
}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0071", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0071", variables => {
host => $host, host => $host,
port => $port, port => $port,
@ -1691,6 +1706,11 @@ sub connect
variable_source_uuid => "NULL", variable_source_uuid => "NULL",
variable_source_table => "", variable_source_table => "",
}); });
$anvil->data->{db_status}{$uuid}{active} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"db_status::${uuid}::active" => $anvil->data->{db_status}{$uuid}{active},
}});
} }
else else
{ {
@ -1708,6 +1728,12 @@ sub connect
} }
} }
# Still here? We're active
$anvil->data->{db_status}{$uuid}{active} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"db_status::${uuid}::active" => $anvil->data->{db_status}{$uuid}{active},
}});
# Set the first ID to be the one I read from later. Alternatively, if this host is # Set the first ID to be the one I read from later. Alternatively, if this host is
# local, use it. # local, use it.
if (($is_local) or (not $anvil->data->{sys}{database}{read_uuid})) if (($is_local) or (not $anvil->data->{sys}{database}{read_uuid}))

@ -0,0 +1,62 @@
#!/usr/bin/perl
#
# This is a machine parsable output of the database states.
#
use strict;
use warnings;
use Anvil::Tools;
use Data::Dumper;
use Text::Diff;
$| = 1;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
if (($running_directory =~ /^\./) && ($ENV{PWD}))
{
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new();
$anvil->Database->connect({debug => 2, check_for_resync => 0});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"});
$anvil->nice_exit({exit_code => 1});
}
$anvil->Get->switches();
print "# Access = talked to DB. Active = flagged as active and usable.\n";
print "connections=".$anvil->data->{sys}{database}{connections}."\n";
if ($anvil->data->{sys}{database}{connections})
{
foreach my $uuid (keys %{$anvil->data->{db_status}})
{
my $host_name = $anvil->Get->host_name_from_uuid({host_uuid => $uuid});
$host_name = "<unknown>" if not $host_name;
my $access = $anvil->data->{db_status}{$uuid}{access};
my $active = $anvil->data->{db_status}{$uuid}{active};
my $details = $anvil->data->{db_status}{$uuid}{details};
# Show the state
print "host_name=".$host_name.",host_uuid=".$uuid.",access=".$access.",active=".$active."\n";
# If we want to show access failure details;
# print "host_name=".$host_name.",host_uuid=".$uuid.",access=".$access.",active=".$active;
# if (not $access)
# {
# print ",details:\n";
# print "====\n";
# print $details;
# print "====";
# }
# print "\n";
}
}
$anvil->nice_exit({exit_code => 0});
Loading…
Cancel
Save