diff --git a/AN/Tools/DB.pm b/AN/Tools/DB.pm index c17accaf..8414762d 100644 --- a/AN/Tools/DB.pm +++ b/AN/Tools/DB.pm @@ -9,6 +9,7 @@ use strict; use warnings; use DBI; use Data::Dumper; +no warnings 'recursion'; our $VERSION = "0.1.001"; my $THIS_FILE = "DB.pm"; @@ -650,15 +651,17 @@ sub do_db_write my $an = $self->parent; # Setup my variables. - my $id = $parameter->{id} ? $parameter->{id} : ""; - my $source = $parameter->{source} ? $parameter->{source} : ""; - my $line = $parameter->{line} ? $parameter->{line} : ""; - my $query = $parameter->{query} ? $parameter->{query} : ""; - $an->Log->entry({log_level => 3, message_key => "an_variables_0004", message_variables => { - name1 => "id", value1 => $id, - name2 => "source", value2 => $source, - name3 => "line", value3 => $line, - name4 => "query", value4 => $query, + my $id = $parameter->{id} ? $parameter->{id} : ""; + my $source = $parameter->{source} ? $parameter->{source} : ""; + my $line = $parameter->{line} ? $parameter->{line} : ""; + my $query = $parameter->{query} ? $parameter->{query} : ""; + my $reenter = $parameter->{reenter} ? $parameter->{reenter} : ""; + $an->Log->entry({log_level => 3, message_key => "an_variables_0005", message_variables => { + name1 => "id", value1 => $id, + name2 => "source", value2 => $source, + name3 => "line", value3 => $line, + name4 => "query", value4 => $query, + name5 => "reenter", value5 => $reenter, }, file => $THIS_FILE, line => __LINE__}); # If I don't have a query, die. @@ -690,35 +693,81 @@ sub do_db_write } # Sort out if I have one or many queries. - my $is_array = 0; - my @query; + my $limit = 25000; + my $count = 0; + my $query_set = []; $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "query", value1 => $query }, file => $THIS_FILE, line => __LINE__}); if (ref($query) eq "ARRAY") { # Multiple things to enter. - $is_array = 1; - foreach my $this_query (@{$query}) + $count = @{$query}; + + # If I am re-entering, then we'll proceed normally. If not, and if we have more than 10k + # queries, we'll split up the queries into 10k chunks and re-enter. + $an->Log->entry({log_level => 2, message_key => "an_variables_0003", message_variables => { + name1 => "count", value1 => $count, + name2 => "limit", value2 => $limit, + name3 => "reenter", value3 => $reenter, + }, file => $THIS_FILE, line => __LINE__}); + if (($count > $limit) && (not $reenter)) + { + my $i = 0; + my $next = $limit; + $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + name1 => "i", value1 => $i, + name2 => "next", value2 => $next, + }, file => $THIS_FILE, line => __LINE__}); + foreach my $this_query (@{$query}) + { + push @{$query_set}, $this_query; + $i++; + + if ($i > $next) + { + # Commit this batch. + foreach my $id (@db_ids) + { + # Commit this chunk to this DB. + $an->DB->do_db_write({id => $id, query => $query_set, source => $THIS_FILE, line => $line, reenter => 1}); + + # This can get memory intensive, so check our RAM usage and + # bail if we're eating too much. + $an->ScanCore->check_ram_usage(); + + # Wipe out the old set array, create it as a new anonymous array and reset 'i'. + undef $query_set; + $query_set = []; + $i = 0; + } + } + } + } + else { - push @query, $this_query; + # Not enough to worry about or we're dealing with a chunk, proceed as normal. + foreach my $this_query (@{$query}) + { + push @{$query_set}, $this_query; + } } } else { - push @query, $query; + push @{$query_set}, $query; } foreach my $id (@db_ids) { # Do the actual query(ies) - if ($is_array) + if ($count) { - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "is_array", value1 => $is_array + $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + name1 => "count", value1 => $count, }, file => $THIS_FILE, line => __LINE__}); $an->data->{dbh}{$id}->begin_work; } - foreach my $query (@query) + foreach my $query (@{$query_set}) { # Record the query if ($an->Log->db_transactions()) @@ -750,12 +799,15 @@ sub do_db_write } # Commit the changes. - if ($is_array) + if ($count) { $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "is_array", value1 => $is_array + name1 => "count", value1 => $count }, file => $THIS_FILE, line => __LINE__}); $an->data->{dbh}{$id}->commit(); + + # Free up some memory. + undef $query_set; } } diff --git a/AN/Tools/ScanCore.pm b/AN/Tools/ScanCore.pm index e2154f5c..8b4e0cc3 100644 --- a/AN/Tools/ScanCore.pm +++ b/AN/Tools/ScanCore.pm @@ -7,11 +7,13 @@ use strict; use warnings; use Data::Dumper; use Text::Diff; +no warnings 'recursion'; our $VERSION = "0.1.001"; my $THIS_FILE = "ScanCore.pm"; ### Methods; +# check_ram_usage # get_anvils # get_dr_jobs # get_dr_targets @@ -81,6 +83,102 @@ sub parent # Provided methods # ############################################################################################################# +# This checks the amount RAM used by ScanCore and exits if it exceeds a scancore::maximum_ram bytes. It looks +# for any process with our name and sums the RAM used. +sub check_ram_usage +{ + my $self = shift; + my $parameter = shift; + my $an = $self->parent; + $an->Log->entry({log_level => 3, title_key => "tools_log_0001", title_variables => { function => "check_ram_usage" }, message_key => "tools_log_0002", file => $THIS_FILE, line => __LINE__}); + + # Read in how much RAM we're using. + my $used_ram = $an->Get->ram_used_by_program({program_name => $an->data->{sys}{program_name}}); + $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + name1 => "used_ram", value1 => "$used_ram", + name2 => "scancore::maximum_ram", value2 => $an->data->{scancore}{maximum_ram} + }, file => $THIS_FILE, line => __LINE__}); + + # Exit if I failed to read the amount of RAM in use. + if (not $used_ram) + { + $an->Alert->warning({message_key => "scancore_warning_0023", message_variables => { program_name => $an->data->{sys}{program_name} }, quiet => 1, file => $THIS_FILE, line => __LINE__}); + $an->data->{sys}{'exit'} = 1; + } + + # Records the RAM used. + my $query = " +SELECT + ram_used_bytes +FROM + ram_used +WHERE + ram_used_by = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{program_name})." +AND + ram_used_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." +;"; + $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + name1 => "query", value1 => $query + }, file => $THIS_FILE, line => __LINE__}); + my $ram_used_bytes = $an->DB->do_db_query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; # (->[row]->[column]) + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { + name1 => "ram_used_bytes", value1 => $ram_used_bytes + }, file => $THIS_FILE, line => __LINE__}); + if (not $ram_used_bytes) + { + # Add this agent to the DB + my $query = " +INSERT INTO + ram_used +( + ram_used_host_uuid, + ram_used_by, + ram_used_bytes, + modified_date +) VALUES ( + ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid}).", + ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{program_name}).", + ".$an->data->{sys}{use_db_fh}->quote($used_ram).", + ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{db_timestamp})." +); +"; + $an->DB->do_db_write({query => $query, source => $THIS_FILE, line => __LINE__}); + } + elsif ($ram_used_bytes ne $used_ram) + { + # It exists and the value has changed. + my $query = " +UPDATE + ram_used +SET + ram_used_bytes = ".$an->data->{sys}{use_db_fh}->quote($used_ram).", + modified_date = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{db_timestamp})." +WHERE + ram_used_by = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{program_name})." +AND + ram_used_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." +;"; + $an->DB->do_db_write({query => $query, source => $THIS_FILE, line => __LINE__}); + } + else + { + # The amount of RAM used is unchanged. + #print __LINE__."; The amount of RAM used by ".$an->data->{sys}{program_name}." is unchanged.\n"; + } + + if ($used_ram > $an->data->{scancore}{maximum_ram}) + { + # Much, too much, much music! + # err, too much RAM... + $an->Alert->error({title_key => "an_0003", message_key => "scancore_error_0013", message_variables => { + used_ram => $an->Readable->bytes_to_hr({'bytes' => $used_ram}), + maximum_ram => $an->Readable->bytes_to_hr({'bytes' => $an->data->{scancore}{maximum_ram}}) + }, code => 5, file => $THIS_FILE, line => __LINE__}); + } + + return(0); +} + # Get a list of Anvil! systems as an array of hash references sub get_anvils { diff --git a/ScanCore/ScanCore b/ScanCore/ScanCore index 2d334419..5c2c3507 100755 --- a/ScanCore/ScanCore +++ b/ScanCore/ScanCore @@ -39,6 +39,7 @@ use strict; use warnings; use AN::Tools; use Data::Dumper; +no warnings 'recursion'; # Disable buffering. $| = 1; @@ -381,7 +382,7 @@ while(1) $an->DB->update_time({file => $THIS_FILE}); # Check RAM usage and bail if it looks like we're leaking. - check_ram_usage($an); + $an->ScanCore->check_ram_usage(); # Archive, if needed. archive_if_needed($an); @@ -511,7 +512,7 @@ sub archive_if_needed } # See if there was a request to archive records older than a certain date. If so, do it now. - # TODO + # TODO: Remove 'states' history. # Now lets look to archive certain fast-growing tables. # * agents @@ -992,7 +993,7 @@ ORDER BY # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({query => $query, source => $THIS_FILE, line => __LINE__}); my $count = @{$results}; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "count", value1 => $count, name2 => "results", value2 => $results, }, file => $THIS_FILE, line => __LINE__}); @@ -1426,7 +1427,7 @@ ORDER BY # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({query => $query, source => $THIS_FILE, line => __LINE__}); my $count = @{$results}; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "count", value1 => $count, name2 => "results", value2 => $results, }, file => $THIS_FILE, line => __LINE__}); @@ -6368,7 +6369,6 @@ sub update_db update_db_nodes($an); update_db_notifications($an); update_db_recipients($an); - update_db_states($an); update_db_nodes_cache($an); update_db_alerts($an); @@ -6825,7 +6825,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -6914,7 +6914,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7106,7 +7106,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7142,7 +7142,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7183,7 +7183,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7335,7 +7335,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7361,7 +7361,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7392,7 +7392,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7498,7 +7498,7 @@ FROM # Now, loop through each record from the unified table and see if it needs to be added to any DBs foreach my $modified_date (sort {$b cmp $a} keys %{$an->data->{db_data}{unified}{recipients}{modified_date}}) { - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "modified_date", value1 => $modified_date, }, file => $THIS_FILE, line => __LINE__}); foreach my $recipient_uuid (keys %{$an->data->{db_data}{unified}{recipients}{modified_date}{$modified_date}{recipient_uuid}}) @@ -7560,7 +7560,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7590,7 +7590,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7625,7 +7625,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7809,7 +7809,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7843,7 +7843,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -7882,7 +7882,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8093,7 +8093,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8133,7 +8133,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8178,7 +8178,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8366,7 +8366,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8400,7 +8400,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8439,7 +8439,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8591,7 +8591,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8617,7 +8617,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8648,7 +8648,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8800,7 +8800,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8826,7 +8826,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8857,7 +8857,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8886,227 +8886,6 @@ INSERT INTO return(0); } -# Update/sync the states table. Like 'servers', this table is not bound to a host. -sub update_db_states -{ - my ($an) = @_; - $an->Log->entry({log_level => 2, title_key => "tools_log_0001", title_variables => { function => "update_db_states" }, message_key => "tools_log_0002", file => $THIS_FILE, line => __LINE__}); - - # Now read in all the 'states' table records that came from us. - foreach my $id (sort {$a cmp $b} keys %{$an->data->{dbh}}) - { - # These will store the INSERTs for this DB, if needed. - $an->data->{db_resync}{$id}{sql} = []; - $an->data->{db_resync}{$id}{public}{sql} = []; - $an->data->{db_resync}{$id}{history}{sql} = []; - - ### NOTE: This table is special in that it does NOT link back to a specific host. - # Read in the history schema - my $query = " -SELECT - state_uuid, - state_name, - state_host_uuid, - state_note, - modified_date -FROM - history.states -;"; - $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { - name1 => "id", value1 => $id, - name2 => "query", value2 => $query - }, file => $THIS_FILE, line => __LINE__}); - - # Do the query against the source DB and loop through the results. - my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "results", value1 => $results - }, file => $THIS_FILE, line => __LINE__}); - foreach my $row (@{$results}) - { - my $state_uuid = $row->[0]; - my $state_name = $row->[1]; - my $state_host_uuid = $row->[2]; - my $state_note = $row->[3]; - my $modified_date = $row->[4]; - $an->Log->entry({log_level => 3, message_key => "an_variables_0005", message_variables => { - name1 => "state_uuid", value1 => $state_uuid, - name2 => "state_name", value2 => $state_name, - name3 => "state_host_uuid", value3 => $state_host_uuid, - name4 => "state_note", value4 => $state_note, - name5 => "modified_date", value5 => $modified_date - }, file => $THIS_FILE, line => __LINE__}); - - # Record this in the unified and local hashes. - $an->data->{db_data}{unified}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid} = { - state_name => $state_name, - state_host_uuid => $state_host_uuid, - state_note => $state_note, - }; - - $an->data->{db_data}{$id}{states}{state_uuid}{$state_uuid}{'exists'} = 1; - $an->data->{db_data}{$id}{states}{state_uuid}{$state_uuid}{seen} = 0; - $an->data->{db_data}{$id}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid} = { - state_name => $state_name, - state_host_uuid => $state_host_uuid, - state_note => $state_note, - }; - } - } - - ### NOTE: Sort '$b cmp $a' on the modified date. - # Now, loop through each record from the unified table and see if it needs to be added to any DBs - foreach my $modified_date (sort {$b cmp $a} keys %{$an->data->{db_data}{unified}{states}{modified_date}}) - { - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "modified_date", value1 => $modified_date, - }, file => $THIS_FILE, line => __LINE__}); - foreach my $state_uuid (keys %{$an->data->{db_data}{unified}{states}{modified_date}{$modified_date}{state_uuid}}) - { - my $state_name = $an->data->{db_data}{unified}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid}{state_name}; - my $state_host_uuid = $an->data->{db_data}{unified}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid}{state_host_uuid}; - my $state_note = $an->data->{db_data}{unified}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid}{state_note}; - $an->Log->entry({log_level => 3, message_key => "an_variables_0004", message_variables => { - name1 => "state_uuid", value1 => $state_uuid, - name2 => "state_name", value2 => $state_name, - name3 => "state_host_uuid", value3 => $state_name, - name4 => "state_note", value4 => $state_note, - }, file => $THIS_FILE, line => __LINE__}); - foreach my $id (sort {$a cmp $b} keys %{$an->data->{dbh}}) - { - # For each 'state_uuid' we see; - # - Check if we've *seen* it before - # |- If not; See if it *exists* in the public schema yet. - # | |- If so, check to see if the entry in the public schema is up to date. - # | | \- If not, _UPDATE_ public schema. - # | \- If not, do an _INSERT_ into public schema. - # \- If we have, see if it exists at the current timestamp. - # \- If not, _INSERT_ it into history schema. - # - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "db_data::${id}::state::state_uuid::${state_uuid}::seen", value1 => $an->data->{db_data}{$id}{states}{state_uuid}{$state_uuid}{seen}, - }, file => $THIS_FILE, line => __LINE__}); - if (not $an->data->{db_data}{$id}{states}{state_uuid}{$state_uuid}{seen}) - { - # Mark this record as now having been seen. - $an->data->{db_data}{$id}{states}{state_uuid}{$state_uuid}{seen} = 1; - - # Never seen it. Check if it exists. - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "db_data::${id}::state::state_uuid::${state_uuid}::exists", value1 => $an->data->{db_data}{$id}{states}{state_uuid}{$state_uuid}{'exists'}, - }, file => $THIS_FILE, line => __LINE__}); - if ($an->data->{db_data}{$id}{states}{state_uuid}{$state_uuid}{'exists'}) - { - # It exists, but does it exist at this time stamp? - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "db_data::${id}::state::modified_date::${modified_date}::state_uuid::${state_uuid}", value1 => $an->data->{db_data}{$id}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid}, - }, file => $THIS_FILE, line => __LINE__}); - if (not $an->data->{db_data}{$id}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid}) - { - # No, so UPDATE it. - my $query = " -UPDATE - public.states -SET - state_name = ".$an->data->{sys}{use_db_fh}->quote($state_name).", - state_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($state_host_uuid).", - state_note = ".$an->data->{sys}{use_db_fh}->quote($state_note).", - modified_date = ".$an->data->{sys}{use_db_fh}->quote($modified_date)." -WHERE - state_uuid = ".$an->data->{sys}{use_db_fh}->quote($state_uuid)." -;"; - # Now record the query in the array - $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { - name1 => "id", value1 => $id, - name2 => "query", value2 => $query - }, file => $THIS_FILE, line => __LINE__}); - push @{$an->data->{db_resync}{$id}{public}{sql}}, $query; - } - } - else - { - # It doesn't exist, so INSERT it. - my $query = " -INSERT INTO - public.states -( - state_uuid, - state_name, - state_host_uuid, - state_note, - modified_date -) VALUES ( - ".$an->data->{sys}{use_db_fh}->quote($state_uuid).", - ".$an->data->{sys}{use_db_fh}->quote($state_name).", - ".$an->data->{sys}{use_db_fh}->quote($state_host_uuid).", - ".$an->data->{sys}{use_db_fh}->quote($state_note).", - ".$an->data->{sys}{use_db_fh}->quote($modified_date)." -);"; - # Now record the query in the array - $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { - name1 => "id", value1 => $id, - name2 => "query", value2 => $query - }, file => $THIS_FILE, line => __LINE__}); - push @{$an->data->{db_resync}{$id}{public}{sql}}, $query; - } - } - else - { - # We've seen this 'state_uuid' before, so it is just a question - # of whether the entry for the current timestamp exists in the - # history schema. - if (not $an->data->{db_data}{$id}{states}{modified_date}{$modified_date}{state_uuid}{$state_uuid}) - { - # It doesn't, INSERT it. - my $query = " -INSERT INTO - history.states -( - state_uuid, - state_name, - state_host_uuid, - state_note, - modified_date -) VALUES ( - ".$an->data->{sys}{use_db_fh}->quote($state_uuid).", - ".$an->data->{sys}{use_db_fh}->quote($state_name).", - ".$an->data->{sys}{use_db_fh}->quote($state_host_uuid).", - ".$an->data->{sys}{use_db_fh}->quote($state_note).", - ".$an->data->{sys}{use_db_fh}->quote($modified_date)." -);"; - # Now record the query in the array - $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { - name1 => "id", value1 => $id, - name2 => "query", value2 => $query - }, file => $THIS_FILE, line => __LINE__}); - push @{$an->data->{db_resync}{$id}{history}{sql}}, $query; - } # Exist in history at timestamp? - } # Seen state_uuid? - } # foreach my $id - } # foreach my $state_uuid ... - } # foreach $modified_date ... - - # Free up memory by deleting the DB data from the main hash. - delete $an->data->{db_data}; - - # Do the INSERTs now and then release the memory. - foreach my $id (sort {$a cmp $b} keys %{$an->data->{dbh}}) - { - # Merge the queries with public schema queries being first. - @{$an->data->{db_resync}{$id}{sql}} = (@{$an->data->{db_resync}{$id}{public}{sql}}, @{$an->data->{db_resync}{$id}{history}{sql}}); - if (@{$an->data->{db_resync}{$id}{sql}} > 0) - { - $an->DB->do_db_write({id => $id, query => $an->data->{db_resync}{$id}{sql}, source => $THIS_FILE, line => __LINE__}); - delete $an->data->{db_resync}{$id}{sql}; - } - } - - return(0); -} - # Update the 'ram_used' table. sub update_db_ram_used { @@ -9231,7 +9010,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9259,7 +9038,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9292,7 +9071,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9482,7 +9261,7 @@ AND ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9518,7 +9297,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9559,7 +9338,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9615,7 +9394,7 @@ FROM WHERE health_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9722,7 +9501,7 @@ AND ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9752,7 +9531,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9787,7 +9566,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9848,7 +9627,7 @@ SELECT FROM history.dr_targets ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9996,7 +9775,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10036,7 +9815,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10081,7 +9860,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10273,7 +10052,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10309,7 +10088,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10350,7 +10129,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10598,7 +10377,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10648,7 +10427,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10703,7 +10482,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10872,7 +10651,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10902,7 +10681,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10937,7 +10716,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11126,7 +10905,7 @@ AND ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11162,7 +10941,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11203,7 +10982,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11400,7 +11179,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11453,7 +11232,7 @@ FROM WHERE agent_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11559,7 +11338,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11589,7 +11368,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11624,7 +11403,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11816,7 +11595,7 @@ WHERE ;"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11850,7 +11629,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -11889,7 +11668,7 @@ INSERT INTO );"; # Now record the query in the array $query =~ s/'NULL'/NULL/g; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -12105,6 +11884,8 @@ sub call_agents # Now loop through the agents I found and try calling them. foreach my $agent (sort {$a cmp $b} @{$an->data->{sys}{agents}}) { + print "$THIS_FILE ".__LINE__."; time: [".time."], agent: [$agent]\n"; + ### TODO: Put a time limit on these... my $start_time = time; my $say_agent = ($agent =~ /.*\/(.*)$/)[0]; @@ -12218,6 +11999,9 @@ WHERE }, file => $THIS_FILE, line => __LINE__}); $an->DB->do_db_write({query => $query, source => $THIS_FILE, line => __LINE__}); } + + # Make sure we're not eating too much RAM. + $an->ScanCore->check_ram_usage(); } # Clear the agent list. @@ -12226,100 +12010,6 @@ WHERE return(0); } -# This checks the amount RAM used by ScanCore and exits if it exceeds a scancore::maximum_ram bytes. It looks -# for any process with our name and sums the RAM used. -sub check_ram_usage -{ - my ($an) = @_; - $an->Log->entry({log_level => 2, title_key => "tools_log_0001", title_variables => { function => "check_ram_usage" }, message_key => "tools_log_0002", file => $THIS_FILE, line => __LINE__}); - - # Read in how much RAM we're using. - my $used_ram = $an->Get->ram_used_by_program({program_name => $an->data->{sys}{program_name}}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { - name1 => "used_ram", value1 => "$used_ram", - name2 => "scancore::maximum_ram", value2 => $an->data->{scancore}{maximum_ram} - }, file => $THIS_FILE, line => __LINE__}); - - # Exit if I failed to read the amount of RAM in use. - if (not $used_ram) - { - $an->Alert->warning({message_key => "scancore_warning_0023", message_variables => { program_name => $an->data->{sys}{program_name} }, quiet => 1, file => $THIS_FILE, line => __LINE__}); - $an->data->{sys}{'exit'} = 1; - } - - # Records the RAM used. - my $query = " -SELECT - ram_used_bytes -FROM - ram_used -WHERE - ram_used_by = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{program_name})." -AND - ram_used_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." -;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { - name1 => "query", value1 => $query - }, file => $THIS_FILE, line => __LINE__}); - my $ram_used_bytes = $an->DB->do_db_query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; # (->[row]->[column]) - $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { - name1 => "ram_used_bytes", value1 => $ram_used_bytes - }, file => $THIS_FILE, line => __LINE__}); - if (not $ram_used_bytes) - { - # Add this agent to the DB - my $query = " -INSERT INTO - ram_used -( - ram_used_host_uuid, - ram_used_by, - ram_used_bytes, - modified_date -) VALUES ( - ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid}).", - ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{program_name}).", - ".$an->data->{sys}{use_db_fh}->quote($used_ram).", - ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{db_timestamp})." -); -"; - $an->DB->do_db_write({query => $query, source => $THIS_FILE, line => __LINE__}); - } - elsif ($ram_used_bytes ne $used_ram) - { - # It exists and the value has changed. - my $query = " -UPDATE - ram_used -SET - ram_used_bytes = ".$an->data->{sys}{use_db_fh}->quote($used_ram).", - modified_date = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{db_timestamp})." -WHERE - ram_used_by = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{program_name})." -AND - ram_used_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." -;"; - $an->DB->do_db_write({query => $query, source => $THIS_FILE, line => __LINE__}); - } - else - { - # The amount of RAM used is unchanged. - #print __LINE__."; The amount of RAM used by ".$an->data->{sys}{program_name}." is unchanged.\n"; - } - - if ($used_ram > $an->data->{scancore}{maximum_ram}) - { - # Much, too much, much music! - # err, too much RAM... - $an->Alert->error({title_key => "an_0003", message_key => "scancore_error_0013", message_variables => { - used_ram => $an->Readable->bytes_to_hr({'bytes' => $used_ram}), - maximum_ram => $an->Readable->bytes_to_hr({'bytes' => $an->data->{scancore}{maximum_ram}}) - }, code => 5, file => $THIS_FILE, line => __LINE__}); - } - - return(0); -} - # This will read the 'results table' and looks for bad conditions, eventually. sub analyze_results { diff --git a/ScanCore/ScanCore.sql b/ScanCore/ScanCore.sql index 661e5e14..b2399a0d 100644 --- a/ScanCore/ScanCore.sql +++ b/ScanCore/ScanCore.sql @@ -609,57 +609,6 @@ CREATE TRIGGER trigger_hosts FOR EACH ROW EXECUTE PROCEDURE history_hosts(); --- This stores state information, like the whether migrations are happening and so on. -CREATE TABLE states ( - state_uuid uuid primary key, - state_name text not null, -- This is the name of the state (ie: 'migration', etc) - state_host_uuid uuid not null, -- The UUID of the machine that the state relates to. In migrations, this is the UUID of the target - state_note text, -- This is a free-form note section that the application setting the state can use for extra information (like the name of the server being migrated) - modified_date timestamp with time zone not null, - - FOREIGN KEY(state_host_uuid) REFERENCES hosts(host_uuid) -); -ALTER TABLE states OWNER TO #!variable!user!#; - -CREATE TABLE history.states ( - history_id bigserial, - state_uuid uuid, - state_name text, - state_host_uuid uuid, - state_note text, - modified_date timestamp with time zone not null -); -ALTER TABLE history.states OWNER TO #!variable!user!#; - -CREATE FUNCTION history_states() RETURNS trigger -AS $$ -DECLARE - history_states RECORD; -BEGIN - SELECT INTO history_states * FROM states WHERE state_uuid = new.state_uuid; - INSERT INTO history.states - (state_uuid, - state_name, - state_host_uuid, - state_note, - modified_date) - VALUES - (history_states.state_uuid, - history_states.state_name, - history_states.state_host_uuid, - history_states.state_note, - history_states.modified_date); - RETURN NULL; -END; -$$ -LANGUAGE plpgsql; -ALTER FUNCTION history_states() OWNER TO #!variable!user!#; - -CREATE TRIGGER trigger_states - AFTER INSERT OR UPDATE ON states - FOR EACH ROW EXECUTE PROCEDURE history_states(); - - -- TODO: Create a 'node_cache' table here that stores things like power check commands, default network to -- use for access, hosts and sshd data and so on. Link it to a host_uuid because some dashboards will -- record different data, like what network to use to talk to the dashboard. @@ -1428,3 +1377,16 @@ CREATE TABLE alert_sent ( FOREIGN KEY(alert_sent_host_uuid) REFERENCES hosts(host_uuid) ); ALTER TABLE updated OWNER TO #!variable!user!#; + + +-- This stores state information, like the whether migrations are happening and so on. +CREATE TABLE states ( + state_uuid uuid primary key, + state_name text not null, -- This is the name of the state (ie: 'migration', etc) + state_host_uuid uuid not null, -- The UUID of the machine that the state relates to. In migrations, this is the UUID of the target + state_note text, -- This is a free-form note section that the application setting the state can use for extra information (like the name of the server being migrated) + modified_date timestamp with time zone not null, + + FOREIGN KEY(state_host_uuid) REFERENCES hosts(host_uuid) +); +ALTER TABLE states OWNER TO #!variable!user!#; diff --git a/ScanCore/agents/scan-apc-ups/scan-apc-ups b/ScanCore/agents/scan-apc-ups/scan-apc-ups index 09066a59..f09758e1 100755 --- a/ScanCore/agents/scan-apc-ups/scan-apc-ups +++ b/ScanCore/agents/scan-apc-ups/scan-apc-ups @@ -23,6 +23,7 @@ use warnings; use AN::Tools; use Data::Dumper; use Socket; +no warnings 'recursion'; # Disable buffering. $| = 1; @@ -4136,7 +4137,7 @@ WHERE AND a.apc_ups_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4159,7 +4160,7 @@ AND my $apc_ups_battery_alarm_temperature = $row->[8]; my $apc_ups_battery_voltage = $row->[9]; my $modified_date = $row->[10]; - $an->Log->entry({log_level => 2, message_key => "an_variables_0011", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0011", message_variables => { name1 => "apc_ups_battery_apc_ups_uuid", value1 => $apc_ups_battery_apc_ups_uuid, name2 => "apc_ups_battery_replacement_date", value2 => $apc_ups_battery_replacement_date, name3 => "apc_ups_battery_health", value3 => $apc_ups_battery_health, @@ -4205,7 +4206,7 @@ AND # Now, loop through each record from the unified table and see if it needs to be added to any DBs. foreach my $modified_date (sort {$b cmp $a} keys %{$an->data->{db_data}{unified}{apc_ups_battery}{modified_date}}) { - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "modified_date", value1 => $modified_date, }, file => $THIS_FILE, line => __LINE__}); foreach my $apc_ups_battery_apc_ups_uuid (sort {$a cmp $b} keys %{$an->data->{db_data}{unified}{apc_ups_battery}{modified_date}{$modified_date}{apc_ups_battery_apc_ups_uuid}}) @@ -4219,7 +4220,7 @@ AND my $apc_ups_battery_temperature = $an->data->{db_data}{unified}{apc_ups_battery}{modified_date}{$modified_date}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{apc_ups_battery_temperature}; my $apc_ups_battery_alarm_temperature = $an->data->{db_data}{unified}{apc_ups_battery}{modified_date}{$modified_date}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{apc_ups_battery_alarm_temperature}; my $apc_ups_battery_voltage = $an->data->{db_data}{unified}{apc_ups_battery}{modified_date}{$modified_date}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{apc_ups_battery_voltage}; - $an->Log->entry({log_level => 2, message_key => "an_variables_0010", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0010", message_variables => { name1 => "apc_ups_battery_apc_ups_uuid", value1 => $apc_ups_battery_apc_ups_uuid, name2 => "apc_ups_battery_replacement_date", value2 => $apc_ups_battery_replacement_date, name3 => "apc_ups_battery_health", value3 => $apc_ups_battery_health, @@ -4242,7 +4243,7 @@ AND # \- If we have, see if it exists at the current timestamp. # \- If not, _INSERT_ it into history schema. # - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_battery::apc_ups_battery_apc_ups_uuid::${apc_ups_battery_apc_ups_uuid}::seen", value1 => $an->data->{db_data}{$id}{apc_ups_battery}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{seen}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups_battery}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{seen}) @@ -4251,13 +4252,13 @@ AND $an->data->{db_data}{$id}{apc_ups_battery}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{seen} = 1; # Never seen it. Check if it exists. - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_battery::apc_ups_battery_apc_ups_uuid::${apc_ups_battery_apc_ups_uuid}::exists", value1 => $an->data->{db_data}{$id}{apc_ups_battery}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{'exists'}, }, file => $THIS_FILE, line => __LINE__}); if ($an->data->{db_data}{$id}{apc_ups_battery}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}{'exists'}) { # It exists, but does it exist at this time stamp? - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_battery::modified_date::${modified_date}::apc_ups_battery_apc_ups_uuid::${apc_ups_battery_apc_ups_uuid}", value1 => $an->data->{db_data}{$id}{apc_ups_battery}{modified_date}{$modified_date}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups_battery}{modified_date}{$modified_date}{apc_ups_battery_apc_ups_uuid}{$apc_ups_battery_apc_ups_uuid}) @@ -4294,7 +4295,7 @@ WHERE ) ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4333,7 +4334,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4386,7 +4387,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4448,7 +4449,7 @@ WHERE AND a.apc_ups_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4468,7 +4469,7 @@ AND my $apc_ups_output_voltage = $row->[5]; my $apc_ups_output_total_output = $row->[6]; my $modified_date = $row->[7]; - $an->Log->entry({log_level => 2, message_key => "an_variables_0008", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0008", message_variables => { name1 => "apc_ups_output_apc_ups_uuid", value1 => $apc_ups_output_apc_ups_uuid, name2 => "apc_ups_output_load_percentage", value2 => $apc_ups_output_load_percentage, name3 => "apc_ups_output_time_on_batteries", value3 => $apc_ups_output_time_on_batteries, @@ -4507,7 +4508,7 @@ AND # Now, loop through each record from the unified table and see if it needs to be added to any DBs. foreach my $modified_date (sort {$b cmp $a} keys %{$an->data->{db_data}{unified}{apc_ups_output}{modified_date}}) { - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "modified_date", value1 => $modified_date, }, file => $THIS_FILE, line => __LINE__}); foreach my $apc_ups_output_apc_ups_uuid (sort {$a cmp $b} keys %{$an->data->{db_data}{unified}{apc_ups_output}{modified_date}{$modified_date}{apc_ups_output_apc_ups_uuid}}) @@ -4518,7 +4519,7 @@ AND my $apc_ups_output_frequency = $an->data->{db_data}{unified}{apc_ups_output}{modified_date}{$modified_date}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{apc_ups_output_frequency}; my $apc_ups_output_voltage = $an->data->{db_data}{unified}{apc_ups_output}{modified_date}{$modified_date}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{apc_ups_output_voltage}; my $apc_ups_output_total_output = $an->data->{db_data}{unified}{apc_ups_output}{modified_date}{$modified_date}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{apc_ups_output_total_output}; - $an->Log->entry({log_level => 2, message_key => "an_variables_0007", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0007", message_variables => { name1 => "apc_ups_output_apc_ups_uuid", value1 => $apc_ups_output_apc_ups_uuid, name2 => "apc_ups_output_load_percentage", value2 => $apc_ups_output_load_percentage, name3 => "apc_ups_output_time_on_batteries", value3 => $apc_ups_output_time_on_batteries, @@ -4538,7 +4539,7 @@ AND # \- If we have, see if it exists at the current timestamp. # \- If not, _INSERT_ it into history schema. # - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_output::apc_ups_output_apc_ups_uuid::${apc_ups_output_apc_ups_uuid}::seen", value1 => $an->data->{db_data}{$id}{apc_ups_output}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{seen}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups_output}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{seen}) @@ -4547,13 +4548,13 @@ AND $an->data->{db_data}{$id}{apc_ups_output}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{seen} = 1; # Never seen it. Check if it exists. - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_output::apc_ups_output_apc_ups_uuid::${apc_ups_output_apc_ups_uuid}::exists", value1 => $an->data->{db_data}{$id}{apc_ups_output}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{'exists'}, }, file => $THIS_FILE, line => __LINE__}); if ($an->data->{db_data}{$id}{apc_ups_output}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}{'exists'}) { # It exists, but does it exist at this time stamp? - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_output::modified_date::${modified_date}::apc_ups_output_apc_ups_uuid::${apc_ups_output_apc_ups_uuid}", value1 => $an->data->{db_data}{$id}{apc_ups_output}{modified_date}{$modified_date}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups_output}{modified_date}{$modified_date}{apc_ups_output_apc_ups_uuid}{$apc_ups_output_apc_ups_uuid}) @@ -4588,7 +4589,7 @@ WHERE ) ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4621,7 +4622,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4668,7 +4669,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4729,7 +4730,7 @@ WHERE AND a.apc_ups_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4748,7 +4749,7 @@ AND my $apc_ups_input_1m_maximum_input_voltage = $row->[4]; my $apc_ups_input_1m_minimum_input_voltage = $row->[5]; my $modified_date = $row->[6]; - $an->Log->entry({log_level => 2, message_key => "an_variables_0007", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0007", message_variables => { name1 => "apc_ups_input_apc_ups_uuid", value1 => $apc_ups_input_apc_ups_uuid, name2 => "apc_ups_input_frequency", value2 => $apc_ups_input_frequency, name3 => "apc_ups_input_sensitivity", value3 => $apc_ups_input_sensitivity, @@ -4782,7 +4783,7 @@ AND # Now, loop through each record from the unified table and see if it needs to be added to any DBs. foreach my $modified_date (sort {$b cmp $a} keys %{$an->data->{db_data}{unified}{apc_ups_input}{modified_date}}) { - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "modified_date", value1 => $modified_date, }, file => $THIS_FILE, line => __LINE__}); foreach my $apc_ups_input_apc_ups_uuid (sort {$a cmp $b} keys %{$an->data->{db_data}{unified}{apc_ups_input}{modified_date}{$modified_date}{apc_ups_input_apc_ups_uuid}}) @@ -4792,7 +4793,7 @@ AND my $apc_ups_input_voltage = $an->data->{db_data}{unified}{apc_ups_input}{modified_date}{$modified_date}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}{apc_ups_input_voltage}; my $apc_ups_input_1m_maximum_input_voltage = $an->data->{db_data}{unified}{apc_ups_input}{modified_date}{$modified_date}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}{apc_ups_input_1m_maximum_input_voltage}; my $apc_ups_input_1m_minimum_input_voltage = $an->data->{db_data}{unified}{apc_ups_input}{modified_date}{$modified_date}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}{apc_ups_input_1m_minimum_input_voltage}; - $an->Log->entry({log_level => 2, message_key => "an_variables_0006", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0006", message_variables => { name1 => "apc_ups_input_apc_ups_uuid", value1 => $apc_ups_input_apc_ups_uuid, name2 => "apc_ups_input_frequency", value2 => $apc_ups_input_frequency, name3 => "apc_ups_input_sensitivity", value3 => $apc_ups_input_sensitivity, @@ -4811,7 +4812,7 @@ AND # \- If we have, see if it exists at the current timestamp. # \- If not, _INSERT_ it into history schema. # - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_input::apc_ups_input_apc_ups_uuid::${apc_ups_input_apc_ups_uuid}::seen", value1 => $an->data->{db_data}{$id}{apc_ups_input}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}{seen}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups_input}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}{seen}) @@ -4826,7 +4827,7 @@ AND if ($an->data->{db_data}{$id}{apc_ups_input}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}{'exists'}) { # It exists, but does it exist at this time stamp? - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups_input::modified_date::${modified_date}::apc_ups_input_apc_ups_uuid::${apc_ups_input_apc_ups_uuid}", value1 => $an->data->{db_data}{$id}{apc_ups_input}{modified_date}{$modified_date}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups_input}{modified_date}{$modified_date}{apc_ups_input_apc_ups_uuid}{$apc_ups_input_apc_ups_uuid}) @@ -4860,7 +4861,7 @@ WHERE ) ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4891,7 +4892,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -4936,7 +4937,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -5005,7 +5006,7 @@ FROM WHERE apc_ups_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -5035,7 +5036,7 @@ WHERE my $apc_ups_nmc_serial_number = $row->[15]; my $apc_ups_nmc_mac_address = $row->[16]; my $modified_date = $row->[17]; - $an->Log->entry({log_level => 2, message_key => "an_variables_0018", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0018", message_variables => { name1 => "apc_ups_uuid", value1 => $apc_ups_uuid, name2 => "apc_ups_name", value2 => $apc_ups_name, name3 => "apc_ups_serial_number", value3 => $apc_ups_serial_number, @@ -5102,7 +5103,7 @@ WHERE # Now, loop through each record from the unified table and see if it needs to be added to any DBs. foreach my $modified_date (sort {$b cmp $a} keys %{$an->data->{db_data}{unified}{apc_ups}{modified_date}}) { - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "modified_date", value1 => $modified_date, }, file => $THIS_FILE, line => __LINE__}); foreach my $apc_ups_uuid (sort {$a cmp $b} keys %{$an->data->{db_data}{unified}{apc_ups}{modified_date}{$modified_date}{apc_ups_uuid}}) @@ -5123,7 +5124,7 @@ WHERE my $apc_ups_nmc_firmware_version = $an->data->{db_data}{unified}{apc_ups}{modified_date}{$modified_date}{apc_ups_uuid}{$apc_ups_uuid}{apc_ups_nmc_firmware_version}; my $apc_ups_nmc_serial_number = $an->data->{db_data}{unified}{apc_ups}{modified_date}{$modified_date}{apc_ups_uuid}{$apc_ups_uuid}{apc_ups_nmc_serial_number}; my $apc_ups_nmc_mac_address = $an->data->{db_data}{unified}{apc_ups}{modified_date}{$modified_date}{apc_ups_uuid}{$apc_ups_uuid}{apc_ups_nmc_mac_address}; - $an->Log->entry({log_level => 2, message_key => "an_variables_0010", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0010", message_variables => { name1 => "apc_ups_uuid", value1 => $apc_ups_uuid, name2 => "apc_ups_name", value2 => $apc_ups_name, name3 => "apc_ups_serial_number", value3 => $apc_ups_serial_number, @@ -5153,7 +5154,7 @@ WHERE # \- If we have, see if it exists at the current timestamp. # \- If not, _INSERT_ it into history schema. # - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups::apc_ups_uuid::${apc_ups_uuid}::seen", value1 => $an->data->{db_data}{$id}{apc_ups}{apc_ups_uuid}{$apc_ups_uuid}{seen}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups}{apc_ups_uuid}{$apc_ups_uuid}{seen}) @@ -5162,13 +5163,13 @@ WHERE $an->data->{db_data}{$id}{apc_ups}{apc_ups_uuid}{$apc_ups_uuid}{seen} = 1; # Never seen it. Check if it exists. - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups::apc_ups_uuid::${apc_ups_uuid}::exists", value1 => $an->data->{db_data}{$id}{apc_ups}{apc_ups_uuid}{$apc_ups_uuid}{'exists'}, }, file => $THIS_FILE, line => __LINE__}); if ($an->data->{db_data}{$id}{apc_ups}{apc_ups_uuid}{$apc_ups_uuid}{'exists'}) { # It exists, but does it exist at this time stamp? - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::apc_ups::modified_date::${modified_date}::apc_ups_uuid::${apc_ups_uuid}", value1 => $an->data->{db_data}{$id}{apc_ups}{modified_date}{$modified_date}{apc_ups_uuid}{$apc_ups_uuid}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{apc_ups}{modified_date}{$modified_date}{apc_ups_uuid}{$apc_ups_uuid}) @@ -5201,7 +5202,7 @@ AND apc_ups_uuid = ".$an->data->{sys}{use_db_fh}->quote($apc_ups_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -5256,7 +5257,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -5316,7 +5317,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); diff --git a/ScanCore/agents/scan-bond/scan-bond b/ScanCore/agents/scan-bond/scan-bond index 7ccfc2ca..c6e7b1f8 100755 --- a/ScanCore/agents/scan-bond/scan-bond +++ b/ScanCore/agents/scan-bond/scan-bond @@ -29,6 +29,7 @@ use strict; use warnings; use AN::Tools; use Data::Dumper; +no warnings 'recursion'; # Disable buffering. $| = 1; @@ -501,7 +502,7 @@ FROM WHERE bond_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -572,7 +573,7 @@ WHERE # needs to be added to any DBs. foreach my $modified_date (sort {$b cmp $a} keys %{$an->data->{db_data}{unified}{bond}{modified_date}}) { - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "modified_date", value1 => $modified_date, }, file => $THIS_FILE, line => __LINE__}); foreach my $bond_uuid (sort {$a cmp $b} keys %{$an->data->{db_data}{unified}{bond}{modified_date}{$modified_date}{bond_uuid}}) @@ -586,7 +587,7 @@ WHERE my $bond_mii_polling_interval = $an->data->{db_data}{unified}{bond}{modified_date}{$modified_date}{bond_uuid}{$bond_uuid}{bond_mii_polling_interval}; my $bond_up_delay = $an->data->{db_data}{unified}{bond}{modified_date}{$modified_date}{bond_uuid}{$bond_uuid}{bond_up_delay}; my $bond_down_delay = $an->data->{db_data}{unified}{bond}{modified_date}{$modified_date}{bond_uuid}{$bond_uuid}{bond_down_delay}; - $an->Log->entry({log_level => 2, message_key => "an_variables_0010", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0010", message_variables => { name1 => "bond_uuid", value1 => $bond_uuid, name2 => "bond_name", value2 => $bond_name, name3 => "bond_mode", value3 => $bond_mode, @@ -609,7 +610,7 @@ WHERE # \- If we have, see if it exists at the current timestamp. # \- If not, _INSERT_ it into history schema. # - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::bond::bond_uuid::${bond_uuid}::seen", value1 => $an->data->{db_data}{$id}{bond}{bond_uuid}{$bond_uuid}{seen}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{bond}{bond_uuid}{$bond_uuid}{seen}) @@ -618,13 +619,13 @@ WHERE $an->data->{db_data}{$id}{bond}{bond_uuid}{$bond_uuid}{seen} = 1; # Never seen it. Check if it exists. - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::bond::bond_uuid::${bond_uuid}::exists", value1 => $an->data->{db_data}{$id}{bond}{bond_uuid}{$bond_uuid}{'exists'}, }, file => $THIS_FILE, line => __LINE__}); if ($an->data->{db_data}{$id}{bond}{bond_uuid}{$bond_uuid}{'exists'}) { # It exists, but does it exist at this time stamp? - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "db_data::${id}::bond::modified_date::${modified_date}::bond_uuid::${bond_uuid}", value1 => $an->data->{db_data}{$id}{bond}{modified_date}{$modified_date}{bond_uuid}{$bond_uuid}, }, file => $THIS_FILE, line => __LINE__}); if (not $an->data->{db_data}{$id}{bond}{modified_date}{$modified_date}{bond_uuid}{$bond_uuid}) @@ -650,7 +651,7 @@ AND bond_uuid = ".$an->data->{sys}{use_db_fh}->quote($bond_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -691,7 +692,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -737,7 +738,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); diff --git a/ScanCore/agents/scan-ipmitool/scan-ipmitool b/ScanCore/agents/scan-ipmitool/scan-ipmitool index 1242817f..c4aa7507 100755 --- a/ScanCore/agents/scan-ipmitool/scan-ipmitool +++ b/ScanCore/agents/scan-ipmitool/scan-ipmitool @@ -10,6 +10,7 @@ # Exit Codes: # 0 - Success # 1 - Passed in host name was not found in the database. +# 2 - Bad number of ipmitool_value_id's returned for the given # # 255 - The host's UUID isn't in the hosts table yet, ScanCore itself hasn't been run. # @@ -75,6 +76,7 @@ use warnings; use AN::Tools; use Data::Dumper; use Socket; +no warnings 'recursion'; #use utf8; #binmode STDOUT, 'encoding(utf8)'; @@ -2666,7 +2668,7 @@ AND # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "results", value1 => $results }, file => $THIS_FILE, line => __LINE__}); foreach my $row (@{$results}) @@ -2748,7 +2750,7 @@ WHERE ipmitool_value_ipmitool_uuid = ".$an->data->{sys}{use_db_fh}->quote($ipmitool_value_ipmitool_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -2771,7 +2773,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -2785,6 +2787,9 @@ INSERT INTO # the history schema. if (not $an->data->{db_data}{$id}{ipmitool_value}{modified_date}{$modified_date}{ipmitool_value_ipmitool_uuid}{$ipmitool_value_ipmitool_uuid}) { + # Get the ID for this. + my $ipmitool_value_id = get_ipmitool_value_id($an, $ipmitool_value_ipmitool_uuid, $id); + # It doesn't, INSERT it. my $query = " INSERT INTO @@ -2795,20 +2800,13 @@ INSERT INTO ipmitool_value_sensor_value, modified_date ) VALUES ( - ( - SELECT - ipmitool_value_id - FROM - public.ipmitool_value - WHERE - ipmitool_value_ipmitool_uuid = ".$an->data->{sys}{use_db_fh}->quote($ipmitool_value_ipmitool_uuid)." - ), + ".$an->data->{sys}{use_db_fh}->quote($ipmitool_value_id).", ".$an->data->{sys}{use_db_fh}->quote($ipmitool_value_ipmitool_uuid).", ".$an->data->{sys}{use_db_fh}->quote($ipmitool_value_sensor_value).", ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -2837,6 +2835,61 @@ INSERT INTO return(0); } +# This returns the ipmitool_value_id for a given ipmitool_value_ipmitool_uuid +sub get_ipmitool_value_id +{ + my ($an, $ipmitool_value_ipmitool_uuid, $id) = @_; + + my $query = " +SELECT + ipmitool_value_id +FROM + public.ipmitool_value +WHERE + ipmitool_value_ipmitool_uuid = ".$an->data->{sys}{use_db_fh}->quote($ipmitool_value_ipmitool_uuid)." +;"; + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { + name1 => "id", value1 => $id, + name2 => "query", value2 => $query, + }, file => $THIS_FILE, line => __LINE__}); + + # Do the query against the source DB and loop through the results. + my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); + my $count = @{$results}; + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { + name1 => "results", value1 => $results, + name2 => "count", value2 => $count, + }, file => $THIS_FILE, line => __LINE__}); + + # There should be only one result + if ($count != 1) + { + my $i = 1; + foreach my $row (@{$results}) + { + my $ipmitool_value_id = $row->[0]; + $an->Log->entry({log_level => 0, message_key => "an_variables_0002", message_variables => { + name1 => "i", value1 => $i, + name2 => "ipmitool_value_id", value2 => $ipmitool_value_id, + }, file => $THIS_FILE, line => __LINE__}); + $i++; + } + $an->Alert->error({title_key => "an_0003", message_key => "scan_ipmitool_error_0001", message_variables => { + query => $query, + id => $id, + count => $count, + }, code => 2, file => $THIS_FILE, line => __LINE__}); + } + + # Return only the first. + my $ipmitool_value_id = $results->[0]->[0]; + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { + name1 => "ipmitool_value_id", value1 => $ipmitool_value_id, + }, file => $THIS_FILE, line => __LINE__}); + + return($ipmitool_value_id); +} + # Update the 'ipmitool' DB table, if needed. sub update_db_ipmitool { @@ -2869,14 +2922,14 @@ FROM WHERE ipmitool_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "results", value1 => $results }, file => $THIS_FILE, line => __LINE__}); foreach my $row (@{$results}) @@ -2891,7 +2944,7 @@ WHERE my $ipmitool_sensor_low_critical = $row->[7]; my $ipmitool_sensor_low_warning = $row->[8]; my $modified_date = $row->[9]; - $an->Log->entry({log_level => 2, message_key => "an_variables_0010", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0010", message_variables => { name1 => "ipmitool_uuid", value1 => $ipmitool_uuid, name2 => "ipmitool_sensor_host", value2 => $ipmitool_sensor_host, name3 => "ipmitool_sensor_name", value3 => $ipmitool_sensor_name, @@ -3012,7 +3065,7 @@ AND ipmitool_uuid = ".$an->data->{sys}{use_db_fh}->quote($ipmitool_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -3051,7 +3104,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -3095,7 +3148,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); diff --git a/ScanCore/agents/scan-ipmitool/scan-ipmitool.xml b/ScanCore/agents/scan-ipmitool/scan-ipmitool.xml index 2bbf48e0..df8d7232 100644 --- a/ScanCore/agents/scan-ipmitool/scan-ipmitool.xml +++ b/ScanCore/agents/scan-ipmitool/scan-ipmitool.xml @@ -22,6 +22,9 @@ with 'scan_ipmitool_'. Failed to query node: [#!variable!machine!#]'s IPMI interface using the call: [#!variable!call!#]. Is the password correct? The thermal sensor named: [#!variable!sensor_name!#] has not changed. + + The query: [#!variable!query!#] against DB: [#!variable!id!#] returned: [#!variable!count!#] rows. Only '1' should have been returned! + OK No Signal diff --git a/ScanCore/agents/scan-server/scan-server b/ScanCore/agents/scan-server/scan-server index 768aa712..c3c3c149 100755 --- a/ScanCore/agents/scan-server/scan-server +++ b/ScanCore/agents/scan-server/scan-server @@ -29,6 +29,7 @@ use strict; use warnings; use AN::Tools; use Text::Diff; +no warnings 'recursion'; # Disable buffering. $| = 1; diff --git a/ScanCore/agents/scan-storcli/scan-storcli b/ScanCore/agents/scan-storcli/scan-storcli index ed9ffe73..b8274abf 100755 --- a/ScanCore/agents/scan-storcli/scan-storcli +++ b/ScanCore/agents/scan-storcli/scan-storcli @@ -47,6 +47,7 @@ use strict; use warnings; use AN::Tools; use Data::Dumper; +no warnings 'recursion'; # Disable buffering. $| = 1; @@ -8575,7 +8576,7 @@ FROM WHERE storcli_drive_group_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8752,7 +8753,7 @@ WHERE storcli_drive_group_uuid = ".$an->data->{sys}{use_db_fh}->quote($storcli_drive_group_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8801,7 +8802,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8855,7 +8856,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -8919,14 +8920,14 @@ FROM WHERE storcli_virtual_drive_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "results", value1 => $results }, file => $THIS_FILE, line => __LINE__}); foreach my $row (@{$results}) @@ -9082,7 +9083,7 @@ WHERE storcli_virtual_drive_uuid = ".$an->data->{sys}{use_db_fh}->quote($storcli_virtual_drive_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9127,7 +9128,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9177,7 +9178,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9238,14 +9239,14 @@ FROM WHERE storcli_bbu_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "results", value1 => $results }, file => $THIS_FILE, line => __LINE__}); foreach my $row (@{$results}) @@ -9380,7 +9381,7 @@ WHERE storcli_bbu_uuid = ".$an->data->{sys}{use_db_fh}->quote($storcli_bbu_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9419,7 +9420,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9463,7 +9464,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9523,14 +9524,14 @@ FROM WHERE storcli_cachevault_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "results", value1 => $results }, file => $THIS_FILE, line => __LINE__}); foreach my $row (@{$results}) @@ -9658,7 +9659,7 @@ WHERE storcli_cachevault_uuid = ".$an->data->{sys}{use_db_fh}->quote($storcli_cachevault_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9695,7 +9696,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9795,14 +9796,14 @@ FROM WHERE storcli_variable_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "results", value1 => $results }, file => $THIS_FILE, line => __LINE__}); foreach my $row (@{$results}) @@ -9916,7 +9917,7 @@ WHERE storcli_variable_uuid = ".$an->data->{sys}{use_db_fh}->quote($storcli_variable_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9949,7 +9950,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -9987,7 +9988,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10044,14 +10045,14 @@ FROM WHERE storcli_controller_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{host_uuid})." ;"; - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); # Do the query against the source DB and loop through the results. my $results = $an->DB->do_db_query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); - $an->Log->entry({log_level => 2, message_key => "an_variables_0001", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0001", message_variables => { name1 => "results", value1 => $results }, file => $THIS_FILE, line => __LINE__}); foreach my $row (@{$results}) @@ -10158,7 +10159,7 @@ AND storcli_controller_uuid = ".$an->data->{sys}{use_db_fh}->quote($storcli_controller_uuid)." ;"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10189,7 +10190,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); @@ -10225,7 +10226,7 @@ INSERT INTO ".$an->data->{sys}{use_db_fh}->quote($modified_date)." );"; # Now record the query in the array - $an->Log->entry({log_level => 2, message_key => "an_variables_0002", message_variables => { + $an->Log->entry({log_level => 3, message_key => "an_variables_0002", message_variables => { name1 => "id", value1 => $id, name2 => "query", value2 => $query }, file => $THIS_FILE, line => __LINE__}); diff --git a/striker.conf b/striker.conf index 0d8462d3..0908a629 100644 --- a/striker.conf +++ b/striker.conf @@ -282,12 +282,12 @@ scancore::enabled = 1 # ScanCore always checks to see how much RAM it is using at the end of a given # scan sweep. This isn't an exact number as it includes all shared libraries. # This is done to catch memory leaks and suicide before it becomes a problem. -# The default is to allow 512 MiB of RAM to be used. However, on some systems +# The default is to allow 1 GiB of RAM to be used. However, on some systems # with a very large number of sensors/scan agent data, a DB resync could cause # the RAM use to climb higher that this. If you find that ScanCore restarts # when a dashboard restarts, then you can increase this value. Please note that # the value is expressed in bytes. -#scancore::maximum_ram = 536870912 +#scancore::maximum_ram = 1073741824 # ScanCore will periodically get started by cron (default is once per minute). # When it starts, it checks to see if another copy is already running. If not, diff --git a/tools/anvil-generate-iso b/tools/anvil-generate-iso index 457fe205..43222d3c 100755 --- a/tools/anvil-generate-iso +++ b/tools/anvil-generate-iso @@ -209,7 +209,7 @@ my $conf = { # git master with '--master', in which case we will download the 'striker_master' URL. In all # cases, the downloaded file will be saved as 'striker_zip_file'. striker => "https://github.com/ClusterLabs/striker.git", - striker_default => "https://github.com/ClusterLabs/striker/archive/2.0.0b-tc4.zip", + striker_default => "https://github.com/ClusterLabs/striker/archive/2.0.0b-tc5.zip", striker_latest => "https://alteeve.ca/striker_latest.txt", striker_master => "https://codeload.github.com/ClusterLabs/striker/zip/master", striker_zip_file => "striker.zip", diff --git a/updates b/updates index 6c0cd6b3..1822d91d 100644 --- a/updates +++ b/updates @@ -20,6 +20,10 @@ DROP FUNCTION history_hosts() CASCADE; CREATE FUNCTION history_hosts() RETURNS trigger AS $$ DECLARE history_hosts RECORD; BEGIN SELECT INTO history_hosts * FROM hosts WHERE host_uuid = new.host_uuid; INSERT INTO history.hosts (host_uuid, host_location_uuid, host_name, host_type, host_emergency_stop, host_stop_reason, host_health, modified_date) VALUES (history_hosts.host_uuid, history_hosts.host_location_uuid, history_hosts.host_name, history_hosts.host_type, history_hosts.host_emergency_stop, history_hosts.host_stop_reason, history_hosts.host_health, history_hosts.modified_date); RETURN NULL; END; $$ LANGUAGE plpgsql; ALTER FUNCTION history_hosts() OWNER TO admin; CREATE TRIGGER trigger_hosts AFTER INSERT OR UPDATE ON hosts FOR EACH ROW EXECUTE PROCEDURE history_hosts(); + +DROP FUNCTION history_states() CASCADE; +DROP TABLE history.states; + COMMIT; -- END