fixing telegram
Deploy / deploy (push) Successful in 8s

This commit is contained in:
2026-05-06 18:30:55 +02:00
parent e203aac2f5
commit 23e37c2e1a
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -949,7 +949,7 @@ document.getElementById('testTelegramBtn').addEventListener('click', async () =>
try { try {
await api('/ingest', { await api('/ingest', {
method: 'POST', method: 'POST',
body: JSON.stringify({ line: 'Jakach Logging: test notification from settings', source: 'test' }), body: JSON.stringify({ line: 'Jakach Logging: test notification from settings — PHP Warning: test alert', source: 'test' }),
}); });
toast('Test alert sent. Check Telegram.'); toast('Test alert sent. Check Telegram.');
} catch (e) { toast('Failed to send test', 'danger'); } } catch (e) { toast('Failed to send test', 'danger'); }
+8 -1
View File
@@ -3,6 +3,7 @@
namespace Jakach\Logging\Api; namespace Jakach\Logging\Api;
use Jakach\Logging\Model\{LogSourceType, AlertStatus}; use Jakach\Logging\Model\{LogSourceType, AlertStatus};
use Jakach\Logging\Notifier\TelegramNotifier;
use Jakach\Logging\Storage\{Database, Repository}; use Jakach\Logging\Storage\{Database, Repository};
use Jakach\Logging\RuleEngine\Engine; use Jakach\Logging\RuleEngine\Engine;
@@ -11,6 +12,7 @@ class Router
private Repository $repo; private Repository $repo;
private AuthMiddleware $auth; private AuthMiddleware $auth;
private Engine $engine; private Engine $engine;
private TelegramNotifier $telegram;
public function __construct() public function __construct()
{ {
@@ -18,6 +20,7 @@ class Router
$this->repo = new Repository($db); $this->repo = new Repository($db);
$this->auth = new AuthMiddleware($this->repo); $this->auth = new AuthMiddleware($this->repo);
$this->engine = new Engine($this->repo); $this->engine = new Engine($this->repo);
$this->telegram = new TelegramNotifier($this->repo);
} }
public function handle(): void public function handle(): void
@@ -272,7 +275,11 @@ class Router
return ['error' => 'Missing "line" field']; return ['error' => 'Missing "line" field'];
} }
$this->engine->evaluate($line, null); $alert = $this->engine->evaluate($line, null);
if ($alert !== null) {
$this->telegram->send($alert);
}
return ['status' => 'ingested', 'line' => substr($line, 0, 100)]; return ['status' => 'ingested', 'line' => substr($line, 0, 100)];
} }