mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Optional availability calculation mode to allow planned maintenance (#12218)
* Add an optional availability calculation mode * Style fixes * Review fixes * Variable fix * Style fixes * Style fixes * Style fixes * Add additional status check, remove uptime * Style fix * Style fix * Fix extra database update * Style fix * Style fix
This commit is contained in:
@@ -2000,6 +2000,9 @@ function device_is_up($device, $record_perf = false)
|
||||
$device_perf = $ping_response['db'];
|
||||
$device_perf['device_id'] = $device['device_id'];
|
||||
$device_perf['timestamp'] = ['NOW()'];
|
||||
$maintenance = DeviceCache::get($device['device_id'])->isUnderMaintenance();
|
||||
$consider_maintenance = Config::get('graphing.availability_consider_maintenance');
|
||||
$state_update_again = false;
|
||||
|
||||
if ($record_perf === true && can_ping_device($device['attribs'])) {
|
||||
$trace_debug = [];
|
||||
@@ -2036,15 +2039,20 @@ function device_is_up($device, $record_perf = false)
|
||||
$response['status_reason'] = 'icmp';
|
||||
}
|
||||
|
||||
if ($device['status'] != $response['status'] || $device['status_reason'] != $response['status_reason']) {
|
||||
dbUpdate(
|
||||
['status' => $response['status'], 'status_reason' => $response['status_reason']],
|
||||
'devices',
|
||||
'device_id=?',
|
||||
[$device['device_id']]
|
||||
);
|
||||
// Special case where the device is still down, optional mode is on, device not in maintenance mode and has no ongoing outages
|
||||
if (($consider_maintenance && ! $maintenance) && ($device['status'] == '0' && $response['status'] == '0')) {
|
||||
$state_update_again = empty(dbFetchCell('SELECT going_down FROM device_outages WHERE device_id=? AND up_again IS NULL ORDER BY going_down DESC', [$device['device_id']]));
|
||||
}
|
||||
|
||||
$uptime = $device['uptime'] ?: 0;
|
||||
if ($device['status'] != $response['status'] || $device['status_reason'] != $response['status_reason'] || $state_update_again) {
|
||||
if (! $state_update_again) {
|
||||
dbUpdate(
|
||||
['status' => $response['status'], 'status_reason' => $response['status_reason']],
|
||||
'devices',
|
||||
'device_id=?',
|
||||
[$device['device_id']]
|
||||
);
|
||||
}
|
||||
|
||||
if ($response['status']) {
|
||||
$type = 'up';
|
||||
@@ -2052,11 +2060,7 @@ function device_is_up($device, $record_perf = false)
|
||||
|
||||
$going_down = dbFetchCell('SELECT going_down FROM device_outages WHERE device_id=? AND up_again IS NULL ORDER BY going_down DESC', [$device['device_id']]);
|
||||
if (! empty($going_down)) {
|
||||
$up_again = time() - $uptime;
|
||||
if ($up_again <= $going_down) {
|
||||
// network connection loss, not device down
|
||||
$up_again = time();
|
||||
}
|
||||
$up_again = time();
|
||||
dbUpdate(
|
||||
['device_id' => $device['device_id'], 'up_again' => $up_again],
|
||||
'device_outages',
|
||||
@@ -2068,9 +2072,12 @@ function device_is_up($device, $record_perf = false)
|
||||
$type = 'down';
|
||||
$reason = $response['status_reason'];
|
||||
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'going_down' => strtotime($device['last_polled']), ];
|
||||
dbInsert($data, 'device_outages');
|
||||
if (! $consider_maintenance || (! $maintenance && $consider_maintenance)) {
|
||||
// use current time as a starting point when an outage starts
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'going_down' => time(), ];
|
||||
dbInsert($data, 'device_outages');
|
||||
}
|
||||
}
|
||||
|
||||
log_event('Device status changed to ' . ucfirst($type) . " from $reason check.", $device, $type);
|
||||
|
@@ -1261,7 +1261,7 @@
|
||||
"graphing.availability": {
|
||||
"group": "poller",
|
||||
"section": "availability",
|
||||
"order": 10,
|
||||
"order": 1,
|
||||
"default": [
|
||||
"86400",
|
||||
"604800",
|
||||
@@ -1270,6 +1270,13 @@
|
||||
],
|
||||
"type": "array"
|
||||
},
|
||||
"graphing.availability_consider_maintenance": {
|
||||
"group": "poller",
|
||||
"section": "availability",
|
||||
"order": 2,
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"dot": {
|
||||
"default": "/usr/bin/dot",
|
||||
"type": "executable"
|
||||
|
@@ -688,6 +688,10 @@ return [
|
||||
'description' => 'Duration',
|
||||
'help' => 'Calculate Device Availability for listed durations. (Durations are defined in seconds)',
|
||||
],
|
||||
'availability_consider_maintenance' => [
|
||||
'description' => 'Scheduled maintenance does not affect availability',
|
||||
'help' => 'Disables the creation of outages and decreasing of availability for devices which are in maintenance mode.',
|
||||
],
|
||||
],
|
||||
'graylog' => [
|
||||
'base_uri' => [
|
||||
|
Reference in New Issue
Block a user