diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 48847f0b..b13e303f 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -69,6 +69,7 @@ my $THIS_FILE = "Database.pm"; # locking # manage_anvil_conf # mark_active +# purge_data # query # quote # read diff --git a/Anvil/Tools/ScanCore.pm b/Anvil/Tools/ScanCore.pm index 8d68f4b0..fc370388 100755 --- a/Anvil/Tools/ScanCore.pm +++ b/Anvil/Tools/ScanCore.pm @@ -156,13 +156,13 @@ sub agent_startup # Read in our word strings. my $words_file = $anvil->data->{path}{directories}{scan_agents}."/".$agent."/".$agent.".xml"; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { words_file => $words_file }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { words_file => $words_file }}); my $problem = $anvil->Words->read({ debug => $debug, file => $words_file, }); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { problem => $problem }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); if ($problem) { diff --git a/Anvil/Tools/Words.pm b/Anvil/Tools/Words.pm index d84ee1cf..5763928d 100644 --- a/Anvil/Tools/Words.pm +++ b/Anvil/Tools/Words.pm @@ -752,7 +752,7 @@ sub string # Setup default values my $key = defined $parameter->{key} ? $parameter->{key} : ""; my $language = $parameter->{language} ? $parameter->{language} : $anvil->Words->language; - my $file = $parameter->{file} ? $parameter->{file} : $anvil->data->{path}{words}{'words.xml'}; + my $file = $parameter->{file} ? $parameter->{file} : ""; my $string = defined $parameter->{string} ? $parameter->{string} : ""; my $variables = defined $parameter->{variables} ? $parameter->{variables} : ""; ### NOTE: Don't call Log->entry here, or we'll get a recursive loop! Use 'test' to debug. diff --git a/scancore-agents/scan-cluster/scan-cluster b/scancore-agents/scan-cluster/scan-cluster new file mode 100755 index 00000000..f5d0b890 --- /dev/null +++ b/scancore-agents/scan-cluster/scan-cluster @@ -0,0 +1,95 @@ +#!/usr/bin/perl +# +# This scans the cluster by processing the CIB and storing information about nodes, cluster states, etc. +# +# Examples; +# +# Exit codes; +# 0 = Normal exit. +# 1 = Startup failure (no DB, bad file read, etc) +# +# TODO: +# - +# + +use strict; +use warnings; +use Anvil::Tools; +use Data::Dumper; + +# Disable buffering +$| = 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({log_level => 2, log_secure => 1}); +$anvil->Log->level({set => 2}); +$anvil->Log->secure({set => 1}); + +$anvil->Storage->read_config(); + +# Read switches +$anvil->Get->switches; + +# These are the tables used by this agent. The order matters as it controls to order the tables are created +# and sync'ed. For purges, this array is walked backwards. +$anvil->data->{scancore}{'scan-cluster'}{tables} = ["scan_cluster"]; + +# Handle start-up tasks +my $problem = $anvil->ScanCore->agent_startup({ + debug => 3, + agent => $THIS_FILE, + tables => $anvil->data->{scancore}{'scan-cluster'}{tables}, +}); +if ($problem) +{ + $anvil->nice_exit({exit_code => 1}); +} + +$anvil->Log->entry({test => 1, source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_cluster_log_0001", variables => { program => $THIS_FILE }}); +if ($anvil->data->{switches}{purge}) +{ + # This can be called when doing bulk-database purges. + $anvil->Database->purge_data({ + debug => 2, + tables => $anvil->data->{scancore}{'scan-cluster'}{tables}, + }); + $anvil->nice_exit({exit_code => 0}); +} + +# Before we do anything, are we a node in a pacemaker cluster? +my $host_type = $anvil->Get->host_type; +$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_type => $host_type }}); +if ($host_type ne "node") +{ + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_cluster_log_0002", variables => { host_type => $host_type }}); + $anvil->nice_exit({exit_code => 0}); +} + +# Read the data. +collect_data($anvil); + + + +$anvil->nice_exit({exit_code => 0}); + +############################################################################################################# +# Functions # +############################################################################################################# + + +# This reads in all the data we can find on the local system +sub collect_data +{ + my ($anvil) = @_; + + # + + + return(0); +} \ No newline at end of file diff --git a/scancore-agents/scan-cluster/scan-cluster.sql b/scancore-agents/scan-cluster/scan-cluster.sql new file mode 100644 index 00000000..15367fa1 --- /dev/null +++ b/scancore-agents/scan-cluster/scan-cluster.sql @@ -0,0 +1,42 @@ +-- This is the database schema for the 'scan-cluster Scan Agent'. + +CREATE TABLE scan_cluster ( + scan_cluster_uuid uuid primary key, + scan_cluster_host_uuid uuid not null, + modified_date timestamp with time zone not null, + + FOREIGN KEY(scan_cluster_host_uuid) REFERENCES hosts(host_uuid) +); +ALTER TABLE scan_cluster OWNER TO admin; + +CREATE TABLE history.scan_cluster ( + history_id bigserial, + scan_cluster_uuid uuid, + scan_cluster_host_uuid uuid, + modified_date timestamp with time zone not null +); +ALTER TABLE history.scan_cluster OWNER TO admin; + +CREATE FUNCTION history_scan_cluster() RETURNS trigger +AS $$ +DECLARE + history_scan_cluster RECORD; +BEGIN + SELECT INTO history_scan_cluster * FROM scan_cluster WHERE scan_cluster_uuid=new.scan_cluster_uuid; + INSERT INTO history.scan_cluster + (scan_cluster_uuid, + scan_cluster_host_uuid, + modified_date) + VALUES + (history_scan_cluster.scan_cluster_uuid, + history_scan_cluster.scan_cluster_host_uuid, + history_scan_cluster.modified_date); + RETURN NULL; +END; +$$ +LANGUAGE plpgsql; +ALTER FUNCTION history_scan_cluster() OWNER TO admin; + +CREATE TRIGGER trigger_scan_cluster + AFTER INSERT OR UPDATE ON scan_cluster + FOR EACH ROW EXECUTE PROCEDURE history_scan_cluster(); diff --git a/scancore-agents/scan-cluster/scan-cluster.xml b/scancore-agents/scan-cluster/scan-cluster.xml new file mode 100644 index 00000000..487af25a --- /dev/null +++ b/scancore-agents/scan-cluster/scan-cluster.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + Starting: [#!variable!program!#]. + This host is a: [#!variable!host_type!#], this agent is only useful on nodes. Exiting. + + + + + + + + + diff --git a/scancore-agents/scan-hardware/scan-hardware b/scancore-agents/scan-hardware/scan-hardware index 4c1970cd..95dac3ff 100755 --- a/scancore-agents/scan-hardware/scan-hardware +++ b/scancore-agents/scan-hardware/scan-hardware @@ -9,7 +9,7 @@ # 1 = Startup failure (no DB, bad file read, etc) # # TODO: -# - Decide if it's worth having a separate ScanCore.log file or just feed into anvil.log. +# - # use strict; diff --git a/tools/test.pl b/tools/test.pl index ff1256fd..33c497ed 100755 --- a/tools/test.pl +++ b/tools/test.pl @@ -25,22 +25,16 @@ $anvil->Log->level({set => 2}); $anvil->Log->secure({set => 1}); $anvil->Get->switches; -my $array = ["1", "2", "a", "b"]; +print "Connecting to the database(s);\n"; +$anvil->Database->connect({debug => 3}); +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, secure => 0, key => "log_0132"}); -print "Normal:\n"; -foreach my $thing (@{$array}) +my $not_in_cluster = $anvil->Cluster->parse_cib({debug => 2}); +if ($not_in_cluster) { - print "- ".$thing."\n"; + print "This node isn't in the cluster.\n"; } - -print "Reverse:\n"; -foreach my $thing (reverse @{$array}) +else { - print "- ".$thing."\n"; + print "CIB parsed.\n"; } - -exit; - -print "Connecting to the database(s);\n"; -$anvil->Database->connect({debug => 3}); -$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, secure => 0, key => "log_0132"});