Skip to content

Commit

Permalink
* Updated 'Storage->read_conf()' to only take parameters as hash refe…
Browse files Browse the repository at this point in the history
…rences now, and added a 'debug' parameter for, surprise, debugging.

* Created the 'locations' table in ScanCore's database and added the 'hosts_location_uuid' to the 'hosts' table. This will be for a location grouping feature scheduled for v2.1, but lays the groundwork now to avoid complicated DB updates later.
* Added an 'updates' file that will be, eventually, part of a Striker upgrade system.
* Started work on making email alerts from Striker dashboards. This includes a new 'Configure' menu entry for configuring the local striker.conf dashboards.

Signed-off-by: Digimer <[email protected]>
  • Loading branch information
Digimer committed Oct 15, 2016
1 parent ad363c3 commit b801d35
Show file tree
Hide file tree
Showing 8 changed files with 780 additions and 129 deletions.
2 changes: 1 addition & 1 deletion AN/Tools.pm
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ sub new

# Before I do anything, read in values from the 'DEFAULT::CONFIG_FILE' configuration file.
$self->{DEFAULT}{CONFIG_FILE} = $an->Storage->find({file => $self->{DEFAULT}{CONFIG_FILE}, fatal => 1});
$an->Storage->read_conf($an->{DEFAULT}{CONFIG_FILE});
$an->Storage->read_conf({file => $an->{DEFAULT}{CONFIG_FILE} });

# Setup my '$an->data' hash right away so that I have a place to store the strings hash.
$an->data($parameter->{data}) if $parameter->{data};
Expand Down
30 changes: 17 additions & 13 deletions AN/Tools/ScanCore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ sub get_hosts
my $query = "
SELECT
host_uuid,
host_location_uuid,
host_name,
host_type,
host_emergency_stop,
Expand All @@ -343,23 +344,26 @@ FROM
foreach my $row (@{$results})
{
my $host_uuid = $row->[0];
my $host_name = $row->[1];
my $host_type = $row->[2];
my $host_emergency_stop = $row->[3] ? $row->[3] : "";
my $host_stop_reason = $row->[4] ? $row->[4] : "";
my $host_health = $row->[5] ? $row->[5] : "";
my $modified_date = $row->[6];
$an->Log->entry({log_level => 3, message_key => "an_variables_0007", message_variables => {
my $host_location_uuid = $row->[1] ? $row->[1] : "";
my $host_name = $row->[2];
my $host_type = $row->[3];
my $host_emergency_stop = $row->[4] ? $row->[4] : "";
my $host_stop_reason = $row->[5] ? $row->[5] : "";
my $host_health = $row->[6] ? $row->[6] : "";
my $modified_date = $row->[7];
$an->Log->entry({log_level => 3, message_key => "an_variables_0008", message_variables => {
name1 => "host_uuid", value1 => $host_uuid,
name2 => "host_name", value2 => $host_name,
name3 => "host_type", value3 => $host_type,
name4 => "host_emergency_stop", value4 => $host_emergency_stop,
name5 => "host_stop_reason", value5 => $host_stop_reason,
name6 => "host_health", value6 => $host_health,
name7 => "modified_date", value7 => $modified_date,
name2 => "host_location_uuid", value2 => $host_location_uuid,
name3 => "host_name", value3 => $host_name,
name4 => "host_type", value4 => $host_type,
name5 => "host_emergency_stop", value5 => $host_emergency_stop,
name6 => "host_stop_reason", value6 => $host_stop_reason,
name7 => "host_health", value7 => $host_health,
name8 => "modified_date", value8 => $modified_date,
}, file => $THIS_FILE, line => __LINE__});
push @{$return}, {
host_uuid => $host_uuid,
host_location_uuid => $host_location_uuid,
host_name => $host_name,
host_type => $host_type,
host_emergency_stop => $host_emergency_stop,
Expand Down
61 changes: 31 additions & 30 deletions AN/Tools/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,6 @@ sub read_conf
# Clear any prior errors as I may set one here.
$an->Alert->_set_error;

my $file;
my $hash = $an->data;

# This is/was for testing.
if (0)
{
Expand All @@ -400,34 +397,24 @@ sub read_conf
$an->nice_exit({exit_code => 0});
}

# Now see if the user passed the values in a hash reference or directly.
if (ref($parameter) eq "HASH")
{
# Values passed in a hash, good.
$file = $parameter->{file} if $parameter->{file};
$hash = $parameter->{hash} if $parameter->{hash};
}
else
{
# Values passed directly.
$file = $parameter;
$hash = $_[0] if defined $_[0];
}
my $file = $parameter->{file} ? $parameter->{file} : "";
my $hash = $parameter->{hash} ? $parameter->{hash} : $an->data;
my $debug = $parameter->{debug} ? $parameter->{debug} : 0;

# Make sure I have a sane file name.
if ($file)
{
# Find it relative to the AN::Tools root directory.
if ($file =~ /^AN::Tools/)
{
my $dir = $INC{'AN/Tools.pm'};
$dir =~ s/Tools.pm//;
$file =~ s/AN::Tools\//$dir/;
$file =~ s/\/\//\//g;
my $dir = $INC{'AN/Tools.pm'};
$dir =~ s/Tools.pm//;
$file =~ s/AN::Tools\//$dir/;
$file =~ s/\/\//\//g;
}

# I have a file. Is it relative to the install dir or fully qualified?
if (($file =~ /^\.\//) || ($file !~ /^\//))
if (($file =~ /^\.\//) or ($file !~ /^\//))
{
# It is in or relative to this directory.
if ($ENV{PWD})
Expand All @@ -452,37 +439,51 @@ sub read_conf
$an->_load_io_handle() if not $an->_io_handle_loaded();
my $read = IO::Handle->new();

if ($debug)
{
print "Content-type: text/html; charset=utf-8\n\n";
print "<pre>\n";
}

# Is it too early to use "$an->error"?
my $short_hostname = $an->short_hostname;
my $hostname = $an->hostname;
open ($read, "<$file") or die "Can't read: [$file], error was: $!\n";
while (<$read>)
{
chomp;
my $line = $_;
$line =~ s/^\s+//;
$line =~ s/\s+$//;
my $line = $_;
$line =~ s/^\s+//;
$line =~ s/\s+$//;
next if ((not $line) or ($line =~ /^#/));
next if $line !~ /=/;
my ($variable, $value) = split/=/, $line, 2;
$variable =~ s/\s+$//;
$value =~ s/^\s+//;
next if not $variable;

if ($debug)
{
print "$variable = $value\n";
}

# If the variable has '#!hostname!#' or '#!short_hostname!#', convert it now.
$value =~ s/#!hostname!#/$hostname/g;
$value =~ s/#!short_hostname!#/$short_hostname/g;

$an->_make_hash_reference($hash, $variable, $value);
}
$read->close();
if ($debug)
{
print "</pre>\n";
die "$THIS_FILE ".__LINE__."; testing...\n";
}

### MADI: Make this a more intelligent method that can go a variable
### number of sub-keys deep and does a search/replace of
### variables based on a given key match.
# Some keys store directories. Below, I convert the ones I know about
# to the current operating system's directory delimiter where '::' is
# found.
### TODO: Make this a more intelligent method that can go a variable number of sub-keys deep and does
### a search/replace of variables based on a given key match.
# Some keys store directories. Below, I convert the ones I know about to the current operating
# system's directory delimiter where '::' is found.
my $directory_delimiter = $an->_directory_delimiter();
foreach my $key (keys %{$an->data->{dir}})
{
Expand Down
Loading

0 comments on commit b801d35

Please sign in to comment.