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.

45 lines
1.6 KiB

6 months ago
#!/bin/bash
set -e
# Custom logic here
# Path to the ECS metadata file
#METADATA_FILE=${ECS_CONTAINER_METADATA_FILE}
SCRIPT_DIR=$(dirname "$0")
METADATA_FILE="$SCRIPT_DIR/config.json"
# Path to the ECS metadata file
#METADATA_FILE=${ECS_CONTAINER_METADATA_FILE:-/dev/null}
#METADATA_FILE=$(cat "$ECS_CONTAINER_METADATA_FILE")
if [ -f "$METADATA_FILE" ]; then
# Extract HostPrivateIPv4Address from the metadata file
HOST_PRIVATE_IP=$(jq -r '.HostPrivateIPv4Address' < "$METADATA_FILE")
if [ "$HOST_PRIVATE_IP" != "null" ]; then
echo "Host Private IP: $HOST_PRIVATE_IP"
export HOST_PRIVATE_IP
6 months ago
# Define the input template file and output file
TEMPLATE_FILE="filebeat.template.yml"
OUTPUT_FILE="filebeat.yml"
6 months ago
6 months ago
mkdir -p /opt/filebeat-configs/${HOST_PRIVATE_IP}
6 months ago
6 months ago
# 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"
6 months ago
6 months ago
# 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
6 months ago
else
echo "HostPrivateIPv4Address not found in metadata file"
fi
else
echo "Metadata file does not exist"
fi
# Run the original filebeat entrypoint
6 months ago
exec /usr/bin/tini -- /usr/local/bin/docker-entrypoint "$@"