From 49bb7884b74d45e6afdf0f6b6406110a0a04caf3 Mon Sep 17 00:00:00 2001 From: Alex Macocian Date: Fri, 26 Sep 2025 06:56:14 +0200 Subject: [PATCH] Add support for hosts --- filebeat/filebeat.yml | 2 +- logstash/conf.d/90-output.conf | 2 +- metricbeat/metricbeat.yml | 2 +- orchestrator/setup-filebeat.sh | 13 +++++++++---- orchestrator/setup-logstash.sh | 13 +++++++++---- orchestrator/setup-metricbeat.sh | 11 ++++++++--- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/filebeat/filebeat.yml b/filebeat/filebeat.yml index 21c9bf9..1a1e4bb 100644 --- a/filebeat/filebeat.yml +++ b/filebeat/filebeat.yml @@ -28,7 +28,7 @@ setup.template.settings: # ---------------------------- Elasticsearch Output ---------------------------- output.elasticsearch: - hosts: ["localhost:9200"] + hosts: ["replace-host"] preset: balanced username: "replace-user" password: "replace-password" diff --git a/logstash/conf.d/90-output.conf b/logstash/conf.d/90-output.conf index b2a4ff4..a9b91b3 100644 --- a/logstash/conf.d/90-output.conf +++ b/logstash/conf.d/90-output.conf @@ -1,7 +1,7 @@ output { # Forward logs to Elasticsearch elasticsearch { - hosts => ["http://localhost:9200"] + hosts => ["http://replace-host:9200"] user => "replace-user" password => "replace-password" } diff --git a/metricbeat/metricbeat.yml b/metricbeat/metricbeat.yml index e93e237..79bc4ed 100644 --- a/metricbeat/metricbeat.yml +++ b/metricbeat/metricbeat.yml @@ -40,7 +40,7 @@ fields: # ---------------------------- Elasticsearch Output ---------------------------- output.elasticsearch: # Array of hosts to connect to. - hosts: ["localhost:9200"] + hosts: ["replace-host"] # Performance preset - one of "balanced", "throughput", "scale", # "latency", or "custom". diff --git a/orchestrator/setup-filebeat.sh b/orchestrator/setup-filebeat.sh index fff7dc4..a7eb731 100755 --- a/orchestrator/setup-filebeat.sh +++ b/orchestrator/setup-filebeat.sh @@ -38,6 +38,7 @@ CheckFilebeatInstalled() { UpdateFilebeatConfig() { local user="$1" local password="$2" + local host="$3" local config_file="${FILEBEAT_CONFIG_DIR}/${CONFIG_FILE}" local temp_file=$(mktemp) @@ -50,10 +51,12 @@ UpdateFilebeatConfig() { sed -e "s/username: \"[^\"]*\"/username: \"$user\"/" \ -e "s/password: \"[^\"]*\"/password: \"$password\"/" \ + -e "s|hosts: \[\"[^\"]*\"\]|hosts: [\"$host\"]|" \ "$config_file" > "$temp_file" if grep -q "username: \"$user\"" "$temp_file" && \ - grep -q "password: \"$password\"" "$temp_file"; then + grep -q "password: \"$password\"" "$temp_file" && \ + grep -q "hosts: [\"$host\"]" "$temp_file"; then mv "$temp_file" "$config_file" LogInformation "Updated Elasticsearch settings: user=$user" else @@ -192,7 +195,7 @@ RemoveFilebeatConfigs() { } ShowUsage() { - echo "Usage: $0 install " + echo "Usage: $0 install " echo " $0 [remove|status|help]" echo "" echo "Commands:" @@ -204,9 +207,10 @@ ShowUsage() { echo "Parameters for install:" echo " user - Elasticsearch username" echo " password - Elasticsearch password" + echo " host - Elasticsearch host URL (e.g., http://localhost:9200)" echo "" echo "Examples:" - echo " sudo $0 install elastic mypassword" + echo " sudo $0 install elastic mypassword http://localhost:9200" echo " sudo $0 status" echo " sudo $0 remove" } @@ -224,13 +228,14 @@ Main() { local user="$2" local password="$3" + local host="$4" LogInformation "Installing Filebeat configurations" LogInformation "Elasticsearch settings: user=$user" CheckRoot CheckFilebeatInstalled - UpdateFilebeatConfig "$user" "$password" + UpdateFilebeatConfig "$user" "$password" "$host" InstallFilebeatConfigs ValidateFilebeatConfig LogInformation "Filebeat setup completed successfully!" diff --git a/orchestrator/setup-logstash.sh b/orchestrator/setup-logstash.sh index 45ee2ea..cb9137f 100755 --- a/orchestrator/setup-logstash.sh +++ b/orchestrator/setup-logstash.sh @@ -38,6 +38,7 @@ CheckLogstashInstalled() { UpdateOutputConfig() { local user="$1" local password="$2" + local host="$3" local output_file="${LOGSTASH_CONFIG_DIR}/${OUTPUT_CONFIG_FILE}" local temp_file=$(mktemp) @@ -50,10 +51,12 @@ UpdateOutputConfig() { sed -e "s/user => \"[^\"]*\"/user => \"$user\"/" \ -e "s/password => \"[^\"]*\"/password => \"$password\"/" \ + -e "s/hosts => \[\"[^\"]*\"\]/hosts => [\"$host\"]/" \ "$output_file" > "$temp_file" if grep -q "user => \"$user\"" "$temp_file" && \ - grep -q "password => \"$password\"" "$temp_file"; then + grep -q "password => \"$password\"" "$temp_file" && \ + grep -q "hosts => [\"$host\"]" "$temp_file"; then mv "$temp_file" "$output_file" LogInformation "Updated Elasticsearch settings: user=$user" else @@ -217,7 +220,7 @@ RemoveLogstashConfigs() { } ShowUsage() { - echo "Usage: $0 install " + echo "Usage: $0 install " echo " $0 [remove|status|help]" echo "" echo "Commands:" @@ -229,9 +232,10 @@ ShowUsage() { echo "Parameters for install:" echo " user - Elasticsearch username" echo " password - Elasticsearch password" + echo " host - Elasticsearch host (e.g., http://localhost:9200)" echo "" echo "Examples:" - echo " sudo $0 install elastic mypassword" + echo " sudo $0 install elastic mypassword http://localhost:9200" echo " sudo $0 status" echo " sudo $0 remove" } @@ -249,13 +253,14 @@ Main() { local user="$2" local password="$3" + local host="$4" LogInformation "Installing Logstash configurations" LogInformation "Elasticsearch settings: user=$user" CheckRoot CheckLogstashInstalled - UpdateOutputConfig "$user" "$password" + UpdateOutputConfig "$user" "$password" "$host" InstallLogstashConfigs ValidateLogstashConfig LogInformation "Logstash setup completed successfully!" diff --git a/orchestrator/setup-metricbeat.sh b/orchestrator/setup-metricbeat.sh index 42ace9a..fe8f326 100755 --- a/orchestrator/setup-metricbeat.sh +++ b/orchestrator/setup-metricbeat.sh @@ -38,6 +38,7 @@ CheckMetricbeatInstalled() { UpdateMetricbeatConfig() { local user="$1" local password="$2" + local host="$3" local config_file="${METRICBEAT_CONFIG_DIR}/${CONFIG_FILE}" local temp_file=$(mktemp) @@ -50,10 +51,12 @@ UpdateMetricbeatConfig() { sed -e "s/username: \"[^\"]*\"/username: \"$user\"/" \ -e "s/password: \"[^\"]*\"/password: \"$password\"/" \ + -e "s|hosts: \[\"[^\"]*\"\]|hosts: [\"$host\"]|" \ "$config_file" > "$temp_file" if grep -q "username: \"$user\"" "$temp_file" && \ - grep -q "password: \"$password\"" "$temp_file"; then + grep -q "password: \"$password\"" "$temp_file" && \ + grep -q "hosts: [\"$host\"]" "$temp_file"; then mv "$temp_file" "$config_file" LogInformation "Updated Elasticsearch settings: user=$user" else @@ -192,7 +195,7 @@ RemoveMetricbeatConfigs() { } ShowUsage() { - echo "Usage: $0 install " + echo "Usage: $0 install " echo " $0 [remove|status|help]" echo "" echo "Commands:" @@ -204,6 +207,7 @@ ShowUsage() { echo "Parameters for install:" echo " user - Elasticsearch username" echo " password - Elasticsearch password" + echo " host - Elasticsearch host (e.g., localhost:9200)" echo "" echo "Examples:" echo " sudo $0 install elastic mypassword" @@ -224,13 +228,14 @@ Main() { local user="$2" local password="$3" + local host="$4" LogInformation "Installing Metricbeat configurations" LogInformation "Elasticsearch settings: user=$user" CheckRoot CheckMetricbeatInstalled - UpdateMetricbeatConfig "$user" "$password" + UpdateMetricbeatConfig "$user" "$password" "$host" InstallMetricbeatConfigs ValidateMetricbeatConfig LogInformation "Metricbeat setup completed successfully!"