* Switched out the static list of core table to use the array generated by Database->get_tables_from_schema().

* Fixed bugs around creating and filtering storage groups.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent 4f33eeef2e
commit 8f823d3b86
  1. 40
      Anvil/Tools.pm
  2. 41
      Anvil/Tools/Database.pm
  3. 30
      Anvil/Tools/Get.pm
  4. 2
      Anvil/Tools/Log.pm
  5. 2
      scancore-agents/scan-server/scan-server.xml
  6. 8
      share/anvil.sql
  7. 5
      tools/test.pl

@ -267,6 +267,9 @@ sub new
# Read in any command line switches. # Read in any command line switches.
$anvil->Get->switches({debug => $debug}); $anvil->Get->switches({debug => $debug});
# Populate the core_tables array reference from the main anvil.sql file.
$anvil->data->{sys}{database}{core_tables} = $anvil->Database->get_tables_from_schema({schema_file => $anvil->data->{path}{sql}{'anvil.sql'}});
# Read in the local Anvil! version. # Read in the local Anvil! version.
#... #...
@ -862,43 +865,6 @@ sub _set_defaults
trigger => 100000, trigger => 100000,
}, },
connections => 0, connections => 0,
### WARNING: The order the tables are resync'ed is important! Any table that has a
### foreign key needs to resync *AFTER* the tables with the primary keys.
# NOTE: Check that this list is complete with;
# grep 'CREATE TABLE' share/anvil.sql | grep -v history. | awk '{print $3}'
core_tables => [
"hosts", # Always has to be first.
"health",
"power",
"temperature",
"ssh_keys",
"users",
"host_variable",
"sessions", # Has to come after users and hosts
"anvils",
"alerts",
"recipients",
"notifications",
"mail_servers",
"variables",
"jobs",
"bridges",
"bonds",
"network_interfaces",
"ip_addresses",
"files",
"file_locations",
"servers",
"definitions",
"oui",
"mac_to_ip",
"updated",
"alert_sent",
"states",
"manifests",
"fences",
"upses",
],
failed_connection_log_level => 1, failed_connection_log_level => 1,
local_lock_active => 0, local_lock_active => 0,
local_uuid => "", local_uuid => "",

@ -10973,14 +10973,13 @@ AND
else else
{ {
my $vg_group_number = 0; my $vg_group_number = 0;
my $storage_group_name = "";
until ($storage_group_name) until ($storage_group_name)
{ {
$vg_group_number++; $vg_group_number++;
my $test_name = $anvil->Words->string({debug => $debug, key => "striker_0280", variables => { number => $vg_group_number }}); my $test_name = $anvil->Words->string({debug => $debug, key => "striker_0280", variables => { number => $vg_group_number }});
my $query = " my $query = "
SELECT SELECT
COUNT(*) storage_group_uuid
FROM FROM
storage_groups storage_groups
WHERE WHERE
@ -10988,9 +10987,41 @@ WHERE
AND AND
storage_group_name = ".$anvil->Database->quote($test_name)." storage_group_name = ".$anvil->Database->quote($test_name)."
;"; ;";
my $count = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { count => $count }}); my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count)
{
# Are there any members of this group? If not, we'll use it.
my $storage_group_uuid = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { storage_group_uuid => $storage_group_uuid }});
my $query = "
SELECT
COUNT(*)
FROM
storage_group_members
WHERE
storage_group_member_storage_group_uuid = ".$anvil->Database->quote($storage_group_uuid)."
;";
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if (not $count)
{
# No members yet, and it's an auto-generated
$storage_group_name = $test_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { storage_group_name => $storage_group_name }});
}
}
if (not $count) if (not $count)
{ {
# We can use this name. # We can use this name.
@ -11221,7 +11252,7 @@ INSERT INTO
".$anvil->Database->quote($storage_group_member_host_uuid).", ".$anvil->Database->quote($storage_group_member_host_uuid).",
".$anvil->Database->quote($storage_group_member_vg_uuid).", ".$anvil->Database->quote($storage_group_member_vg_uuid).",
".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})." ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
};"; );";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__}); $anvil->Database->write({uuid => $uuid, query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
} }

@ -332,6 +332,9 @@ sub available_resources
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Get->available_resources()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Get->available_resources()" }});
my $anvil_uuid = defined $parameter->{anvil_uuid} ? $parameter->{anvil_uuid} : ""; my $anvil_uuid = defined $parameter->{anvil_uuid} ? $parameter->{anvil_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
anvil_uuid=> $anvil_uuid,
}});
if (not $anvil_uuid) if (not $anvil_uuid)
{ {
@ -377,21 +380,6 @@ WHERE
dr1_host_uuid => $dr1_host_uuid, dr1_host_uuid => $dr1_host_uuid,
}}); }});
# Make sure scancore has run. We do this by looking for the 'scan_lvm_vg_groups' table.
undef $query;
undef $count;
$query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename='scan_lvm_vg_groups' AND schemaname='public';";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$count = $anvil->Database->query({debug => $debug, query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { count => $count }});
if ($count < 1)
{
# Not ready yes.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "warning_0070", variables => { anvil_name => $anvil_name }});
return('!!error!!');
}
# Load hosts, Network bridge, and Storages group data # Load hosts, Network bridge, and Storages group data
$anvil->Database->get_hosts({debug => $debug}); $anvil->Database->get_hosts({debug => $debug});
$anvil->Database->get_bridges({debug => $debug}); $anvil->Database->get_bridges({debug => $debug});
@ -470,14 +458,16 @@ ORDER BY
$anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_uuid} = $row->[0]; $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_uuid} = $row->[0];
$anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_name} = $row->[1]; $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_name} = $row->[1];
$anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_extent_size} = $row->[2]; $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_extent_size} = $row->[2];
$anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_free} = $row->[3]; $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_size} = $row->[3];
$anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_internal_uuid} = $row->[4]; $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_free} = $row->[4];
$anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_internal_uuid} = $row->[5];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"ungrouped_vg_count::${this_is}" => $anvil->data->{ungrouped_vg_count}{$this_is}, "ungrouped_vg_count::${this_is}" => $anvil->data->{ungrouped_vg_count}{$this_is},
"ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::count" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{count}, "ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::count" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{count},
"ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_uuid" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_uuid}, "ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_uuid" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_uuid},
"ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_name" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_name}, "ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_name" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_name},
"ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_extent_size" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_extent_size}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_extent_size}}).")", "ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_extent_size" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_extent_size}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_extent_size}}).")",
"ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_size" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_size}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_size}}).")",
"ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_free" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_free}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_free}}).")", "ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_free" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_free}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_free}}).")",
"ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_internal_uuid" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_internal_uuid}, "ungrouped_vgs::${scan_lvm_vg_size}::host_uuid::${host_uuid}::vg_internal_uuid" => $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_internal_uuid},
}}); }});
@ -493,7 +483,7 @@ ORDER BY
if (($count == 2) or ($count == 3)) if (($count == 2) or ($count == 3))
{ {
# Create the volume group ... group. First we need a group number # Create the volume group ... group. First we need a group number
my $storage_group_uuid = $anvil->Database->create_storage_group({ my $storage_group_uuid = $anvil->Database->insert_or_update_storage_groups({
debug => $debug, debug => $debug,
storage_group_anvil_uuid => $anvil_uuid, storage_group_anvil_uuid => $anvil_uuid,
}); });
@ -507,7 +497,9 @@ ORDER BY
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { this_is => $this_is }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { this_is => $this_is }});
my $storage_group_member_vg_uuid = $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_internal_uuid}; my $storage_group_member_vg_uuid = $anvil->data->{ungrouped_vgs}{$scan_lvm_vg_size}{host_uuid}{$host_uuid}{vg_internal_uuid};
my $storage_group_member_uuid = $anvil->Database->insert_or_update_storage_group_members({ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { storage_group_member_vg_uuid => $storage_group_member_vg_uuid }});
my $storage_group_member_uuid = $anvil->Database->insert_or_update_storage_group_members({
debug => $debug, debug => $debug,
storage_group_member_storage_group_uuid => $storage_group_uuid, storage_group_member_storage_group_uuid => $storage_group_uuid,
storage_group_member_host_uuid => $host_uuid, storage_group_member_host_uuid => $host_uuid,

@ -984,7 +984,7 @@ sub _adjust_log_level
{ {
$anvil->Log->secure({set => 1}); $anvil->Log->secure({set => 1});
} }
if ($anvil->data->{switches}{'log-db'}) if (($anvil->data->{switches}{'log-db'}) or ($anvil->data->{switches}{'log-db-transactions'}))
{ {
$anvil->data->{sys}{database}{log_transactions} = 1; $anvil->data->{sys}{database}{log_transactions} = 1;
} }

@ -59,7 +59,7 @@ The definition for the server: [#!variable!server!#] was edited outside of the A
==[ Database ]======== ==[ Database ]========
#!variable!db_difference!# #!variable!db_difference!#
==[ New Definition ]== ==[ New Definition ]==
#!variable!new_difference!# #!variable!new_definition!#
====================== ======================
</key> </key>
<key name="scan_server_alert_0004">The name of the server: [#!variable!old_name!#] has changed to: [#!variable!new_name!#]</key> <key name="scan_server_alert_0004">The name of the server: [#!variable!old_name!#] has changed to: [#!variable!new_name!#]</key>

@ -1694,20 +1694,20 @@ CREATE TRIGGER trigger_storage_groups
-- This links specific VGs with a give storage group -- This links specific VGs with a give storage group
CREATE TABLE storage_group_members ( CREATE TABLE storage_group_members (
storage_group_member_uuid uuid not null primary key, storage_group_member_uuid uuid not null primary key,
storage_group_member_storage_group_uuid uuid storage_group_member_storage_group_uuid uuid not null,
storage_group_member_host_uuid uuid not null, -- The host this VG comes from. storage_group_member_host_uuid uuid not null, -- The host this VG comes from.
storage_group_member_vg_uuid text not null, -- This is the VG's internal "uuid". It's not a valid UUID string format, but it's what LVM calls a 'uuid'. storage_group_member_vg_uuid text not null, -- This is the VG's internal "uuid". It's not a valid UUID string format, but it's what LVM calls a 'uuid'.
modified_date timestamp with time zone not null, modified_date timestamp with time zone not null,
FOREIGN KEY(storage_group_member_storage_group_uuid) REFERENCES storage_groups(storage_group_uuid) FOREIGN KEY(storage_group_member_storage_group_uuid) REFERENCES storage_groups(storage_group_uuid),
FOREIGN KEY(storage_group_member_anvil_uuid) REFERENCES anvils(anvil_uuid) FOREIGN KEY(storage_group_member_host_uuid) REFERENCES hosts(host_uuid)
); );
ALTER TABLE storage_group_members OWNER TO admin; ALTER TABLE storage_group_members OWNER TO admin;
CREATE TABLE history.storage_group_members ( CREATE TABLE history.storage_group_members (
history_id bigserial, history_id bigserial,
storage_group_member_uuid uuid, storage_group_member_uuid uuid,
storage_group_member_storage_group_uuid uuid storage_group_member_storage_group_uuid uuid,
storage_group_member_host_uuid uuid, storage_group_member_host_uuid uuid,
storage_group_member_vg_uuid text, storage_group_member_vg_uuid text,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null

@ -26,7 +26,10 @@ $anvil->Get->switches;
$anvil->Database->connect; $anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0132"});
$anvil->Words->load_agent_strings({debug => 2}); $anvil->Get->available_resources({
debug => 2,
anvil_uuid => '2ac4dbcb-25d2-44b2-ae07-59707b0551ca',
});
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});

Loading…
Cancel
Save