59 lines
1.7 KiB
Plaintext
Executable File
59 lines
1.7 KiB
Plaintext
Executable File
<?php
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
|
|
use Jakach\Logging\Storage\Database;
|
|
use Jakach\Logging\Storage\Repository;
|
|
use Jakach\Logging\Model\LogSourceType;
|
|
|
|
$db = new Database();
|
|
$repo = new Repository($db);
|
|
$config = require __DIR__ . '/../config/default.php';
|
|
|
|
echo "Seeding default rules...\n";
|
|
foreach ($config['rules'] as $rule) {
|
|
$r = $repo->createRule(
|
|
name: $rule['name'],
|
|
pattern: $rule['pattern'],
|
|
severity: $rule['severity'],
|
|
rateLimitSeconds: $rule['rate_limit_seconds'] ?? null,
|
|
);
|
|
echo sprintf(" + Rule #%d: %s (%s)\n", $r->id, $r->name, $r->severity->value);
|
|
}
|
|
|
|
echo "Seeding default log sources...\n";
|
|
|
|
$existing = $repo->getSources();
|
|
$existingNames = array_map(fn($s) => $s->name, $existing);
|
|
|
|
if (!in_array('syslog-tcp', $existingNames)) {
|
|
$s = $repo->createSource(
|
|
name: 'syslog-tcp',
|
|
type: LogSourceType::Tcp,
|
|
address: 'tcp://0.0.0.0:9514',
|
|
labels: ['protocol' => 'syslog'],
|
|
);
|
|
echo sprintf(" + Source #%d: syslog-tcp (TCP :9514)\n", $s->id);
|
|
}
|
|
|
|
if (!in_array('syslog-udp', $existingNames)) {
|
|
$s = $repo->createSource(
|
|
name: 'syslog-udp',
|
|
type: LogSourceType::Udp,
|
|
address: 'udp://0.0.0.0:9514',
|
|
labels: ['protocol' => 'syslog'],
|
|
);
|
|
echo sprintf(" + Source #%d: syslog-udp (UDP :9514)\n", $s->id);
|
|
}
|
|
|
|
if (!in_array('collect-volume', $existingNames)) {
|
|
$s = $repo->createSource(
|
|
name: 'collect-volume',
|
|
type: LogSourceType::File,
|
|
address: '/collect/*.log',
|
|
labels: ['type' => 'shared-volume'],
|
|
);
|
|
echo sprintf(" + Source #%d: collect-volume (/collect/*.log)\n", $s->id);
|
|
}
|
|
|
|
echo "Done.\n"; |