* Fixed a bug in Words->string() where not having the parameter 'file' set caused the default 'words.xml' to be specified, preventing strings from scan agents from being used.

* Started work on the new scan-cluster scan agent that will parse out and store data from the pacemaker CIB.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent 4be943ebf3
commit 44dc4f4b47
  1. 1
      Anvil/Tools/Database.pm
  2. 4
      Anvil/Tools/ScanCore.pm
  3. 2
      Anvil/Tools/Words.pm
  4. 95
      scancore-agents/scan-cluster/scan-cluster
  5. 42
      scancore-agents/scan-cluster/scan-cluster.sql
  6. 30
      scancore-agents/scan-cluster/scan-cluster.xml
  7. 2
      scancore-agents/scan-hardware/scan-hardware
  8. 22
      tools/test.pl

@ -69,6 +69,7 @@ my $THIS_FILE = "Database.pm";
# locking # locking
# manage_anvil_conf # manage_anvil_conf
# mark_active # mark_active
# purge_data
# query # query
# quote # quote
# read # read

@ -156,13 +156,13 @@ sub agent_startup
# Read in our word strings. # Read in our word strings.
my $words_file = $anvil->data->{path}{directories}{scan_agents}."/".$agent."/".$agent.".xml"; 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({ my $problem = $anvil->Words->read({
debug => $debug, debug => $debug,
file => $words_file, 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) if ($problem)
{ {

@ -752,7 +752,7 @@ sub string
# Setup default values # Setup default values
my $key = defined $parameter->{key} ? $parameter->{key} : ""; my $key = defined $parameter->{key} ? $parameter->{key} : "";
my $language = $parameter->{language} ? $parameter->{language} : $anvil->Words->language; 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 $string = defined $parameter->{string} ? $parameter->{string} : "";
my $variables = defined $parameter->{variables} ? $parameter->{variables} : ""; 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. ### NOTE: Don't call Log->entry here, or we'll get a recursive loop! Use 'test' to debug.

@ -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);
}

@ -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();

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Company: Alteeve's Niche, Inc.
License: GPL v2+
Author: Madison Kelly <mkelly@alteeve.ca>
NOTE: All string keys MUST be prefixed with the agent name! ie: 'scan_cluster_log_0001'.
-->
<words>
<meta version="3.0.0" languages="en_CA,jp"/>
<!-- Canadian English -->
<language name="en_CA" long_name="Canadian English" description="ScanCore scan agent that monitors hardware, like RAM modules, CSS LED status, CPU information, etc.">
<!-- Alert entries -->
<key name="scan_cluster_alert_0001"></key>
<!-- Log entries -->
<key name="scan_cluster_log_0001">Starting: [#!variable!program!#].</key>
<key name="scan_cluster_log_0002">This host is a: [#!variable!host_type!#], this agent is only useful on nodes. Exiting.</key>
<!-- Message entries (usually meant to be alerts) -->
<key name="scan_cluster_message_0001"></key>
<!-- Units -->
<key name="scan_cluster_unit_0001"></key>
</language>
</words>

@ -9,7 +9,7 @@
# 1 = Startup failure (no DB, bad file read, etc) # 1 = Startup failure (no DB, bad file read, etc)
# #
# TODO: # TODO:
# - Decide if it's worth having a separate ScanCore.log file or just feed into anvil.log. # -
# #
use strict; use strict;

@ -25,22 +25,16 @@ $anvil->Log->level({set => 2});
$anvil->Log->secure({set => 1}); $anvil->Log->secure({set => 1});
$anvil->Get->switches; $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"; my $not_in_cluster = $anvil->Cluster->parse_cib({debug => 2});
foreach my $thing (@{$array}) if ($not_in_cluster)
{ {
print "- ".$thing."\n"; print "This node isn't in the cluster.\n";
} }
else
print "Reverse:\n";
foreach my $thing (reverse @{$array})
{ {
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"});

Loading…
Cancel
Save