feat: custom log drain endpoints
This commit is contained in:
parent
3b67d0a8de
commit
cc72f416e8
@ -16,6 +16,8 @@ class InstallLogDrain
|
|||||||
$type = 'highlight';
|
$type = 'highlight';
|
||||||
} else if ($server->settings->is_logdrain_axiom_enabled) {
|
} else if ($server->settings->is_logdrain_axiom_enabled) {
|
||||||
$type = 'axiom';
|
$type = 'axiom';
|
||||||
|
} else if ($server->settings->is_logdrain_custom_enabled) {
|
||||||
|
$type = 'custom';
|
||||||
} else {
|
} else {
|
||||||
$type = 'none';
|
$type = 'none';
|
||||||
}
|
}
|
||||||
@ -114,15 +116,23 @@ class InstallLogDrain
|
|||||||
json_date_format iso8601
|
json_date_format iso8601
|
||||||
tls On
|
tls On
|
||||||
");
|
");
|
||||||
|
} else if ($type === 'custom') {
|
||||||
|
if (!$server->settings->is_logdrain_custom_enabled) {
|
||||||
|
throw new \Exception('Custom log drain is not enabled.');
|
||||||
|
}
|
||||||
|
$config = base64_encode($server->settings->logdrain_custom_config);
|
||||||
|
$parsers = base64_encode($server->settings->logdrain_custom_config_parser);
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception('Unknown log drain type.');
|
throw new \Exception('Unknown log drain type.');
|
||||||
}
|
}
|
||||||
$parsers = base64_encode("
|
if ($type !== 'custom') {
|
||||||
|
$parsers = base64_encode("
|
||||||
[PARSER]
|
[PARSER]
|
||||||
Name empty_line_skipper
|
Name empty_line_skipper
|
||||||
Format regex
|
Format regex
|
||||||
Regex /^(?!\s*$).+/
|
Regex /^(?!\s*$).+/
|
||||||
");
|
");
|
||||||
|
}
|
||||||
$compose = base64_encode("
|
$compose = base64_encode("
|
||||||
services:
|
services:
|
||||||
coolify-log-drain:
|
coolify-log-drain:
|
||||||
@ -179,6 +189,12 @@ Files:
|
|||||||
"echo AXIOM_DATASET_NAME={$server->settings->logdrain_axiom_dataset_name} >> $config_path/.env",
|
"echo AXIOM_DATASET_NAME={$server->settings->logdrain_axiom_dataset_name} >> $config_path/.env",
|
||||||
"echo AXIOM_API_KEY={$server->settings->logdrain_axiom_api_key} >> $config_path/.env",
|
"echo AXIOM_API_KEY={$server->settings->logdrain_axiom_api_key} >> $config_path/.env",
|
||||||
];
|
];
|
||||||
|
} else if ($type === 'custom') {
|
||||||
|
$add_envs_command = [
|
||||||
|
"touch $config_path/.env"
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
throw new \Exception('Unknown log drain type.');
|
||||||
}
|
}
|
||||||
$restart_command = [
|
$restart_command = [
|
||||||
"echo 'Stopping old Fluent Bit'",
|
"echo 'Stopping old Fluent Bit'",
|
||||||
|
@ -19,6 +19,9 @@ class LogDrains extends Component
|
|||||||
'server.settings.is_logdrain_axiom_enabled' => 'required|boolean',
|
'server.settings.is_logdrain_axiom_enabled' => 'required|boolean',
|
||||||
'server.settings.logdrain_axiom_dataset_name' => 'required|string',
|
'server.settings.logdrain_axiom_dataset_name' => 'required|string',
|
||||||
'server.settings.logdrain_axiom_api_key' => 'required|string',
|
'server.settings.logdrain_axiom_api_key' => 'required|string',
|
||||||
|
'server.settings.is_logdrain_custom_enabled' => 'required|boolean',
|
||||||
|
'server.settings.logdrain_custom_config' => 'required|string',
|
||||||
|
'server.settings.logdrain_custom_config_parser' => 'nullable',
|
||||||
];
|
];
|
||||||
protected $validationAttributes = [
|
protected $validationAttributes = [
|
||||||
'server.settings.is_logdrain_newrelic_enabled' => 'New Relic log drain',
|
'server.settings.is_logdrain_newrelic_enabled' => 'New Relic log drain',
|
||||||
@ -29,6 +32,9 @@ class LogDrains extends Component
|
|||||||
'server.settings.is_logdrain_axiom_enabled' => 'Axiom log drain',
|
'server.settings.is_logdrain_axiom_enabled' => 'Axiom log drain',
|
||||||
'server.settings.logdrain_axiom_dataset_name' => 'Axiom dataset name',
|
'server.settings.logdrain_axiom_dataset_name' => 'Axiom dataset name',
|
||||||
'server.settings.logdrain_axiom_api_key' => 'Axiom API key',
|
'server.settings.logdrain_axiom_api_key' => 'Axiom API key',
|
||||||
|
'server.settings.is_logdrain_custom_enabled' => 'Custom log drain',
|
||||||
|
'server.settings.logdrain_custom_config' => 'Custom log drain configuration',
|
||||||
|
'server.settings.logdrain_custom_config_parser' => 'Custom log drain configuration parser',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
@ -84,6 +90,7 @@ class LogDrains extends Component
|
|||||||
$this->server->settings->update([
|
$this->server->settings->update([
|
||||||
'is_logdrain_highlight_enabled' => false,
|
'is_logdrain_highlight_enabled' => false,
|
||||||
'is_logdrain_axiom_enabled' => false,
|
'is_logdrain_axiom_enabled' => false,
|
||||||
|
'is_logdrain_custom_enabled' => false,
|
||||||
]);
|
]);
|
||||||
} else if ($type === 'highlight') {
|
} else if ($type === 'highlight') {
|
||||||
$this->validate([
|
$this->validate([
|
||||||
@ -93,6 +100,7 @@ class LogDrains extends Component
|
|||||||
$this->server->settings->update([
|
$this->server->settings->update([
|
||||||
'is_logdrain_newrelic_enabled' => false,
|
'is_logdrain_newrelic_enabled' => false,
|
||||||
'is_logdrain_axiom_enabled' => false,
|
'is_logdrain_axiom_enabled' => false,
|
||||||
|
'is_logdrain_custom_enabled' => false,
|
||||||
]);
|
]);
|
||||||
} else if ($type === 'axiom') {
|
} else if ($type === 'axiom') {
|
||||||
$this->validate([
|
$this->validate([
|
||||||
@ -103,6 +111,18 @@ class LogDrains extends Component
|
|||||||
$this->server->settings->update([
|
$this->server->settings->update([
|
||||||
'is_logdrain_newrelic_enabled' => false,
|
'is_logdrain_newrelic_enabled' => false,
|
||||||
'is_logdrain_highlight_enabled' => false,
|
'is_logdrain_highlight_enabled' => false,
|
||||||
|
'is_logdrain_custom_enabled' => false,
|
||||||
|
]);
|
||||||
|
} else if ($type === 'custom') {
|
||||||
|
$this->validate([
|
||||||
|
'server.settings.is_logdrain_custom_enabled' => 'required|boolean',
|
||||||
|
'server.settings.logdrain_custom_config' => 'required|string',
|
||||||
|
'server.settings.logdrain_custom_config_parser' => 'nullable',
|
||||||
|
]);
|
||||||
|
$this->server->settings->update([
|
||||||
|
'is_logdrain_newrelic_enabled' => false,
|
||||||
|
'is_logdrain_highlight_enabled' => false,
|
||||||
|
'is_logdrain_axiom_enabled' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$this->server->settings->save();
|
$this->server->settings->save();
|
||||||
@ -121,6 +141,10 @@ class LogDrains extends Component
|
|||||||
$this->server->settings->update([
|
$this->server->settings->update([
|
||||||
'is_logdrain_axiom_enabled' => false,
|
'is_logdrain_axiom_enabled' => false,
|
||||||
]);
|
]);
|
||||||
|
} else if ($type === 'custom') {
|
||||||
|
$this->server->settings->update([
|
||||||
|
'is_logdrain_custom_enabled' => false,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
handleError($e, $this);
|
handleError($e, $this);
|
||||||
return false;
|
return false;
|
||||||
|
@ -349,7 +349,7 @@ class Server extends BaseModel
|
|||||||
}
|
}
|
||||||
public function isLogDrainEnabled()
|
public function isLogDrainEnabled()
|
||||||
{
|
{
|
||||||
return $this->settings->is_logdrain_newrelic_enabled || $this->settings->is_logdrain_highlight_enabled || $this->settings->is_logdrain_axiom_enabled;
|
return $this->settings->is_logdrain_newrelic_enabled || $this->settings->is_logdrain_highlight_enabled || $this->settings->is_logdrain_axiom_enabled || $this->settings->is_logdrain_custom_enabled;
|
||||||
}
|
}
|
||||||
public function validateOS(): bool | Stringable
|
public function validateOS(): bool | Stringable
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('server_settings', function (Blueprint $table) {
|
||||||
|
$table->boolean('is_logdrain_custom_enabled')->default(false);
|
||||||
|
$table->text('logdrain_custom_config')->nullable();
|
||||||
|
$table->text('logdrain_custom_config_parser')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('server_settings', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('is_logdrain_custom_enabled');
|
||||||
|
$table->dropColumn('logdrain_custom_config');
|
||||||
|
$table->dropColumn('logdrain_custom_config_parser');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -62,6 +62,25 @@
|
|||||||
</x-forms.button>
|
</x-forms.button>
|
||||||
</div>
|
</div>
|
||||||
</form> --}}
|
</form> --}}
|
||||||
|
<h3>Custom FluentBit configuration</h3>
|
||||||
|
<div class="w-32">
|
||||||
|
<x-forms.checkbox instantSave='instantSave("custom")' id="server.settings.is_logdrain_custom_enabled"
|
||||||
|
label="Enabled" />
|
||||||
|
</div>
|
||||||
|
<form wire:submit.prevent='submit("custom")' class="flex flex-col">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<x-forms.textarea rows="6" required id="server.settings.logdrain_custom_config"
|
||||||
|
label="Custom FluentBit Configuration" />
|
||||||
|
<x-forms.textarea id="server.settings.logdrain_custom_config_parser"
|
||||||
|
label="Custom Parser Configuration" />
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end gap-4 pt-6">
|
||||||
|
<x-forms.button type="submit">
|
||||||
|
Save
|
||||||
|
</x-forms.button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user