mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Availability Calculation for all Devices (#12004)
* Availability Calculation for all Devices * remove not more need uptime column
This commit is contained in:
@@ -2125,35 +2125,33 @@ function device_is_up($device, $record_perf = false)
|
||||
array($device['device_id'])
|
||||
);
|
||||
|
||||
$uptime = $device['uptime'] ?: 0;
|
||||
|
||||
if ($response['status']) {
|
||||
$type = 'up';
|
||||
$reason = $device['status_reason'];
|
||||
|
||||
if ($device['uptime']) {
|
||||
$going_down = dbFetchCell('SELECT going_down FROM device_outages WHERE device_id=? AND up_again IS NULL', array($device['device_id']));
|
||||
if (!empty($going_down)) {
|
||||
$up_again = time() - $device['uptime'];
|
||||
if ($up_again <= $going_down) {
|
||||
# network connection loss, not device down
|
||||
$up_again = time();
|
||||
}
|
||||
dbUpdate(
|
||||
array('device_id' => $device['device_id'], 'up_again' => $up_again),
|
||||
'device_outages',
|
||||
'device_id=? and up_again is NULL',
|
||||
array($device['device_id'])
|
||||
);
|
||||
$going_down = dbFetchCell('SELECT going_down FROM device_outages WHERE device_id=? AND up_again IS NULL', array($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();
|
||||
}
|
||||
dbUpdate(
|
||||
array('device_id' => $device['device_id'], 'up_again' => $up_again),
|
||||
'device_outages',
|
||||
'device_id=? and up_again is NULL',
|
||||
array($device['device_id'])
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$type = 'down';
|
||||
$reason = $response['status_reason'];
|
||||
if ($device['uptime']) {
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'uptime' => $device['uptime'],
|
||||
'going_down' => strtotime($device['last_polled'])];
|
||||
dbInsert($data, 'device_outages');
|
||||
}
|
||||
|
||||
$data = ['device_id' => $device['device_id'],
|
||||
'going_down' => strtotime($device['last_polled'])];
|
||||
dbInsert($data, 'device_outages');
|
||||
}
|
||||
|
||||
log_event('Device status changed to ' . ucfirst($type) . " from $reason check.", $device, $type);
|
||||
|
||||
Reference in New Issue
Block a user