Fix ping.php skipped results (#14368)

* Update PingCheck.php

* Update PingCheck.php

* Update phpstan-baseline.neon

* Update PingCheck.php

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
sembeek
2022-09-19 22:10:26 +02:00
committed by GitHub
parent 27a19039dc
commit 4e1f958e16
2 changed files with 23 additions and 33 deletions

View File

@@ -119,20 +119,24 @@ class PingCheck implements ShouldQueue
if (Process::ERR === $type) {
// Check for devices we couldn't resolve dns for
if (preg_match('/^(?<hostname>[^\s]+): (?:Name or service not known|Temporary failure in name resolution)/', $line, $errored)) {
$this->recordData([
'hostname' => $errored['hostname'],
'status' => 'unreachable',
]);
$this->recordData($errored['hostname'], 'unreachable');
}
continue;
}
if (preg_match(
'/^(?<hostname>[^\s]+) is (?<status>alive|unreachable)(?: \((?<rtt>[\d.]+) ms\))?/',
dump($line);
if (preg_match_all(
'/^(?<hostname>[^\s]+) is (?<status>alive|unreachable)(?: \((?<rtt>[\d.]+) ms\))?/m',
$line,
$captured
)) {
$this->recordData($captured);
foreach ($captured[0] as $index => $matched) {
$this->recordData(
$captured['hostname'][$index],
$captured['status'][$index],
$captured['rtt'][$index] ?: 0
);
}
$this->processTier();
}
@@ -214,7 +218,7 @@ class PingCheck implements ShouldQueue
// update and remove devices in the current tier
foreach ($this->deferred->pull($this->current_tier, []) as $data) {
$this->recordData($data);
$this->recordData(...$data);
}
// try to process the new tier in case we took care of all the devices
@@ -224,17 +228,16 @@ class PingCheck implements ShouldQueue
/**
* If the device is on the current tier, record the data and remove it
* $data should have keys: hostname, status, and conditionally rtt
*
* @param array $data
*/
private function recordData(array $data)
private function recordData(string $hostname, string $status, float $rtt = 0): void
{
dump(get_defined_vars());
if (Debug::isVerbose()) {
echo "Attempting to record data for {$data['hostname']}... ";
echo "Attempting to record data for $hostname... ";
}
/** @var Device $device */
$device = $this->devices->get($data['hostname']);
$device = $this->devices->get($hostname);
// process the data if this is a standalone device or in the current tier
if ($device->max_depth === 0 || $this->current->has($device->hostname)) {
@@ -243,9 +246,9 @@ class PingCheck implements ShouldQueue
}
// mark up only if snmp is not down too
$device->status = ($data['status'] == 'alive' && $device->status_reason != 'snmp');
$device->status = ($status == 'alive' && $device->status_reason != 'snmp');
$device->last_ping = Carbon::now();
$device->last_ping_timetaken = isset($data['rtt']) ? $data['rtt'] : 0;
$device->last_ping_timetaken = $rtt;
if ($device->isDirty('status')) {
// if changed, update reason
@@ -273,7 +276,7 @@ class PingCheck implements ShouldQueue
echo "Deferred\n";
}
$this->defer($data);
$this->defer($hostname, $status, $rtt);
}
}
@@ -290,23 +293,20 @@ class PingCheck implements ShouldQueue
/**
* Defer this data processing until all parent devices are complete
*
*
* @param array $data
*/
private function defer(array $data)
private function defer(string $hostname, string $status, float $rtt): void
{
$device = $this->devices->get($data['hostname']);
$device = $this->devices->get($hostname);
if ($this->deferred->has($device->max_depth)) {
// add this data to the proper tier, unless it already exists...
$tier = $this->deferred->get($device->max_depth);
if (! $tier->has($device->hostname)) {
$tier->put($device->hostname, $data);
$tier->put($device->hostname, [$hostname, $status, $rtt]);
}
} else {
// create a new tier containing this data
$this->deferred->put($device->max_depth, collect([$device->hostname => $data]));
$this->deferred->put($device->max_depth, collect([$device->hostname => [$hostname, $status, $rtt]]));
}
}
}

View File

@@ -7825,11 +7825,6 @@ parameters:
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Method App\\\\Jobs\\\\PingCheck\\:\\:defer\\(\\) has no return type specified\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Method App\\\\Jobs\\\\PingCheck\\:\\:fetchDevices\\(\\) has no return type specified\\.$#"
count: 1
@@ -7840,11 +7835,6 @@ parameters:
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Method App\\\\Jobs\\\\PingCheck\\:\\:recordData\\(\\) has no return type specified\\.$#"
count: 1
path: app/Jobs/PingCheck.php
-
message: "#^Property App\\\\Jobs\\\\PingCheck\\:\\:\\$command has no type specified\\.$#"
count: 1