mirror of
https://repository.entgra.net/community/entgra-elk.git
synced 2025-09-16 23:32:20 +00:00
34 lines
1.3 KiB
Bash
34 lines
1.3 KiB
Bash
#!/bin/bash
|
|
|
|
# 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}
|
|
|
|
# Replace the placeholder with the actual node name and write to the output file
|
|
sed "s/{{HOST_PRIVATE_IP}}/${HOST_PRIVATE_IP}/g" "/opt/filebeat-configs/$TEMPLATE_FILE" > "/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
|
|
|
|
# Run the original filebeat entrypoint
|
|
exec /usr/bin/tini -- /usr/local/bin/docker-entrypoint "$@"
|