Skip to content

Commit c91010c

Browse files
authored
Prevent multiple outages (librenms#18138)
Previous code could have multiple open outages. Do not trust previous status and just check for an open outage every time. Close all open outages if a device is up to rectify previously left open outages. If ignoring maintenance, ignore all types of maintenance
1 parent 0da6a5e commit c91010c

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

LibreNMS/Polling/ConnectivityHelper.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public function saveMetrics(): void
7676
*/
7777
public function isUp(): bool
7878
{
79-
$previous = $this->device->status;
8079
$ping_response = $this->isPingable();
8180

8281
// calculate device status
@@ -100,7 +99,7 @@ public function isUp(): bool
10099
if ($this->canPing()) {
101100
$ping_response->saveStats($this->device);
102101
}
103-
$this->updateAvailability($previous, $this->device->status);
102+
$this->updateAvailability($this->device->status);
104103

105104
$this->device->save(); // confirm device is saved
106105
}
@@ -170,25 +169,26 @@ public function ipFamily(): string
170169
return $this->family;
171170
}
172171

173-
private function updateAvailability(bool $previous, bool $status): void
172+
private function updateAvailability(bool $current_status): void
174173
{
175-
// skip update if we are considering maintenance and skipping alerts
174+
// skip update if we are considering maintenance
176175
if (LibrenmsConfig::get('graphing.availability_consider_maintenance')
177-
&& $this->device->getMaintenanceStatus() == MaintenanceStatus::SKIP_ALERTS) {
176+
&& $this->device->getMaintenanceStatus() !== MaintenanceStatus::NONE) {
178177
return;
179178
}
180179

181-
// check for open outage
182-
$open_outage = $this->device->getCurrentOutage();
180+
if ($current_status) {
181+
// Device is up, close any open outages
182+
$this->device->outages()->whereNull('up_again')->get()->each(function (DeviceOutage $outage) {
183+
$outage->up_again = time();
184+
$outage->save();
185+
});
183186

184-
if ($status) {
185-
if ($open_outage) {
186-
$open_outage->up_again = time();
187-
$open_outage->save();
188-
}
189-
} elseif ($previous || $open_outage === null) {
190-
// status changed from up to down or there is no open outage
191-
// open new outage
187+
return;
188+
}
189+
190+
// Device is down, only open a new outage if none is currently open
191+
if ($this->device->getCurrentOutage() === null) {
192192
$this->device->outages()->save(new DeviceOutage(['going_down' => time()]));
193193
}
194194
}

0 commit comments

Comments
 (0)