* 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
parent
4be943ebf3
commit
44dc4f4b47
8 changed files with 180 additions and 18 deletions
@ -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> |
Loading…
Reference in new issue