* Created the ScanCore.pm module with the first 'agent_startup' method which generalized scan agent start up.
* Updated Alert->register to take a hash reference for message variables to simplify when a caller plans to log and register an alert at the same time. * Updated Convert->bytes_to_human_readable() to name the 'size' variable used internally for 'bytes' to actually be 'bytes' for better consistency. * Created multiple new Database methods; ** ->check_condition_age() is meant to be used by scan agents to see how long a given condition has been in play (ie: how long ago power was lost to a UPS or a sensor became unreadable). ** ->insert_or_update_health() handles recording data to the new 'health' table, used for determining ideal hosts for servers between nodes. ** ->insert_or_update_power() handles recording data to the new 'power' table, used for determining how power events are handled. ** ->insert_or_update_temperature() handles recording temperature data to the new 'temperature' table, used to determine how thermal events are handled. * Got a lot more done on the scan-hardware scan agent. Only part left now is post-scan health processing. Signed-off-by: Digimer <digimer@alteeve.ca>main
parent
28ac266024
commit
0a1dc809a2
14 changed files with 3463 additions and 379 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,177 @@ |
||||
package Anvil::Tools::ScanCore; |
||||
# |
||||
# This module contains methods used to handle message processing related to support of multi-lingual use. |
||||
# |
||||
|
||||
use strict; |
||||
use warnings; |
||||
use Data::Dumper; |
||||
use Scalar::Util qw(weaken isweak); |
||||
use Data::Dumper; |
||||
use Time::HiRes qw(gettimeofday tv_interval); |
||||
use Text::Diff; |
||||
|
||||
our $VERSION = "3.0.0"; |
||||
my $THIS_FILE = "ScanCore.pm"; |
||||
|
||||
### Methods; |
||||
# agent_startup |
||||
|
||||
=pod |
||||
|
||||
=encoding utf8 |
||||
|
||||
=head1 NAME |
||||
|
||||
Anvil::Tools::ScanCore |
||||
|
||||
Provides all methods related to ScanCore and scan agents. |
||||
|
||||
=head1 SYNOPSIS |
||||
|
||||
use Anvil::Tools; |
||||
|
||||
# Get a common object handle on all Anvil::Tools modules. |
||||
my $anvil = Anvil::Tools->new(); |
||||
|
||||
# Access to methods using '$anvil->ScanCore->X'. |
||||
# |
||||
# Example using 'agent_startup()'; |
||||
my $foo_path = $anvil->ScanCore->read({file => $anvil->data->{path}{words}{'anvil.xml'}}); |
||||
|
||||
=head1 METHODS |
||||
|
||||
Methods in this module; |
||||
|
||||
=cut |
||||
sub new |
||||
{ |
||||
my $class = shift; |
||||
my $self = {}; |
||||
|
||||
bless $self, $class; |
||||
|
||||
return ($self); |
||||
} |
||||
|
||||
# Get a handle on the Anvil::Tools object. I know that technically that is a sibling module, but it makes more |
||||
# sense in this case to think of it as a parent. |
||||
sub parent |
||||
{ |
||||
my $self = shift; |
||||
my $parent = shift; |
||||
|
||||
$self->{HANDLE}{TOOLS} = $parent if $parent; |
||||
|
||||
# Defend against memory leads. See Scalar::Util'. |
||||
if (not isweak($self->{HANDLE}{TOOLS})) |
||||
{ |
||||
weaken($self->{HANDLE}{TOOLS}); |
||||
} |
||||
|
||||
return ($self->{HANDLE}{TOOLS}); |
||||
} |
||||
|
||||
|
||||
############################################################################################################# |
||||
# Public methods # |
||||
############################################################################################################# |
||||
|
||||
|
||||
# =head3 |
||||
# |
||||
# Private Functions; |
||||
# |
||||
# =cut |
||||
|
||||
############################################################################################################# |
||||
# Private functions # |
||||
############################################################################################################# |
||||
|
||||
|
||||
=head2 agent_startup |
||||
|
||||
This method handles connecting to the databases, loading the agent's schema, resync'ing database tables if needed and reading in the words files. |
||||
|
||||
If there is a problem, this method exits with C<< 1 >>. Otherwise, it exits with C<< 0 >>. |
||||
|
||||
Parameters; |
||||
|
||||
=head3 agent (required) |
||||
|
||||
This is the name of the scan agent. Usually this can be set as C<< $THIS_FILE >>. |
||||
|
||||
=head3 tables (required) |
||||
|
||||
This is an array reference of database tables to check when resync'ing. It is important that the tables are sorted in the order they need to be resync'ed in. (tables with primary keys before their foreign key tables). |
||||
|
||||
=cut |
||||
sub agent_startup |
||||
{ |
||||
my $self = shift; |
||||
my $parameter = shift; |
||||
my $anvil = $self->parent; |
||||
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "ScanCore->agent_startup()" }}); |
||||
|
||||
my $agent = defined $parameter->{agent} ? $parameter->{agent} : ""; |
||||
my $tables = defined $parameter->{tables} ? $parameter->{tables} : ""; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { |
||||
agent => $agent, |
||||
tables => $tables, |
||||
}}); |
||||
|
||||
if (not $agent) |
||||
{ |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "ScanCore->agent_startup()", parameter => "agent" }}); |
||||
return("!!error!!"); |
||||
} |
||||
if ((not $tables) or (ref($tables) ne "ARRAY") or (@{$tables} == 0)) |
||||
{ |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "ScanCore->agent_startup()", parameter => "tables" }}); |
||||
return("!!error!!"); |
||||
} |
||||
|
||||
# Append our tables |
||||
foreach my $table (@{$tables}) |
||||
{ |
||||
push @{$anvil->data->{sys}{database}{check_tables}}, $table; |
||||
} |
||||
|
||||
# Connect to DBs. |
||||
$anvil->Database->connect({debug => ($debug + 1)}); |
||||
$anvil->Log->entry({source => $agent, line => __LINE__, level => $debug, secure => 0, key => "log_0132"}); |
||||
if (not $anvil->data->{sys}{database}{connections}) |
||||
{ |
||||
# No databases, exit. |
||||
$anvil->Log->entry({source => $agent, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0003"}); |
||||
return(1); |
||||
} |
||||
|
||||
# Make sure our schema is loaded. |
||||
$anvil->Database->check_agent_data({ |
||||
debug => $debug, |
||||
agent => $agent, |
||||
}); |
||||
|
||||
# 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 => 2, list => { words_file => $words_file }}); |
||||
|
||||
my $problem = $anvil->Words->read({ |
||||
debug => ($debug + 1), |
||||
file => $words_file, |
||||
}); |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); |
||||
|
||||
if ($problem) |
||||
{ |
||||
# Something went wrong loading the file. |
||||
return(1); |
||||
} |
||||
|
||||
return(0); |
||||
|
||||
} |
||||
|
||||
1; |
File diff suppressed because it is too large
Load Diff
@ -1,155 +1,156 @@ |
||||
-- This is the database schema for the 'hardware Scan Agent'. |
||||
-- This is the database schema for the 'scan-hardware Scan Agent'. |
||||
|
||||
CREATE TABLE hardware ( |
||||
hardware_uuid uuid primary key, |
||||
hardware_host_uuid uuid not null, |
||||
hardware_cpu_model text not null, |
||||
hardware_cpu_cores numeric not null, -- We don't care about individual sockets / chips |
||||
hardware_cpu_threads numeric not null, |
||||
hardware_cpu_bugs text not null, |
||||
hardware_cpu_flags text not null, -- |
||||
hardware_ram_total numeric not null, -- This is the sum of the hardware memory module capacity |
||||
hardware_memory_total numeric not null, -- This is the amount seen by the OS, minus shared memory, like that allocated to video |
||||
hardware_memory_free numeric not null, -- |
||||
hardware_swap_total numeric not null, -- |
||||
hardware_swap_free numeric not null, -- |
||||
hardware_led_id text not null, -- |
||||
hardware_led_css text not null, -- |
||||
hardware_led_error text not null, -- |
||||
modified_date timestamp with time zone not null, |
||||
CREATE TABLE scan_hardware ( |
||||
scan_hardware_uuid uuid primary key, |
||||
scan_hardware_host_uuid uuid not null, |
||||
scan_hardware_cpu_model text not null, |
||||
scan_hardware_cpu_cores numeric not null, -- We don't care about individual sockets / chips |
||||
scan_hardware_cpu_threads numeric not null, |
||||
scan_hardware_cpu_bugs text not null, |
||||
scan_hardware_cpu_flags text not null, -- |
||||
scan_hardware_ram_total numeric not null, -- This is the sum of the hardware memory module capacity |
||||
scan_hardware_memory_total numeric not null, -- This is the amount seen by the OS, minus shared memory, like that allocated to video |
||||
scan_hardware_memory_free numeric not null, -- |
||||
scan_hardware_swap_total numeric not null, -- |
||||
scan_hardware_swap_free numeric not null, -- |
||||
scan_hardware_led_id text not null, -- |
||||
scan_hardware_led_css text not null, -- |
||||
scan_hardware_led_error text not null, -- |
||||
modified_date timestamp with time zone not null, |
||||
|
||||
FOREIGN KEY(hardware_host_uuid) REFERENCES hosts(host_uuid) |
||||
FOREIGN KEY(scan_hardware_host_uuid) REFERENCES hosts(host_uuid) |
||||
); |
||||
ALTER TABLE hardware OWNER TO admin; |
||||
ALTER TABLE scan_hardware OWNER TO admin; |
||||
|
||||
CREATE TABLE history.hardware ( |
||||
history_id bigserial, |
||||
hardware_uuid uuid, |
||||
hardware_host_uuid uuid, |
||||
hardware_cpu_model text, |
||||
hardware_cpu_cores numeric, |
||||
hardware_cpu_threads numeric, |
||||
hardware_cpu_bugs text, |
||||
hardware_cpu_flags text, |
||||
hardware_ram_total numeric, |
||||
hardware_memory_total numeric, |
||||
hardware_memory_free numeric, |
||||
hardware_swap_total numeric, |
||||
hardware_swap_free numeric, |
||||
hardware_led_id text, |
||||
hardware_led_css text, |
||||
hardware_led_error text, |
||||
modified_date timestamp with time zone not null |
||||
CREATE TABLE history.scan_hardware ( |
||||
history_id bigserial, |
||||
scan_hardware_uuid uuid, |
||||
scan_hardware_host_uuid uuid, |
||||
scan_hardware_cpu_model text, |
||||
scan_hardware_cpu_cores numeric, |
||||
scan_hardware_cpu_threads numeric, |
||||
scan_hardware_cpu_bugs text, |
||||
scan_hardware_cpu_flags text, |
||||
scan_hardware_ram_total numeric, |
||||
scan_hardware_memory_total numeric, |
||||
scan_hardware_memory_free numeric, |
||||
scan_hardware_swap_total numeric, |
||||
scan_hardware_swap_free numeric, |
||||
scan_hardware_led_id text, |
||||
scan_hardware_led_css text, |
||||
scan_hardware_led_error text, |
||||
modified_date timestamp with time zone not null |
||||
); |
||||
ALTER TABLE history.hardware OWNER TO admin; |
||||
ALTER TABLE history.scan_hardware OWNER TO admin; |
||||
|
||||
CREATE FUNCTION history_hardware() RETURNS trigger |
||||
CREATE FUNCTION history_scan_hardware() RETURNS trigger |
||||
AS $$ |
||||
DECLARE |
||||
history_hardware RECORD; |
||||
history_scan_hardware RECORD; |
||||
BEGIN |
||||
SELECT INTO history_hardware * FROM hardware WHERE hardware_uuid=new.hardware_uuid; |
||||
INSERT INTO history.hardware |
||||
(hardware_uuid, |
||||
hardware_host_uuid, |
||||
hardware_cpu_model, |
||||
hardware_cpu_cores, |
||||
hardware_cpu_threads, |
||||
hardware_cpu_bugs, |
||||
hardware_cpu_flags, |
||||
hardware_ram_total, |
||||
hardware_memory_total, |
||||
hardware_memory_free, |
||||
hardware_swap_total, |
||||
hardware_swap_free, |
||||
hardware_led_id, |
||||
hardware_led_css, |
||||
hardware_led_error, |
||||
SELECT INTO history_scan_hardware * FROM scan_hardware WHERE scan_hardware_uuid=new.scan_hardware_uuid; |
||||
INSERT INTO history.scan_hardware |
||||
(scan_hardware_uuid, |
||||
scan_hardware_host_uuid, |
||||
scan_hardware_cpu_model, |
||||
scan_hardware_cpu_cores, |
||||
scan_hardware_cpu_threads, |
||||
scan_hardware_cpu_bugs, |
||||
scan_hardware_cpu_flags, |
||||
scan_hardware_ram_total, |
||||
scan_hardware_memory_total, |
||||
scan_hardware_memory_free, |
||||
scan_hardware_swap_total, |
||||
scan_hardware_swap_free, |
||||
scan_hardware_led_id, |
||||
scan_hardware_led_css, |
||||
scan_hardware_led_error, |
||||
modified_date) |
||||
VALUES |
||||
(history_hardware.hardware_uuid, |
||||
history_hardware.hardware_host_uuid, |
||||
history_hardware.hardware_cpu_model, |
||||
history_hardware.hardware_cpu_cores, |
||||
history_hardware.hardware_cpu_threads, |
||||
history_hardware.hardware_cpu_bugs, |
||||
history_hardware.hardware_cpu_flags, |
||||
history_hardware.hardware_ram_total, |
||||
history_hardware.hardware_memory_total, |
||||
history_hardware.hardware_memory_free, |
||||
history_hardware.hardware_swap_total, |
||||
history_hardware.hardware_swap_free, |
||||
history_hardware.hardware_led_id, |
||||
history_hardware.hardware_led_css, |
||||
history_hardware.hardware_led_error, |
||||
history_hardware.modified_date); |
||||
(history_scan_hardware.scan_hardware_uuid, |
||||
history_scan_hardware.scan_hardware_host_uuid, |
||||
history_scan_hardware.scan_hardware_cpu_model, |
||||
history_scan_hardware.scan_hardware_cpu_cores, |
||||
history_scan_hardware.scan_hardware_cpu_threads, |
||||
history_scan_hardware.scan_hardware_cpu_bugs, |
||||
history_scan_hardware.scan_hardware_cpu_flags, |
||||
history_scan_hardware.scan_hardware_ram_total, |
||||
history_scan_hardware.scan_hardware_memory_total, |
||||
history_scan_hardware.scan_hardware_memory_free, |
||||
history_scan_hardware.scan_hardware_swap_total, |
||||
history_scan_hardware.scan_hardware_swap_free, |
||||
history_scan_hardware.scan_hardware_led_id, |
||||
history_scan_hardware.scan_hardware_led_css, |
||||
history_scan_hardware.scan_hardware_led_error, |
||||
history_scan_hardware.modified_date); |
||||
RETURN NULL; |
||||
END; |
||||
$$ |
||||
LANGUAGE plpgsql; |
||||
ALTER FUNCTION history_hardware() OWNER TO admin; |
||||
ALTER FUNCTION history_scan_hardware() OWNER TO admin; |
||||
|
||||
CREATE TRIGGER trigger_hardware |
||||
AFTER INSERT OR UPDATE ON hardware |
||||
FOR EACH ROW EXECUTE PROCEDURE history_hardware(); |
||||
CREATE TRIGGER trigger_scan_hardware |
||||
AFTER INSERT OR UPDATE ON scan_hardware |
||||
FOR EACH ROW EXECUTE PROCEDURE history_scan_hardware(); |
||||
|
||||
CREATE TABLE hardware_ram_modules ( |
||||
hardware_ram_module_uuid uuid primary key, |
||||
hardware_ram_module_host_uuid uuid not null, |
||||
hardware_ram_module_locator text not null, |
||||
hardware_ram_module_size numeric not null, |
||||
hardware_ram_module_manufacturer text not null, |
||||
hardware_ram_module_model text not null, |
||||
hardware_ram_module_serial_number text not null, |
||||
modified_date timestamp with time zone not null, |
||||
|
||||
CREATE TABLE scan_hardware_ram_modules ( |
||||
scan_hardware_ram_module_uuid uuid primary key, |
||||
scan_hardware_ram_module_host_uuid uuid not null, |
||||
scan_hardware_ram_module_locator text not null, |
||||
scan_hardware_ram_module_size numeric not null, |
||||
scan_hardware_ram_module_manufacturer text not null, |
||||
scan_hardware_ram_module_model text not null, |
||||
scan_hardware_ram_module_serial_number text not null, |
||||
modified_date timestamp with time zone not null, |
||||
|
||||
FOREIGN KEY(hardware_ram_module_host_uuid) REFERENCES hosts(host_uuid) |
||||
FOREIGN KEY(scan_hardware_ram_module_host_uuid) REFERENCES hosts(host_uuid) |
||||
); |
||||
ALTER TABLE hardware_ram_modules OWNER TO admin; |
||||
ALTER TABLE scan_hardware_ram_modules OWNER TO admin; |
||||
|
||||
CREATE TABLE history.hardware_ram_modules ( |
||||
history_id bigserial, |
||||
hardware_ram_module_uuid uuid, |
||||
hardware_ram_module_host_uuid uuid, |
||||
hardware_ram_module_locator text, |
||||
hardware_ram_module_size numeric, |
||||
hardware_ram_module_manufacturer text, |
||||
hardware_ram_module_model text, |
||||
hardware_ram_module_serial_number text, |
||||
modified_date timestamp with time zone not null |
||||
CREATE TABLE history.scan_hardware_ram_modules ( |
||||
history_id bigserial, |
||||
scan_hardware_ram_module_uuid uuid, |
||||
scan_hardware_ram_module_host_uuid uuid, |
||||
scan_hardware_ram_module_locator text, |
||||
scan_hardware_ram_module_size numeric, |
||||
scan_hardware_ram_module_manufacturer text, |
||||
scan_hardware_ram_module_model text, |
||||
scan_hardware_ram_module_serial_number text, |
||||
modified_date timestamp with time zone not null |
||||
); |
||||
ALTER TABLE history.hardware_ram_modules OWNER TO admin; |
||||
ALTER TABLE history.scan_hardware_ram_modules OWNER TO admin; |
||||
|
||||
CREATE FUNCTION history_hardware_ram_modules() RETURNS trigger |
||||
CREATE FUNCTION history_scan_hardware_ram_modules() RETURNS trigger |
||||
AS $$ |
||||
DECLARE |
||||
history_hardware_ram_modules RECORD; |
||||
history_scan_hardware_ram_modules RECORD; |
||||
BEGIN |
||||
SELECT INTO history_hardware_ram_modules * FROM hardware_ram_modules WHERE hardware_ram_module_uuid=new.hardware_ram_module_uuid; |
||||
INSERT INTO history.hardware_ram_modules |
||||
(hardware_ram_module_uuid, |
||||
hardware_ram_module_host_uuid, |
||||
hardware_ram_module_locator, |
||||
hardware_ram_module_size, |
||||
hardware_ram_module_manufacturer, |
||||
hardware_ram_module_model, |
||||
hardware_ram_module_serial_number, |
||||
SELECT INTO history_scan_hardware_ram_modules * FROM scan_hardware_ram_modules WHERE scan_hardware_ram_module_uuid=new.scan_hardware_ram_module_uuid; |
||||
INSERT INTO history.scan_hardware_ram_modules |
||||
(scan_hardware_ram_module_uuid, |
||||
scan_hardware_ram_module_host_uuid, |
||||
scan_hardware_ram_module_locator, |
||||
scan_hardware_ram_module_size, |
||||
scan_hardware_ram_module_manufacturer, |
||||
scan_hardware_ram_module_model, |
||||
scan_hardware_ram_module_serial_number, |
||||
modified_date) |
||||
VALUES |
||||
(history_hardware_ram_modules.hardware_ram_module_uuid, |
||||
history_hardware_ram_modules.hardware_ram_module_host_uuid, |
||||
history_hardware_ram_modules.hardware_ram_module_locator, |
||||
history_hardware_ram_modules.hardware_ram_module_size, |
||||
history_hardware_ram_modules.hardware_ram_module_manufacturer, |
||||
history_hardware_ram_modules.hardware_ram_module_model, |
||||
history_hardware_ram_modules.hardware_ram_module_serial_number, |
||||
history_hardware_ram_modules.modified_date); |
||||
(history_scan_hardware_ram_modules.scan_hardware_ram_module_uuid, |
||||
history_scan_hardware_ram_modules.scan_hardware_ram_module_host_uuid, |
||||
history_scan_hardware_ram_modules.scan_hardware_ram_module_locator, |
||||
history_scan_hardware_ram_modules.scan_hardware_ram_module_size, |
||||
history_scan_hardware_ram_modules.scan_hardware_ram_module_manufacturer, |
||||
history_scan_hardware_ram_modules.scan_hardware_ram_module_model, |
||||
history_scan_hardware_ram_modules.scan_hardware_ram_module_serial_number, |
||||
history_scan_hardware_ram_modules.modified_date); |
||||
RETURN NULL; |
||||
END; |
||||
$$ |
||||
LANGUAGE plpgsql; |
||||
ALTER FUNCTION history_hardware_ram_modules() OWNER TO admin; |
||||
ALTER FUNCTION history_scan_hardware_ram_modules() OWNER TO admin; |
||||
|
||||
CREATE TRIGGER trigger_hardware_ram_modules |
||||
AFTER INSERT OR UPDATE ON hardware_ram_modules |
||||
FOR EACH ROW EXECUTE PROCEDURE history_hardware_ram_modules(); |
||||
CREATE TRIGGER trigger_scan_hardware_ram_modules |
||||
AFTER INSERT OR UPDATE ON scan_hardware_ram_modules |
||||
FOR EACH ROW EXECUTE PROCEDURE history_scan_hardware_ram_modules(); |
||||
|
Loading…
Reference in new issue