Skip to content
Snippets Groups Projects
Commit 9c804005 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

fixed count file

parent 47598c2b
No related branches found
No related tags found
2 merge requests!1568Development,!1566Resolve "Count Script is missing a value"
...@@ -43,28 +43,37 @@ class ConvertCountFile implements ShouldQueue ...@@ -43,28 +43,37 @@ class ConvertCountFile implements ShouldQueue
try { try {
$fh = fopen($this->files["logFile"], "r"); $fh = fopen($this->files["logFile"], "r");
$currentLogTime = Carbon::now()->hour(0)->minute(0)->second(0)->addMinutes(5); $currentLogTime = Carbon::now()->hour(0)->minute(0)->second(0)->addMinutes(5);
while ($fh !== false && ($line = fgets($fh)) !== false) { while ($fh !== false && ($line = fgets($fh)) !== false) {
$logTime = []; $logTime = [];
$interface = ""; $interface = "";
// i.e. [Wed Apr 17 00:00:01] ref=https://metager.de/ time=0.51 serv=web interface=de // i.e. [Wed Apr 17 00:00:01] ref=https://metager.de/ time=0.51 serv=web interface=de
if (preg_match('/(\d{2}:\d{2}:\d{2}).*?\sinterface=(\S+)/', $line, $matches)) { if (preg_match('/(\d{2}:\d{2}:\d{2}).*?\sinterface=(\S+)/', $line, $matches)) {
// Create Date Object // Create Date Object
$logTime = explode(":", $matches[1]); $logTime = $matches[1];
$interface = $matches[2]; $interface = $matches[2];
} else if (preg_match('/\[[a-zA-z]{3},\s\d{2}\s[a-zA-Z]{3}\s\d{2}\s(\d{2}:\d{2}:\d{2})/', $line, $matches)) {
$logTime = explode(":", $matches[1]);
} else if (preg_match('/\[\d{2}\/\d{2}\/\d{4}:(\d{2}:\d{2}:\d{2})/', $line, $matches)) {
$logTime = explode(":", $matches[1]);
} else { } else {
continue; continue;
} }
$thatTime = \DateTime::createFromFormat('H:i:s', $logTime);
$thatTime->sub(new \DateInterval("PT" . ($thatTime->format('i') % 5) . "M"));
while (!$fullRound && ((intval($logTime[0]) * 60) + intval($logTime[1])) > (($currentLogTime->hour * 60) + $currentLogTime->minute)) { if(empty($result["time"][$thatTime->format('H:i')])){
$result["time"][$currentLogTime->format('H:i')] = $result["insgesamt"]; $result["time"][$thatTime->format('H:i')] = [
$currentLogTime->addMinutes(5); "insgesamt" => [
if ($currentLogTime->hour === 0 && $currentLogTime->minute === 0) { "all" => 0,
$fullRound = true; ],
];
}
if(empty($result["time"][$thatTime->format('H:i')]["all"])){
$result["time"][$thatTime->format('H:i')]["all"] = 1;
}else{
$result["time"][$thatTime->format('H:i')]["all"]++;
}
if (!empty($interface)) {
if(empty($result["time"][$thatTime->format('H:i')][$interface])){
$result["time"][$thatTime->format('H:i')][$interface] = 1;
}else{
$result["time"][$thatTime->format('H:i')][$interface]++;
} }
} }
// Update the total statistics // Update the total statistics
...@@ -81,10 +90,6 @@ class ConvertCountFile implements ShouldQueue ...@@ -81,10 +90,6 @@ class ConvertCountFile implements ShouldQueue
} }
} }
} }
if (empty($result["time"][$currentLogTime->format('H:i')])) {
$result["time"][$currentLogTime->format('H:i')] = $result["insgesamt"];
}
} catch (\ErrorException $e) { } catch (\ErrorException $e) {
$error = true; $error = true;
} finally { } finally {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment