+1
-1
@@ -949,7 +949,7 @@ document.getElementById('testTelegramBtn').addEventListener('click', async () =>
|
||||
try {
|
||||
await api('/ingest', {
|
||||
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.');
|
||||
} catch (e) { toast('Failed to send test', 'danger'); }
|
||||
|
||||
+8
-1
@@ -3,6 +3,7 @@
|
||||
namespace Jakach\Logging\Api;
|
||||
|
||||
use Jakach\Logging\Model\{LogSourceType, AlertStatus};
|
||||
use Jakach\Logging\Notifier\TelegramNotifier;
|
||||
use Jakach\Logging\Storage\{Database, Repository};
|
||||
use Jakach\Logging\RuleEngine\Engine;
|
||||
|
||||
@@ -11,6 +12,7 @@ class Router
|
||||
private Repository $repo;
|
||||
private AuthMiddleware $auth;
|
||||
private Engine $engine;
|
||||
private TelegramNotifier $telegram;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -18,6 +20,7 @@ class Router
|
||||
$this->repo = new Repository($db);
|
||||
$this->auth = new AuthMiddleware($this->repo);
|
||||
$this->engine = new Engine($this->repo);
|
||||
$this->telegram = new TelegramNotifier($this->repo);
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
@@ -272,7 +275,11 @@ class Router
|
||||
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)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user