Fix bug of alerting by ping.php (#9311)

* Fix bug of alert by ping.php.

Fix bug of alert by ping.php.
Please refer to the Help ticket for more information:
https://community.librenms.org/t/please-help-with-for-fast-ping-checks-problems/5586
This commit is contained in:
Roger
2018-10-12 23:26:16 +11:00
committed by Tony Murray
parent 44747fda25
commit 36e2467434

View File

@@ -244,16 +244,20 @@ class PingCheck implements ShouldQueue
$device->last_ping = Carbon::now();
$device->last_ping_timetaken = isset($data['rtt']) ? $data['rtt'] : 0;
if ($device->isDirty('status')) {
if ($changed = $device->isDirty('status')) {
// if changed, update reason
$device->status_reason = $device->status ? '' : 'icmp';
$type = $device->status ? 'up' : 'down';
log_event('Device status changed to ' . ucfirst($type) . " from icmp check.", $device->toArray(), $type);
log_event('Device status changed to ' . ucfirst($type) . " from icmp check.", $device->toArray(), $type);
echo "Device $device->hostname changed status to $type, running alerts\n";
}
$device->save();
if ($changed) {
RunRules($device->device_id);
}
$device->save(); // only saves if needed (which is every time because of last_ping)
// add data to rrd
data_update($device->toArray(), 'ping-perf', $this->rrd_tags, ['ping' => $device->last_ping_timetaken]);