* Fixed a bug in Alert->check_condition_age() where not setting a host_uuid caused the returned age to always be 0.

* Updated scan_apc_pdu to not report a lost PDU unless it's been gone for ten minutes.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 2 years ago
parent 99a6593fe6
commit 89121a2b3b
  1. 2
      Anvil/Tools/Alert.pm
  2. 52
      scancore-agents/scan-apc-pdu/scan-apc-pdu
  3. 1
      share/words.xml

@ -276,7 +276,7 @@ sub check_condition_age
my $clear = defined $parameter->{clear} ? $parameter->{clear} : 0;
my $name = defined $parameter->{name} ? $parameter->{name} : "";
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : "NULL";
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
clear => $clear,
name => $name,

@ -260,7 +260,7 @@ FROM
my $scan_apc_pdu_link_speed = $row->[10];
my $scan_apc_pdu_phase_count = $row->[11];
my $scan_apc_pdu_outlet_count = $row->[12];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
scan_apc_pdu_uuid => $scan_apc_pdu_uuid,
scan_apc_pdu_fence_uuid => $scan_apc_pdu_fence_uuid,
scan_apc_pdu_serial_number => $scan_apc_pdu_serial_number,
@ -1385,6 +1385,7 @@ WHERE
}
# Delete this from the SQL hash so we know it didn't vanish.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0726", variables => { hash_key => "sql::scan_apc_pdu_uuid::${scan_apc_pdu_uuid}" }});
delete $anvil->data->{sql}{scan_apc_pdu_uuid}{$scan_apc_pdu_uuid};
}
else
@ -1596,10 +1597,19 @@ INSERT INTO
scan_apc_pdu_ipv4_address => $scan_apc_pdu_ipv4_address,
}});
if ($scan_apc_pdu_model_number ne "DELETED")
{
# Yup! send an alert.
my $query = "
# The PDUs only allow one connection at a time, so if another scan agent is
# connected, we'll get this issue. As such, check how long it's been missing, and
# alert only if it's been missing for 10 minutes.
my $age = $anvil->Alert->check_condition_age({name => "scan_apc_pdu::lost_pdu::".$scan_apc_pdu_serial_number});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { age => $age }});
if ($age > 600)
{
# Yup! send an alert.
my $query = "
UPDATE
scan_apc_pdus
SET
@ -1608,22 +1618,23 @@ SET
WHERE
scan_apc_pdu_uuid = ".$anvil->Database->quote($scan_apc_pdu_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
push @{$anvil->data->{sys}{queries}}, $query;
my $variables = {
model => $scan_apc_pdu_model_number,
serial_numer => $scan_apc_pdu_serial_number,
ip_address => $scan_apc_pdu_ipv4_address,
};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_apc_pdu_message_0040", variables => $variables});
$anvil->Alert->register({
alert_level => "warning",
message => "scan_apc_pdu_message_0040",
variables => $variables,
set_by => $THIS_FILE,
sort_position => $anvil->data->{'scan-apc-pdu'}{alert_sort}++,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
push @{$anvil->data->{sys}{queries}}, $query;
my $variables = {
model => $scan_apc_pdu_model_number,
serial_numer => $scan_apc_pdu_serial_number,
ip_address => $scan_apc_pdu_ipv4_address,
};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_apc_pdu_message_0040", variables => $variables});
$anvil->Alert->register({
alert_level => "warning",
message => "scan_apc_pdu_message_0040",
variables => $variables,
set_by => $THIS_FILE,
sort_position => $anvil->data->{'scan-apc-pdu'}{alert_sort}++,
});
}
}
}
@ -2003,6 +2014,9 @@ sub gather_pdu_data
# If I got the serial number, I found the PDU.
next if not $scan_apc_pdu_serial_number;
# In case this PDU disappeared before, this will clear that condition.
$anvil->Alert->check_condition_age({clear => 1, name => "scan_apc_pdu::lost_pdu::".$scan_apc_pdu_serial_number});
#############################################################################################
# Base PDU info #

@ -2199,6 +2199,7 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<key name="log_0723">The server: [#!variable!server!#] is configured to stay off, ignoring it.</key>
<key name="log_0724">The file: [#!variable!file!#] needs to be added to the database, but since the last scan it's size grew from: [#!variable!old_size_bytes!# (#!variable!old_size_hr!#)] to: [#!variable!new_size_bytes!# (#!variable!new_size_hr!#)]. A difference of: [#!variable!difference_bytes!# (#!variable!difference_hr!#)]. It might still be being uploaded, so we'll keep checking periodocally until the size stops changing.</key>
<key name="log_0725">Found the missing file: [#!variable!file!#] in the directory: [#!variable!directory!#]. Updating the database now.</key>
<key name="log_0726">Deleting the hash key: [#!variable!hash_key!#].</key>
<!-- Messages for users (less technical than log entries), though sometimes used for logs, too. -->
<key name="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key>

Loading…
Cancel
Save