Remove jq usage

pull/2/head
Pasindu Rupasinghe 6 months ago
parent 7734be4321
commit 0510968173

@ -3,9 +3,6 @@ FROM docker.elastic.co/beats/filebeat:8.2.0
# Switch to root user # Switch to root user
USER root USER root
#install jq to the container
RUN apt-get update && apt-get install -y jq
COPY entrypoint.sh /usr/local/bin/entrypoint.sh COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh

@ -1,35 +1,32 @@
#!/bin/bash #!/bin/bash
set -e
# Check if ECS_CONTAINER_METADATA_FILE is set
# Path to the ECS metadata file if [ -z "$ECS_CONTAINER_METADATA_FILE" ]; then
METADATA_FILE=$(cat "$ECS_CONTAINER_METADATA_FILE") echo "ECS_CONTAINER_METADATA_FILE is not set or the server is running on local deployment environment"
fi
if [ -f "$METADATA_FILE" ]; then
# Extract HostPrivateIPv4Address from the metadata file # Extract HostPrivateIPv4Address from the metadata file
HOST_PRIVATE_IP=$(jq -r '.HostPrivateIPv4Address' < "$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" if [ "$HOST_PRIVATE_IP" != "null" ]; then
export HOST_PRIVATE_IP echo "Host Private IP: $HOST_PRIVATE_IP"
# Define the input template file and output file # Define the input template file and output file
TEMPLATE_FILE="filebeat.template.yml" TEMPLATE_FILE="filebeat.template.yml"
OUTPUT_FILE="filebeat.yml" OUTPUT_FILE="filebeat.yml"
mkdir -p /opt/filebeat-configs/${HOST_PRIVATE_IP} mkdir -p /opt/filebeat-configs/${HOST_PRIVATE_IP}
# Replace the placeholder with the actual node name and write to the output file # 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" 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" echo "Filebeat configuration file created: $OUTPUT_FILE"
# Create symlinks # Create symlinks
rm -rf /usr/share/filebeat/elk rm -rf /usr/share/filebeat/elk
ln -sf "/opt/logs/${HOST_PRIVATE_IP}/elk" /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 ln -sf "/opt/filebeat-configs/${HOST_PRIVATE_IP}/filebeat.yml" /usr/share/filebeat/filebeat.yml
else
echo "HostPrivateIPv4Address not found in metadata file"
fi
else else
echo "Metadata file does not exist" echo "HostPrivateIPv4Address not found"
fi fi
# Run the original filebeat entrypoint # Run the original filebeat entrypoint

Loading…
Cancel
Save