From 7df378d794b466eae31864dbc5c1b56b8d319088 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Tue, 28 Jul 2020 15:40:48 +0200 Subject: [PATCH] Device Log to Server Log --- app/api/EndpointsApi.php | 18 ++++++++++++++---- app/api/UpdatesApi.php | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/api/EndpointsApi.php b/app/api/EndpointsApi.php index bc645cd..85e17fd 100644 --- a/app/api/EndpointsApi.php +++ b/app/api/EndpointsApi.php @@ -8,9 +8,8 @@ class EndpointsApi extends ApiController{ $command = "null"; //Log - $logManager = new LogManager(); - $logManager->setLevel(LOGLEVEL); $logManager = new LogManager('../logs/api/'. date("Y-m-d").'.log'); + $logManager->setLevel(LOGLEVEL); //Token Checks if ($obj['token'] == null || !isset($obj['token'])) { @@ -62,7 +61,7 @@ class EndpointsApi extends ApiController{ ], 401); } - //Diagnostic/Log Data Save + //Diagnostic if (isset($obj['settings'])){ $data = ['mac' => $obj['settings']["network"]["mac"], 'ip_address' => $obj['settings']["network"]["ip"]]; if (array_key_exists("firmware_hash", $obj['settings'])) { @@ -75,6 +74,16 @@ class EndpointsApi extends ApiController{ ], 200); } + //Log Data Save + if (isset($obj['logs'])){ + foreach ($deviceLogs as $log) { + $logManager = new LogManager('../logs/devices/'. date("Y-m-d").'.log'); + $logManager->setLevel(LOGLEVEL); + $logManager->write("[Device Log Msg] Device_ID " . $deviceId . "->" . $log, LogRecordType::ERROR); + unset($logManager); + } + } + // Issuing command if ($command == "null"){ $device = DeviceManager::getDeviceByToken($obj['token']); @@ -148,7 +157,7 @@ class EndpointsApi extends ApiController{ } } else { if (count(SubDeviceManager::getAllSubDevices($deviceId)) == 0) { - SubDeviceManager::create($deviceId, 'on/off', UNITS[$key]); + //SubDeviceManager::create($deviceId, 'on/off', UNITS[$key]); //RecordManager::create($deviceId, 'on/off', 0); } @@ -177,5 +186,6 @@ class EndpointsApi extends ApiController{ $this->response($jsonAnswer); // this method returns response as json + unset($logManager) } } diff --git a/app/api/UpdatesApi.php b/app/api/UpdatesApi.php index 32a26fc..91269a7 100644 --- a/app/api/UpdatesApi.php +++ b/app/api/UpdatesApi.php @@ -13,7 +13,7 @@ class UpdatesApi { header('Content-type: text/plain; charset=utf8', true); $logManager = new LogManager('../logs/ota/'. date("Y-m-d").'.log'); $logManager->setLevel(LOGLEVEL); - $logManager->write("[Updater] Client Connected", LogRecordTypes::WARNING); + $logManager->write("[Updater] Client Connected", LogRecordTypes::INFO); //Filtrování IP adress @@ -42,7 +42,7 @@ class UpdatesApi { $deviceName = $device['name']; $deviceId = $device['device_id']; //logfile write - $logManager->write("[Device] device_ID " . $deviceId . " was just updated to new version", LogRecordTypes::WARNING); + $logManager->write("[Device] device_ID " . $deviceId . " was just updated to new version", LogRecordTypes::INFO); $logManager->write("[Device] version hash: " . md5_file($localBinary), LogRecordTypes::INFO); //notification $notificationMng = new NotificationManager;