From 2394e8cb0b0113a334e2389042876acfbbbd6c8f Mon Sep 17 00:00:00 2001 From: SCHAUAUS GmbH <2+schauausgmbh@noreply.aaskablackwolf.servehttp.com> Date: Tue, 2 Jun 2026 21:34:36 +0000 Subject: [PATCH] =?UTF-8?q?worker.php=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worker.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 worker.php diff --git a/worker.php b/worker.php new file mode 100644 index 0000000..9929d4b --- /dev/null +++ b/worker.php @@ -0,0 +1,70 @@ +service->username) && defined($config->service->password) ) + $authorization = 'Basic ' + base64_encode($config->service->username + ':' + $config->service->password); + elseif( defined($config->service->token) ) + $authorization = 'Bearer ' + $config->service->token; + + $result = file_get_contents( $config->service->url + '/' + $config->service->topic, false, stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => + 'Content-Type: text/plain\r\n' . + 'Authorization: ' + $authorization, + 'content' => $message + ] + ])); + + return true; +} + +function queryMonitors() { + global $config; + // establish database connection + $dbPath = (str_starts_with($config->database, '/')) ? $config->database : dirname(__FILE__) . '/../' . $config->database; + try { + $db = new SQLite3($dbPath, SQLITE3_OPEN_READONLY); + } + catch (Exception $e) { + return false; + } + // query devices from database + $sql = "SELECT name FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%' AND name <> 'meta' ORDER BY name ASC;"; + $data = queryDb($sql); + + // process every device found on database + foreach( $data as $device) { + // query device data from database + $sql = "SELECT * FROM $device->name ORDER BY date DESC, time DESC LIMIT 1;"; + $res = $db->query($sql)->fetchArray(SQLITE3_NUM); + $dataset = json_decode($res[0][2]); + print_r($dataset); + + // process configured monitors + foreach($config->monitors as $monitor) { + } + } +} + +?> \ No newline at end of file