You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.2 KiB
54 lines
2.2 KiB
#!/bin/bash
|
|
|
|
# Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
#
|
|
# Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
# Version 2.0 (the "License"); you may not use this file except
|
|
# in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
# Check if ECS_CONTAINER_METADATA_FILE is set
|
|
if [ -z "$ECS_CONTAINER_METADATA_FILE" ]; then
|
|
echo "ECS_CONTAINER_METADATA_FILE is not set or the server is running on local deployment environment"
|
|
fi
|
|
|
|
# Extract HostPrivateIPv4Address from the metadata file
|
|
HOST_PRIVATE_IP=$(cat $ECS_CONTAINER_METADATA_FILE | grep -oP '(?<=HostPrivateIPv4Address": ")[^"]+')
|
|
|
|
if [ "$HOST_PRIVATE_IP" != "null" ]; then
|
|
echo "Host Private IP: $HOST_PRIVATE_IP"
|
|
|
|
# Define the input template file and output file
|
|
TEMPLATE_FILE="filebeat.template.yml"
|
|
OUTPUT_FILE="filebeat.yml"
|
|
|
|
mkdir -p /opt/filebeat-configs/${HOST_PRIVATE_IP}
|
|
cp /opt/filebeat-configs/$TEMPLATE_FILE /opt/filebeat-configs/${HOST_PRIVATE_IP}/$OUTPUT_FILE
|
|
|
|
# Replace the placeholder with the actual node name and write to the output file
|
|
sed -i 's/${HOST_PRIVATE_IP}/'$HOST_PRIVATE_IP'/g' /opt/filebeat-configs/${HOST_PRIVATE_IP}/$OUTPUT_FILE
|
|
sed -i 's/${LOGSTASH_HOST}/'$LOGSTASH_HOST'/g' /opt/filebeat-configs/${HOST_PRIVATE_IP}/$OUTPUT_FILE
|
|
sed -i 's/${LOGSTASH_PORT}/'$LOGSTASH_PORT'/g' /opt/filebeat-configs/${HOST_PRIVATE_IP}/$OUTPUT_FILE
|
|
|
|
echo "Filebeat configuration file created: $OUTPUT_FILE"
|
|
|
|
# Create symlinks
|
|
rm -rf /usr/share/filebeat/elk
|
|
ln -sf "/opt/logs/${HOST_PRIVATE_IP}/elk" /usr/share/filebeat/elk
|
|
ln -sf "/opt/filebeat-configs/${HOST_PRIVATE_IP}/filebeat.yml" /usr/share/filebeat/filebeat.yml
|
|
else
|
|
echo "HostPrivateIPv4Address not found"
|
|
fi
|
|
|
|
# Execute the original Filebeat entry point with passed arguments
|
|
exec /usr/local/bin/docker-entrypoint "$@"
|