From beeb9edeec5e1afb34e131c27c69597d0ef72a42 Mon Sep 17 00:00:00 2001 From: jhartworks Date: Fri, 4 Jul 2025 13:27:04 +0200 Subject: [PATCH] Timmer corrected --- Monitoring Server Influx V1/module.php | 166 ++++++++++++------------- library.json | 2 +- 2 files changed, 84 insertions(+), 84 deletions(-) diff --git a/Monitoring Server Influx V1/module.php b/Monitoring Server Influx V1/module.php index 3180efc..fb6f3a0 100644 --- a/Monitoring Server Influx V1/module.php +++ b/Monitoring Server Influx V1/module.php @@ -84,7 +84,7 @@ class MonitoringServer extends IPSModule { $this->SetTimerInterval("UpdateAlarms", $this->ReadPropertyInteger("UpdateintervallAlarms") * 1000); $this->SetTimerInterval("UpdateValues", $this->ReadPropertyInteger("UpdateintervallValues") * 1000); $this->SetTimerInterval("ForceUpdateValues", $this->ReadPropertyInteger("UpdateintervallForceValues") * 1000 * 60); - $this->SetTimerInterval("UpdateFtp", $this->ReadPropertyInteger("UpdateintervallSendFtp") * 1000 * 60); + $this->SetTimerInterval("UpdateFtp", $this->ReadPropertyInteger("UpdateintervallSendFtp") * 1000); $this->SetTimerInterval("CheckChanges", 10 * 1000); @@ -582,99 +582,99 @@ class MonitoringServer extends IPSModule { } } -private function sendFtp(){ - $goforit = $this->ReadPropertyBoolean("SendFtp"); - $ftp_server = $this->ReadPropertyString("FtpHost"); - $ftp_user_name = $this->ReadPropertyString("FtpUser"); - $ftp_user_pass = $this->ReadPropertyString("FtpPassword"); + private function sendFtp(){ + $goforit = $this->ReadPropertyBoolean("SendFtp"); + $ftp_server = $this->ReadPropertyString("FtpHost"); + $ftp_user_name = $this->ReadPropertyString("FtpUser"); + $ftp_user_pass = $this->ReadPropertyString("FtpPassword"); - if ($goforit == true or $goforit == 1){ - IPS_LogMessage ("FTP", "FTP Is ON!!!"); - $catNotifyId = $this->ReadPropertyInteger("ParseNotifyCategoryID"); - $catAnalogId = $this->ReadPropertyInteger("ParseAnalogCategoryID"); - $catAlarmId = $this->ReadPropertyInteger("ParseAlarmCategoryID"); + if ($goforit == true or $goforit == 1){ + IPS_LogMessage ("FTP", "FTP Is ON!!!"); + $catNotifyId = $this->ReadPropertyInteger("ParseNotifyCategoryID"); + $catAnalogId = $this->ReadPropertyInteger("ParseAnalogCategoryID"); + $catAlarmId = $this->ReadPropertyInteger("ParseAlarmCategoryID"); - $ispName = ""; - $projectName = ""; - $yearName = ""; + $ispName = ""; + $projectName = ""; + $yearName = ""; - $usedCat = 0; - if ($catNotifyId > 0) $usedCat = $catNotifyId; - elseif ($catAnalogId > 0) $usedCat = $catAnalogId; - elseif ($catAlarmId > 0) $usedCat = $catAlarmId; + $usedCat = 0; + if ($catNotifyId > 0) $usedCat = $catNotifyId; + elseif ($catAnalogId > 0) $usedCat = $catAnalogId; + elseif ($catAlarmId > 0) $usedCat = $catAlarmId; - if ($usedCat > 0){ - $parentid = IPS_GetParent($usedCat); - $ispName = IPS_GetName($parentid); - $projectId = IPS_GetParent($parentid); - $projectName = IPS_GetName($projectId); - $yearId = IPS_GetParent($projectId); - $yearName = IPS_GetName($yearId); - } + if ($usedCat > 0){ + $parentid = IPS_GetParent($usedCat); + $ispName = IPS_GetName($parentid); + $projectId = IPS_GetParent($parentid); + $projectName = IPS_GetName($projectId); + $yearId = IPS_GetParent($projectId); + $yearName = IPS_GetName($yearId); + } - $ftp = ftp_ssl_connect($ftp_server); - if (!$ftp) { - IPS_LogMessage ("FTP", "FTP-Verbindung fehlgeschlagen."); - ///echo "FTP-Verbindung fehlgeschlagen."; - return; - } + $ftp = ftp_ssl_connect($ftp_server); + if (!$ftp) { + IPS_LogMessage ("FTP", "FTP-Verbindung fehlgeschlagen."); + ///echo "FTP-Verbindung fehlgeschlagen."; + return; + } + + $login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass); + if (!$login_result) { + IPS_LogMessage ("FTP", "FTP-Login fehlgeschlagen."); + ///echo "FTP-Login fehlgeschlagen."; + ftp_close($ftp); + return; + } + + // Pfad erstellen + $ftpPath = "$yearName/$projectName/$ispName"; + $pathParts = explode("/", $ftpPath); + $currentPath = ""; + foreach ($pathParts as $part) { + $currentPath .= "$part/"; + if (!@ftp_chdir($ftp, $currentPath)) { + ftp_mkdir($ftp, $currentPath); + } + } + + // Temp-Dateipfad vorbereiten + $tmpDir = sys_get_temp_dir(); + + // Verarbeitungsfunktion + $this->generateAndUploadCsv($catNotifyId, $ftp, "$ftpPath/notify.csv", "$tmpDir/notify.csv"); + $this->generateAndUploadCsv($catAlarmId, $ftp, "$ftpPath/alarms.csv", "$tmpDir/alarms.csv"); + $this->generateAndUploadCsv($catAnalogId, $ftp, "$ftpPath/analog.csv", "$tmpDir/analog.csv"); - $login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass); - if (!$login_result) { - IPS_LogMessage ("FTP", "FTP-Login fehlgeschlagen."); - ///echo "FTP-Login fehlgeschlagen."; ftp_close($ftp); - return; - } - - // Pfad erstellen - $ftpPath = "$yearName/$projectName/$ispName"; - $pathParts = explode("/", $ftpPath); - $currentPath = ""; - foreach ($pathParts as $part) { - $currentPath .= "$part/"; - if (!@ftp_chdir($ftp, $currentPath)) { - ftp_mkdir($ftp, $currentPath); - } - } - - // Temp-Dateipfad vorbereiten - $tmpDir = sys_get_temp_dir(); - - // Verarbeitungsfunktion - $this->generateAndUploadCsv($catNotifyId, $ftp, "$ftpPath/notify.csv", "$tmpDir/notify.csv"); - $this->generateAndUploadCsv($catAlarmId, $ftp, "$ftpPath/alarms.csv", "$tmpDir/alarms.csv"); - $this->generateAndUploadCsv($catAnalogId, $ftp, "$ftpPath/analog.csv", "$tmpDir/analog.csv"); - - ftp_close($ftp); - } -} - -private function generateAndUploadCsv($catId, $ftp, $remotePath, $localPath) { - if ($catId <= 0) return; - - $data = "Name;Wert\n"; - - $catChilds = IPS_GetChildrenIDs($catId); - foreach ($catChilds as $catChild) { - $objchildids = IPS_GetChildrenIDs($catChild); - $parentName = IPS_GetName($catChild); - - foreach ($objchildids as $varId) { - if (IPS_VariableExists($varId)) { - $varName = IPS_GetName($varId); - $formattedValue = GetValueFormatted($varId); - $data .= "\"{$parentName}_{$varName}\";\"{$formattedValue}\"\n"; - } } } - // Schreibe Datei lokal - file_put_contents($localPath, $data); + private function generateAndUploadCsv($catId, $ftp, $remotePath, $localPath) { + if ($catId <= 0) return; - // Lade hoch - ftp_put($ftp, $remotePath, $localPath, FTP_BINARY); -} + $data = "Name;Wert\n"; + + $catChilds = IPS_GetChildrenIDs($catId); + foreach ($catChilds as $catChild) { + $objchildids = IPS_GetChildrenIDs($catChild); + $parentName = IPS_GetName($catChild); + + foreach ($objchildids as $varId) { + if (IPS_VariableExists($varId)) { + $varName = IPS_GetName($varId); + $formattedValue = GetValueFormatted($varId); + $data .= "\"{$parentName}_{$varName}\";\"{$formattedValue}\"\n"; + } + } + } + + // Schreibe Datei lokal + file_put_contents($localPath, $data); + + // Lade hoch + ftp_put($ftp, $remotePath, $localPath, FTP_BINARY); + } } ?> \ No newline at end of file diff --git a/library.json b/library.json index 6b803a2..34863bf 100644 --- a/library.json +++ b/library.json @@ -8,6 +8,6 @@ "date": 1491343200 }, "version": "2.5", - "build": 2, + "build": 3, "date": 0 } \ No newline at end of file