* Changed tabs to white-spaces in the SQL source to make copy/pasting easier.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent f1bd4b99ca
commit 4e30f2024c
  1. 17
      tools/anvil-prep-database
  2. 102
      tools/anvil.sql

@ -87,7 +87,7 @@ if ($local_id)
# Setup postgresql.conf # Setup postgresql.conf
my $postgresql_backup = $anvil->data->{path}{directories}{backups}."/pgsql/postgresql.conf"; my $postgresql_backup = $anvil->data->{path}{directories}{backups}."/pgsql/postgresql.conf";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { postgresql_backup => $postgresql_backup }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { postgresql_backup => $postgresql_backup }});
$anvil->Storage->copy_file({source => $anvil->data->{path}{configs}{'postgresql.conf'}, target => $postgresql_backup}); $anvil->Storage->copy_file({source => $anvil->data->{path}{configs}{'postgresql.conf'}, target => $postgresql_backup});
my $postgresql_conf = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'postgresql.conf'}}); my $postgresql_conf = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'postgresql.conf'}});
@ -95,7 +95,7 @@ if ($local_id)
my $new_postgresql_conf = ""; my $new_postgresql_conf = "";
foreach my $line (split/\n/, $postgresql_conf) foreach my $line (split/\n/, $postgresql_conf)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /^listen_addresses = '\*'/) if ($line =~ /^listen_addresses = '\*'/)
{ {
# No need to update. # No need to update.
@ -109,7 +109,7 @@ if ($local_id)
} }
$new_postgresql_conf .= $line."\n"; $new_postgresql_conf .= $line."\n";
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { update_file => $update_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update_file => $update_file }});
if ($update_file) if ($update_file)
{ {
$anvil->Storage->write_file({ $anvil->Storage->write_file({
@ -125,7 +125,7 @@ if ($local_id)
# Setup pg_hba.conf now # Setup pg_hba.conf now
my $pg_hba_backup = $anvil->data->{path}{directories}{backups}."/pgsql/pg_hba.conf"; my $pg_hba_backup = $anvil->data->{path}{directories}{backups}."/pgsql/pg_hba.conf";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { pg_hba_backup => $pg_hba_backup }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { pg_hba_backup => $pg_hba_backup }});
$anvil->Storage->copy_file({source => $anvil->data->{path}{configs}{'pg_hba.conf'}, target => $pg_hba_backup}); $anvil->Storage->copy_file({source => $anvil->data->{path}{configs}{'pg_hba.conf'}, target => $pg_hba_backup});
my $pg_hba_conf = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'pg_hba.conf'}}); my $pg_hba_conf = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'pg_hba.conf'}});
@ -133,25 +133,26 @@ if ($local_id)
my $new_pg_hba_conf = ""; my $new_pg_hba_conf = "";
foreach my $line (split/\n/, $pg_hba_conf) foreach my $line (split/\n/, $pg_hba_conf)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /^host\s+all\s+all\s+\all\s+md5$/) if ($line =~ /^host\s+all\s+all\s+\all\s+md5$/)
{ {
# No need to update. # No need to update.
$update_file = 0; $update_file = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update_file => $update_file }});
last; last;
} }
elsif ($line =~ /^# TYPE\s+DATABASE/) elsif ($line =~ /^# TYPE\s+DATABASE/)
{ {
# Inject the new listen_addresses # Inject the new listen_addresses
$new_pg_hba_conf .= $line."\n"; $new_pg_hba_conf .= $line."\n";
$new_pg_hba_conf .= "host\tall\t\tall\t\t*\t\t\tmd5\n"; $new_pg_hba_conf .= "host\tall\t\tall\t\tall\t\t\tmd5\n";
} }
else else
{ {
$new_pg_hba_conf .= $line."\n"; $new_pg_hba_conf .= $line."\n";
} }
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { update_file => $update_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update_file => $update_file }});
if ($update_file) if ($update_file)
{ {
$anvil->Storage->write_file({ $anvil->Storage->write_file({
@ -162,7 +163,7 @@ if ($local_id)
mode => "0600", mode => "0600",
overwrite => 1, overwrite => 1,
}); });
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0057", variables => { file => $anvil->data->{path}{configs}{'postgresql.conf'} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0057", variables => { file => $anvil->data->{path}{configs}{'pg_hba.conf'} }});
} }
} }

@ -135,7 +135,7 @@ CREATE TRIGGER trigger_host_variable
-- This stores alerts coming in from various sources -- This stores alerts coming in from various sources
CREATE TABLE alerts ( CREATE TABLE alerts (
alert_uuid uuid primary key, alert_uuid uuid not null primary key,
alert_host_uuid uuid not null, -- The name of the node or dashboard that this alert came from. alert_host_uuid uuid not null, -- The name of the node or dashboard that this alert came from.
alert_set_by text not null, alert_set_by text not null,
alert_level text not null, -- debug (log only), info (+ admin email), notice (+ curious users), warning (+ client technical staff), critical (+ all) alert_level text not null, -- debug (log only), info (+ admin email), notice (+ curious users), warning (+ client technical staff), critical (+ all)
@ -210,7 +210,7 @@ CREATE TRIGGER trigger_alerts
-- This holds user-configurable variable. These values override defaults but NOT configuration files. -- This holds user-configurable variable. These values override defaults but NOT configuration files.
CREATE TABLE variables ( CREATE TABLE variables (
variable_uuid uuid not null primary key, -- variable_uuid uuid not null primary key,
variable_name text not null, -- This is the 'x::y::z' style variable name. variable_name text not null, -- This is the 'x::y::z' style variable name.
variable_value text, -- It is up to the software to sanity check variable values before they are stored variable_value text, -- It is up to the software to sanity check variable values before they are stored
variable_default text, -- This acts as a reference for the user should they want to roll-back changes. variable_default text, -- This acts as a reference for the user should they want to roll-back changes.
@ -335,53 +335,6 @@ CREATE TRIGGER trigger_jobs
AFTER INSERT OR UPDATE ON jobs AFTER INSERT OR UPDATE ON jobs
FOR EACH ROW EXECUTE PROCEDURE history_jobs(); FOR EACH ROW EXECUTE PROCEDURE history_jobs();
-- ------------------------------------------------------------------------------------------------------- --
-- These are special tables with no history or tracking UUIDs that simply record transient information. --
-- ------------------------------------------------------------------------------------------------------- --
-- This table records the last time a scan ran. It's sole purpose is to make sure at least one table's
-- 'modified_date' changes per run, so that database resyncs can be triggered reliably.
CREATE TABLE updated (
updated_host_uuid uuid not null,
updated_by text not null, -- The name of the agent (or "ScanCore' itself) that updated.
modified_date timestamp with time zone not null,
FOREIGN KEY(updated_host_uuid) REFERENCES hosts(host_uuid)
);
ALTER TABLE updated OWNER TO #!variable!user!#;
-- To avoid "waffling" when a sensor is close to an alert (or cleared) threshold, a gap between the alarm
-- value and the clear value is used. If the sensor climbs above (or below) the "clear" value, but didn't
-- previously pass the "alert" threshold, we DON'T want to send an "all clear" message. So do solve that,
-- this table is used by agents to record when a warning message was sent.
CREATE TABLE alert_sent (
alert_sent_uuid uuid primary key,
alert_sent_host_uuid uuid not null, -- The node associated with this alert
alert_set_by text not null, -- name of the program that set this alert
alert_record_locator text not null, -- String used by the agent to identify the source of the alert (ie: UPS serial number)
alert_name text not null, -- A free-form name used by the caller to identify this alert.
modified_date timestamp with time zone not null,
FOREIGN KEY(alert_sent_host_uuid) REFERENCES hosts(host_uuid)
);
ALTER TABLE updated OWNER TO #!variable!user!#;
-- This stores state information, like the whether migrations are happening and so on.
CREATE TABLE states (
state_uuid uuid primary key,
state_name text not null, -- This is the name of the state (ie: 'migration', etc)
state_host_uuid uuid not null, -- The UUID of the machine that the state relates to. In migrations, this is the UUID of the target
state_note text, -- This is a free-form note section that the application setting the state can use for extra information (like the name of the server being migrated)
modified_date timestamp with time zone not null,
FOREIGN KEY(state_host_uuid) REFERENCES hosts(host_uuid)
);
ALTER TABLE states OWNER TO #!variable!user!#;
-- NOTE: network_interfaces, network_bonds and network_bridges are all used by scan-network (which doesn't -- NOTE: network_interfaces, network_bonds and network_bridges are all used by scan-network (which doesn't
-- exist yet). -- exist yet).
@ -469,7 +422,7 @@ CREATE TRIGGER trigger_network_interfaces
-- This stores information about network bonds (mode=1) on a hosts. -- This stores information about network bonds (mode=1) on a hosts.
CREATE TABLE bonds ( CREATE TABLE bonds (
bond_uuid uuid primary key, bond_uuid uuid not null primary key,
bond_host_uuid uuid not null, bond_host_uuid uuid not null,
bond_name text not null, bond_name text not null,
bond_mode integer not null, -- This is the numerical bond type (will translate to the user's language in ScanCore) bond_mode integer not null, -- This is the numerical bond type (will translate to the user's language in ScanCore)
@ -552,7 +505,7 @@ CREATE TRIGGER trigger_bonds
-- This stores information about network bridges. -- This stores information about network bridges.
CREATE TABLE bridges ( CREATE TABLE bridges (
bridge_uuid uuid primary key, bridge_uuid uuid not null primary key,
bridge_host_uuid uuid not null, bridge_host_uuid uuid not null,
bridge_name text not null, bridge_name text not null,
bridge_id text, bridge_id text,
@ -606,3 +559,50 @@ CREATE TRIGGER trigger_bridges
AFTER INSERT OR UPDATE ON bridges AFTER INSERT OR UPDATE ON bridges
FOR EACH ROW EXECUTE PROCEDURE history_bridges(); FOR EACH ROW EXECUTE PROCEDURE history_bridges();
-- ------------------------------------------------------------------------------------------------------- --
-- These are special tables with no history or tracking UUIDs that simply record transient information. --
-- ------------------------------------------------------------------------------------------------------- --
-- This table records the last time a scan ran. It's sole purpose is to make sure at least one table's
-- 'modified_date' changes per run, so that database resyncs can be triggered reliably.
CREATE TABLE updated (
updated_host_uuid uuid not null,
updated_by text not null, -- The name of the agent (or "ScanCore' itself) that updated.
modified_date timestamp with time zone not null,
FOREIGN KEY(updated_host_uuid) REFERENCES hosts(host_uuid)
);
ALTER TABLE updated OWNER TO #!variable!user!#;
-- To avoid "waffling" when a sensor is close to an alert (or cleared) threshold, a gap between the alarm
-- value and the clear value is used. If the sensor climbs above (or below) the "clear" value, but didn't
-- previously pass the "alert" threshold, we DON'T want to send an "all clear" message. So do solve that,
-- this table is used by agents to record when a warning message was sent.
CREATE TABLE alert_sent (
alert_sent_uuid uuid not null primary key,
alert_sent_host_uuid uuid not null, -- The node associated with this alert
alert_set_by text not null, -- name of the program that set this alert
alert_record_locator text not null, -- String used by the agent to identify the source of the alert (ie: UPS serial number)
alert_name text not null, -- A free-form name used by the caller to identify this alert.
modified_date timestamp with time zone not null,
FOREIGN KEY(alert_sent_host_uuid) REFERENCES hosts(host_uuid)
);
ALTER TABLE updated OWNER TO #!variable!user!#;
-- This stores state information, like the whether migrations are happening and so on.
CREATE TABLE states (
state_uuid uuid not null primary key,
state_name text not null, -- This is the name of the state (ie: 'migration', etc)
state_host_uuid uuid not null, -- The UUID of the machine that the state relates to. In migrations, this is the UUID of the target
state_note text, -- This is a free-form note section that the application setting the state can use for extra information (like the name of the server being migrated)
modified_date timestamp with time zone not null,
FOREIGN KEY(state_host_uuid) REFERENCES hosts(host_uuid)
);
ALTER TABLE states OWNER TO #!variable!user!#;

Loading…
Cancel
Save