Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: custom log drain endpoints

Andras Bacsaicc72f416e8ea
diff --git a/app/Actions/Server/InstallLogDrain.php b/app/Actions/Server/InstallLogDrain.php
index 11487d6334..e43642e7aa 100644
--- a/app/Actions/Server/InstallLogDrain.php
+++ b/app/Actions/Server/InstallLogDrain.php
@@ -16,6 +16,8 @@ class InstallLogDrain
$type = 'highlight';
} else if ($server->settings->is_logdrain_axiom_enabled) {
$type = 'axiom';
+ } else if ($server->settings->is_logdrain_custom_enabled) {
+ $type = 'custom';
} else {
$type = 'none';
}
@@ -114,15 +116,23 @@ class InstallLogDrain
json_date_format iso8601
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 {
throw new \Exception('Unknown log drain type.');
}
- $parsers = base64_encode("
+ if ($type !== 'custom') {
+ $parsers = base64_encode("
[PARSER]
- Name empty_line_skipper
- Format regex
- Regex /^(?!\s*$).+/
+Name empty_line_skipper
+Format regex
+Regex /^(?!\s*$).+/
");
+ }
$compose = base64_encode("
services:
coolify-log-drain:
@@ -179,6 +189,12 @@ Files:
"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",
];
+ } else if ($type === 'custom') {
+ $add_envs_command = [
+ "touch $config_path/.env"
+ ];
+ } else {
+ throw new \Exception('Unknown log drain type.');
}
$restart_command = [
"echo 'Stopping old Fluent Bit'",
diff --git a/app/Http/Livewire/Server/LogDrains.php b/app/Http/Livewire/Server/LogDrains.php
index 056beb5845..5afe540ca8 100644
--- a/app/Http/Livewire/Server/LogDrains.php
+++ b/app/Http/Livewire/Server/LogDrains.php
@@ -19,6 +19,9 @@ class LogDrains extends Component
'server.settings.is_logdrain_axiom_enabled' => 'required|boolean',
'server.settings.logdrain_axiom_dataset_name' => '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 = [
'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.logdrain_axiom_dataset_name' => 'Axiom dataset name',
'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()
@@ -84,6 +90,7 @@ class LogDrains extends Component
$this->server->settings->update([
'is_logdrain_highlight_enabled' => false,
'is_logdrain_axiom_enabled' => false,
+ 'is_logdrain_custom_enabled' => false,
]);
} else if ($type === 'highlight') {
$this->validate([
@@ -93,6 +100,7 @@ class LogDrains extends Component
$this->server->settings->update([
'is_logdrain_newrelic_enabled' => false,
'is_logdrain_axiom_enabled' => false,
+ 'is_logdrain_custom_enabled' => false,
]);
} else if ($type === 'axiom') {
$this->validate([
@@ -103,6 +111,18 @@ class LogDrains extends Component
$this->server->settings->update([
'is_logdrain_newrelic_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();
@@ -121,6 +141,10 @@ class LogDrains extends Component
$this->server->settings->update([
'is_logdrain_axiom_enabled' => false,
]);
+ } else if ($type === 'custom') {
+ $this->server->settings->update([
+ 'is_logdrain_custom_enabled' => false,
+ ]);
}
handleError($e, $this);
return false;
diff --git a/app/Models/Server.php b/app/Models/Server.php
index 4081061070..f65ecfb10d 100644
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@ -349,7 +349,7 @@ class Server extends BaseModel
}
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
{
diff --git a/database/migrations/2023_12_01_095356_add_custom_fluentd_config_for_logdrains.php b/database/migrations/2023_12_01_095356_add_custom_fluentd_config_for_logdrains.php
new file mode 100644
index 0000000000..ff100b484d
--- /dev/null
+++ b/database/migrations/2023_12_01_095356_add_custom_fluentd_config_for_logdrains.php
@@ -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');
+ });
+ }
+};
diff --git a/resources/views/livewire/server/log-drains.blade.php b/resources/views/livewire/server/log-drains.blade.php
index 465702053a..c452b171bd 100644
--- a/resources/views/livewire/server/log-drains.blade.php
+++ b/resources/views/livewire/server/log-drains.blade.php
@@ -62,6 +62,25 @@
</x-forms.button>
</div>
</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>