Updated scan-apc-pdu to remove PDUs that are associated with fence devices that have beed deleted.

Updated scan-network to set a health score against an interface that has been missing for 1 minute, instead of waiting for 5 minutes.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent 3445d008d2
commit 7f1f71dcf0
  1. 113
      scancore-agents/scan-apc-pdu/scan-apc-pdu
  2. 3
      scancore-agents/scan-apc-pdu/scan-apc-pdu.xml
  3. 4
      scancore-agents/scan-network/scan-network

@ -237,7 +237,7 @@ SELECT
FROM FROM
scan_apc_pdus scan_apc_pdus
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
@ -325,7 +325,7 @@ SELECT
FROM FROM
scan_apc_pdu_phases scan_apc_pdu_phases
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
# Do the query against the source DB and loop through the results. # Do the query against the source DB and loop through the results.
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
@ -378,7 +378,7 @@ SELECT
FROM FROM
scan_apc_pdu_outlets scan_apc_pdu_outlets
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results}; $count = @{$results};
@ -406,7 +406,7 @@ FROM
# Which serial number does this phase belong to? # Which serial number does this phase belong to?
my $scan_apc_pdu_serial_number = $anvil->data->{uuid_to_serial}{$scan_apc_pdu_outlet_scan_apc_pdu_uuid}; my $scan_apc_pdu_serial_number = $anvil->data->{uuid_to_serial}{$scan_apc_pdu_outlet_scan_apc_pdu_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { scan_apc_pdu_serial_number => $scan_apc_pdu_serial_number }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { scan_apc_pdu_serial_number => $scan_apc_pdu_serial_number }});
$anvil->data->{sql}{scan_apc_pdu_uuid}{$scan_apc_pdu_outlet_scan_apc_pdu_uuid}{scan_apc_pdu_outlets}{$scan_apc_pdu_outlet_number}{scan_apc_pdu_outlet_uuid} = $scan_apc_pdu_outlet_uuid; $anvil->data->{sql}{scan_apc_pdu_uuid}{$scan_apc_pdu_outlet_scan_apc_pdu_uuid}{scan_apc_pdu_outlets}{$scan_apc_pdu_outlet_number}{scan_apc_pdu_outlet_uuid} = $scan_apc_pdu_outlet_uuid;
$anvil->data->{sql}{scan_apc_pdu_uuid}{$scan_apc_pdu_outlet_scan_apc_pdu_uuid}{scan_apc_pdu_outlets}{$scan_apc_pdu_outlet_number}{scan_apc_pdu_outlet_scan_apc_pdu_uuid} = $scan_apc_pdu_outlet_scan_apc_pdu_uuid; $anvil->data->{sql}{scan_apc_pdu_uuid}{$scan_apc_pdu_outlet_scan_apc_pdu_uuid}{scan_apc_pdu_outlets}{$scan_apc_pdu_outlet_number}{scan_apc_pdu_outlet_scan_apc_pdu_uuid} = $scan_apc_pdu_outlet_scan_apc_pdu_uuid;
@ -434,7 +434,7 @@ SELECT
FROM FROM
scan_apc_pdu_variables scan_apc_pdu_variables
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results}; $count = @{$results};
@ -2590,10 +2590,12 @@ FROM
fences fences
WHERE WHERE
fence_agent LIKE 'fence_apc_%' fence_agent LIKE 'fence_apc_%'
AND
fence_arguments != 'DELETED'
ORDER BY ORDER BY
fence_name ASC fence_name ASC
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
@ -2623,6 +2625,90 @@ ORDER BY
"fences::fence_uuid::${fence_uuid}::name" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{name}, "fences::fence_uuid::${fence_uuid}::name" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{name},
"fences::fence_uuid::${fence_uuid}::ip_address" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{ip_address}, "fences::fence_uuid::${fence_uuid}::ip_address" => $anvil->data->{fences}{fence_uuid}{$fence_uuid}{ip_address},
}}); }});
# If there are two or more entries in scan_apc_pdu for this fence UUID, remove the extras.
my $query = "
SELECT
scan_apc_pdu_uuid,
scan_apc_pdu_model_number
FROM
scan_apc_pdus
WHERE
scan_apc_pdu_fence_uuid = ".$anvil->Database->quote($fence_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
if ($count > 1)
{
# Duplicate! Is one of them marked as DELETED?
foreach my $row (@{$results})
{
# Is this one deleted?
my $scan_apc_pdu_uuid = $row->[0];
my $scan_apc_pdu_model_number = $row->[1];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
scan_apc_pdu_uuid => $scan_apc_pdu_uuid,
scan_apc_pdu_model_number => $scan_apc_pdu_model_number,
}});
if ($scan_apc_pdu_model_number eq "DELETED")
{
# Take this one out.
my $variables = {
name => $fence_name,
uuid => $scan_apc_pdu_uuid,
};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_apc_pdu_log_0002", variables => $variables});
$anvil->Alert->register({
alert_level => "notice",
message => "scan_apc_pdu_log_0002",
variables => $variables,
set_by => $THIS_FILE,
sort_position => $anvil->data->{'scan-apc-pdu'}{alert_sort}++,
});
delete_pdu($anvil, $scan_apc_pdu_uuid);
$count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
}
last if $count == 1;
}
# If count is still > 1, we need to arbitrarily delete an interface.
if ($count > 1)
{
foreach my $row (@{$results})
{
# Is this one deleted?
my $scan_apc_pdu_uuid = $row->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { scan_apc_pdu_uuid => $scan_apc_pdu_uuid }});
my $variables = {
name => $fence_name,
uuid => $scan_apc_pdu_uuid,
};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_apc_pdu_log_0002", variables => $variables});
$anvil->Alert->register({
alert_level => "notice",
message => "scan_apc_pdu_log_0002",
variables => $variables,
set_by => $THIS_FILE,
sort_position => $anvil->data->{'scan-apc-pdu'}{alert_sort}++,
});
delete_pdu($anvil, $scan_apc_pdu_uuid);
$count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
}
last if $count == 1;
}
}
} }
} }
@ -2630,3 +2716,18 @@ ORDER BY
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { pdu_count => $pdu_count }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { pdu_count => $pdu_count }});
return($pdu_count); return($pdu_count);
} }
sub delete_pdu
{
my ($anvil, $scan_apc_pdu_uuid) = @_;
my $queries = [
"DELETE FROM scan_apc_pdu_variables WHERE scan_apc_pdu_variable_scan_apc_pdu_uuid = ".$anvil->Database->quote($scan_apc_pdu_uuid).";",
"DELETE FROM scan_apc_pdu_phases WHERE scan_apc_pdu_phase_scan_apc_pdu_uuid = ".$anvil->Database->quote($scan_apc_pdu_uuid).";",
"DELETE FROM scan_apc_pdu_outlets WHERE scan_apc_pdu_outlet_scan_apc_pdu_uuid = ".$anvil->Database->quote($scan_apc_pdu_uuid).";",
"DELETE FROM scan_apc_pdus WHERE scan_apc_pdu_uuid = ".$anvil->Database->quote($scan_apc_pdu_uuid).";"
];
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
return(0);
}

@ -21,6 +21,7 @@ NOTE: All string keys MUST be prefixed with the agent name! ie: 'scan_apc_pdu_lo
<!-- Log entries --> <!-- Log entries -->
<key name="scan_apc_pdu_log_0001">Starting: [#!variable!program!#].</key> <key name="scan_apc_pdu_log_0001">Starting: [#!variable!program!#].</key>
<key name="scan_apc_pdu_log_0002">[ Note ] - The APC PDU associated with the fence device: [#!variable!name!#] with 'scan_apc_pdu_uuid': [#!variable!uuid!#] is a duplicate, removing it from the database(s).</key>
<!-- Message entries (usually meant to be alerts) --> <!-- Message entries (usually meant to be alerts) -->
<key name="scan_apc_pdu_message_0001">No APC PDUs found as configured fence devices, nothing to do.</key> <key name="scan_apc_pdu_message_0001">No APC PDUs found as configured fence devices, nothing to do.</key>
@ -44,7 +45,7 @@ NOTE: All string keys MUST be prefixed with the agent name! ie: 'scan_apc_pdu_lo
<key name="scan_apc_pdu_message_0019">The PDU: [#!variable!name!#] appears to have rebooted. The uptime changed from; [#!variable!old_uptime!#] to: [#!variable!new_uptime!#]. Was the power restored after a power outage?</key> <key name="scan_apc_pdu_message_0019">The PDU: [#!variable!name!#] appears to have rebooted. The uptime changed from; [#!variable!old_uptime!#] to: [#!variable!new_uptime!#]. Was the power restored after a power outage?</key>
<key name="scan_apc_pdu_message_0020">The wattage draw through the PDU: [#!variable!name!#] has changed from: [#!variable!old_total_wattage_draw!#] to: [#!variable!new_total_wattage_draw!#].</key> <key name="scan_apc_pdu_message_0020">The wattage draw through the PDU: [#!variable!name!#] has changed from: [#!variable!old_total_wattage_draw!#] to: [#!variable!new_total_wattage_draw!#].</key>
<key name="scan_apc_pdu_message_0021">The phase number: [#!variable!phase!#] on the PDU: [#!variable!name!#] has returned.</key> <key name="scan_apc_pdu_message_0021">The phase number: [#!variable!phase!#] on the PDU: [#!variable!name!#] has returned.</key>
<key name="scan_apc_pdu_message_0022">The maximum amperage threshold on the phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] has changed from: [#!variable!old_phase_max_amperage#] to: [#!variable!new_phase_max_amperage!#].</key> <key name="scan_apc_pdu_message_0022">The maximum amperage threshold on the phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] has changed from: [#!variable!old_phase_max_amperage!#] to: [#!variable!new_phase_max_amperage!#].</key>
<key name="scan_apc_pdu_message_0023">The amperage draw on phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] has changed from: [#!variable!old_phase_current_amperage!#] to: [#!variable!new_phase_current_amperage!#].</key> <key name="scan_apc_pdu_message_0023">The amperage draw on phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] has changed from: [#!variable!old_phase_current_amperage!#] to: [#!variable!new_phase_current_amperage!#].</key>
<key name="scan_apc_pdu_message_0024">The amperage drawing through the phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] is below the low-warning threshold. This is not a concern for the Anvil!, but would only happen if a user configured a low draw alert. So this could be a concern to a user of this Anvil! system.</key> <key name="scan_apc_pdu_message_0024">The amperage drawing through the phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] is below the low-warning threshold. This is not a concern for the Anvil!, but would only happen if a user configured a low draw alert. So this could be a concern to a user of this Anvil! system.</key>
<key name="scan_apc_pdu_message_0025">The amperage drawing through the phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] has rised over the high critical alert threshold!</key> <key name="scan_apc_pdu_message_0025">The amperage drawing through the phase: [#!variable!phase!#] of the PDU: [#!variable!name!#] has rised over the high critical alert threshold!</key>

@ -3437,14 +3437,14 @@ AND
} }
else else
{ {
# Has the interface been down for at least a minute?
my $age = $anvil->Alert->check_condition_age({ my $age = $anvil->Alert->check_condition_age({
debug => 2, debug => 2,
name => $source_name, name => $source_name,
host_uuid => $anvil->Get->host_uuid, host_uuid => $anvil->Get->host_uuid,
}); });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { age => $age }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { age => $age }});
if ($age > 60)
if ($age > 300)
{ {
# New, save. # New, save.
my ($health_uuid) = $anvil->Database->insert_or_update_health({ my ($health_uuid) = $anvil->Database->insert_or_update_health({

Loading…
Cancel
Save