From a1604344c7db64f268984945cabf72a032e75797 Mon Sep 17 00:00:00 2001 From: Digimer Date: Thu, 7 Oct 2021 22:08:34 -0400 Subject: [PATCH] * Fixed a bug in Convert->round where numbers with exponents were not handled properly. * Fixed a bug in scan-hardware where the raw bytes free for swap was used to see if the high / cleared thresholds were passed, instead of the percentage as it should have been. * Fixed a bug in scan-network where a new-line wasn't be cleared off the MAC address. Signed-off-by: Digimer --- Anvil/Tools/Convert.pm | 3 +++ scancore-agents/scan-hardware/scan-hardware | 21 ++++++++++++++++++--- scancore-agents/scan-network/scan-network | 3 ++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Anvil/Tools/Convert.pm b/Anvil/Tools/Convert.pm index f5a619bd..28c50483 100644 --- a/Anvil/Tools/Convert.pm +++ b/Anvil/Tools/Convert.pm @@ -1197,6 +1197,9 @@ sub round # Return if the user passed a double-dash. return('--') if $number eq "--"; + # Take out exponent notation + $number =~ s/e-\d+$//; + # Make a copy of the passed number that I can manipulate. my $rounded_number = $number; diff --git a/scancore-agents/scan-hardware/scan-hardware b/scancore-agents/scan-hardware/scan-hardware index aaf3734c..9f5ee0d5 100755 --- a/scancore-agents/scan-hardware/scan-hardware +++ b/scancore-agents/scan-hardware/scan-hardware @@ -632,6 +632,11 @@ sub find_changes my $new_scan_hardware_memory_free = $anvil->data->{summary}{ram}{proc}{memory_free}; my $new_scan_hardware_swap_total = $anvil->data->{summary}{ram}{proc}{swap_total}; my $new_scan_hardware_swap_free = $anvil->data->{summary}{ram}{proc}{swap_free}; + my $new_scan_hardware_swap_used = $new_scan_hardware_swap_total - $new_scan_hardware_swap_free; + my $new_swap_used_percentage = $anvil->Convert->round({ + number => (($new_scan_hardware_swap_used / $new_scan_hardware_swap_total) * 100), + places => 0, + }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "new_scan_hardware_cpu_model" => $new_scan_hardware_cpu_model, "new_scan_hardware_cpu_cores" => $new_scan_hardware_cpu_cores, @@ -646,6 +651,8 @@ sub find_changes "new_scan_hardware_memory_free" => $anvil->Convert->add_commas({number => $new_scan_hardware_memory_free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $new_scan_hardware_memory_free}).")", "new_scan_hardware_swap_total" => $anvil->Convert->add_commas({number => $new_scan_hardware_swap_total})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $new_scan_hardware_swap_total}).")", "new_scan_hardware_swap_free" => $anvil->Convert->add_commas({number => $new_scan_hardware_swap_free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $new_scan_hardware_swap_free}).")", + "new_scan_hardware_swap_used" => $anvil->Convert->add_commas({number => $new_scan_hardware_swap_used})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $new_scan_hardware_swap_used}).")", + "new_swap_used_percentage" => $new_swap_used_percentage."%", }}); # The LED status needs to be translated. @@ -901,12 +908,16 @@ sub find_changes if ($new_scan_hardware_memory_free ne $old_scan_hardware_memory_free) { # This always changes, so it's an info-level alert - $update = 1; + $update = 1; my $say_new_scan_hardware_memory_free = $anvil->Convert->bytes_to_human_readable({'bytes' => $new_scan_hardware_memory_free})." (".$anvil->Convert->add_commas({number => $new_scan_hardware_memory_free})." #!string!scan_hardware_unit_0001!#)"; my $say_old_scan_hardware_memory_free = $anvil->Convert->bytes_to_human_readable({'bytes' => $old_scan_hardware_memory_free})." (".$anvil->Convert->add_commas({number => $old_scan_hardware_memory_free})." #!string!scan_hardware_unit_0001!#)"; $anvil->Alert->register({set_by => $THIS_FILE, alert_level => "info", message => "scan_hardware_alert_0018,!!new!".$say_new_scan_hardware_memory_free."!!,!!old!".$say_old_scan_hardware_memory_free."!!"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_hardware_alert_0018", variables => { new => $say_new_scan_hardware_memory_free, old => $say_old_scan_hardware_memory_free}}); } + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + new_scan_hardware_swap_free => $new_scan_hardware_swap_free, + old_scan_hardware_swap_free => $old_scan_hardware_swap_free, + }}); if ($new_scan_hardware_swap_free ne $old_scan_hardware_swap_free) { $update = 1; @@ -932,7 +943,11 @@ sub find_changes # Check if swap has gone over the high threshold or dropped below the clear # threashold. - if ($new_scan_hardware_swap_free > $anvil->data->{scancore}{'scan-hardware'}{swap}{high_threshold}) + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + new_scan_hardware_swap_free => $new_scan_hardware_swap_free, + "scancore::scan-hardware::swap::high_threshold" => $anvil->data->{scancore}{'scan-hardware'}{swap}{high_threshold}, + }}); + if ($new_swap_used_percentage > $anvil->data->{scancore}{'scan-hardware'}{swap}{high_threshold}) { # It's high my $changed = $anvil->Alert->check_alert_sent({ @@ -955,7 +970,7 @@ sub find_changes $anvil->Alert->register({alert_level => "notice", message => "scan_hardware_alert_0020", variables => $variables, set_by => $THIS_FILE }); } } - elsif ($new_scan_hardware_swap_free < $anvil->data->{scancore}{'scan-hardware'}{swap}{clear_threshold}) + elsif ($new_swap_used_percentage < $anvil->data->{scancore}{'scan-hardware'}{swap}{clear_threshold}) { # It's low my $changed = $anvil->Alert->check_alert_sent({ diff --git a/scancore-agents/scan-network/scan-network b/scancore-agents/scan-network/scan-network index c66fc286..72acd10a 100755 --- a/scancore-agents/scan-network/scan-network +++ b/scancore-agents/scan-network/scan-network @@ -227,7 +227,8 @@ sub collect_data } elsif (-e $full_path."/address") { - $mac_address = $anvil->Storage->read_file({file => $full_path."/address"}); + $mac_address = $anvil->Storage->read_file({file => $full_path."/address"}); + $mac_address =~ s/\n//; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }}); } }