Add support for hosts

This commit is contained in:
2025-09-26 06:56:14 +02:00
parent 42377abb0e
commit 49bb7884b7
6 changed files with 29 additions and 14 deletions
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
}
+1 -1
View File
@@ -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".
+9 -4
View File
@@ -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 <user> <password>"
echo "Usage: $0 install <user> <password> <host>"
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!"
+9 -4
View File
@@ -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 <user> <password>"
echo "Usage: $0 install <user> <password> <host>"
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!"
+8 -3
View File
@@ -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 <user> <password>"
echo "Usage: $0 install <user> <password> <host>"
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!"