parent
7856de4bbb
commit
ea33ba07ca
|
@ -179,36 +179,42 @@ class StatusUpdater
|
||||||
$max_runs = 1;
|
$max_runs = 1;
|
||||||
}
|
}
|
||||||
$result = null;
|
$result = null;
|
||||||
// Execute ping
|
// Choose right ping version, ping6 for IPV6, ping for IPV4
|
||||||
$pingCommand = 'ping6';
|
$pingCommand = 'ping6';
|
||||||
$serverIp = $this->server['ip'];
|
$serverIp = $this->server['ip'];
|
||||||
if (filter_var($serverIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
|
if (filter_var($serverIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
|
||||||
$pingCommand = 'ping';
|
$pingCommand = 'ping';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// execute PING
|
||||||
$txt = exec($pingCommand . " -c " . $max_runs . " " . $serverIp . " 2>&1", $output);
|
$txt = exec($pingCommand . " -c " . $max_runs . " " . $serverIp . " 2>&1", $output);
|
||||||
// Non-greedy match on filler
|
|
||||||
$re1 = '.*?';
|
// Check if output is PING and if transmitted packets is equal to received packets.
|
||||||
// Uninteresting: float
|
preg_match('/^(\d{1,3}) packets transmitted, (\d{1,3}).*$/', $output[count($output) - 2], $output_package_loss);
|
||||||
$re2 = '[+-]?\\d*\\.\\d+(?![-+0-9\\.])';
|
|
||||||
// Non-greedy match on filler
|
if (
|
||||||
$re3 = '.*?';
|
substr($output[0], 0, 4) == 'PING' &&
|
||||||
// Float 1
|
!empty($output_package_loss) &&
|
||||||
$re4 = '([+-]?\\d*\\.\\d+)(?![-+0-9\\.])';
|
$output_package_loss[1] === $output_package_loss[2]
|
||||||
if (preg_match_all("/" . $re1 . $re2 . $re3 . $re4 . "/is", $txt, $matches)) {
|
) {
|
||||||
$result = $matches[1][0];
|
// Gets avg from 'round-trip min/avg/max/stddev = 7.109/7.109/7.109/0.000 ms'
|
||||||
}
|
preg_match_all("/(\d+\.\d+)/", $output[count($output) - 1], $result);
|
||||||
if (substr($output[0], 0, 4) == 'PING' && strpos($output[count($output) - 2], 'packets transmitted')) {
|
$result = floatval($result[0][1]);
|
||||||
$result = 0;
|
|
||||||
}
|
$this->header = "";
|
||||||
if (!is_null($result)) {
|
foreach ($output as $key => $value) {
|
||||||
$this->header = $output[0];
|
$this->header .= $value . "\n";
|
||||||
|
}
|
||||||
$status = true;
|
$status = true;
|
||||||
} else {
|
} else {
|
||||||
$this->header = "-";
|
$this->header = "-";
|
||||||
$this->error = $output[0];
|
foreach ($output as $key => $value) {
|
||||||
|
$this->header .= $value . "\n";
|
||||||
|
}
|
||||||
|
$this->error = $output[count($output) - 2];
|
||||||
$status = false;
|
$status = false;
|
||||||
}
|
}
|
||||||
//Divide by a thousand to convert to milliseconds
|
// To miliseconds
|
||||||
$this->rtime = $result / 1000;
|
$this->rtime = $result / 1000;
|
||||||
|
|
||||||
// check if server is available and rerun if asked.
|
// check if server is available and rerun if asked.
|
||||||
|
|
Loading…
Reference in New Issue