From aee6ab81a250211c0d2f5f52d1a11903764d241e Mon Sep 17 00:00:00 2001 From: pasindu Date: Wed, 3 Jul 2024 14:00:51 +0530 Subject: [PATCH] Fix issues in custom filebeat image --- Dockerfile | 6 +++++- docker-compose.yml | 17 +++++++++++++++++ entrypoint.sh | 10 +++++++--- .../filebeat-configs/filebeat.template.yml | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml create mode 100644 files/filebeat/opt/filebeat-configs/filebeat.template.yml diff --git a/Dockerfile b/Dockerfile index ba86611..e63f579 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,8 @@ USER root COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh -ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] +# Set the entry point to your custom script using tini +ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/entrypoint.sh"] + +# Set the CMD to pass the environment argument to Filebeat +CMD ["-environment", "container"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..50804ec --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.8" + +services: + entgra-filebeat: + image: filebeat:8.2.0-entgra-v2 + container_name: entgra-filebeat + restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" + volumes: + - ./files/iots/logs/:/opt/logs + - ./files/filebeat/opt/filebeat-configs:/opt/filebeat-configs + command: ["--strict.perms=false"] + environment: + - TZ=Asia/Colombo + - LOGSTASH_HOST=logstash + - LOGSTASH_PORT=5044 \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index d859a04..ab0bc69 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,9 +16,13 @@ if [ "$HOST_PRIVATE_IP" != "null" ]; then 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 "s/{{HOST_PRIVATE_IP}}/${HOST_PRIVATE_IP}/g" "/opt/filebeat-configs/$TEMPLATE_FILE" > "/opt/filebeat-configs/${HOST_PRIVATE_IP}/$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 @@ -29,5 +33,5 @@ else echo "HostPrivateIPv4Address not found" fi -# Run the original filebeat entrypoint -exec /usr/bin/tini -- /usr/local/bin/docker-entrypoint "$@" +# Execute the original Filebeat entry point with passed arguments +exec /usr/local/bin/docker-entrypoint "$@" \ No newline at end of file diff --git a/files/filebeat/opt/filebeat-configs/filebeat.template.yml b/files/filebeat/opt/filebeat-configs/filebeat.template.yml new file mode 100644 index 0000000..b429c54 --- /dev/null +++ b/files/filebeat/opt/filebeat-configs/filebeat.template.yml @@ -0,0 +1,19 @@ +filebeat.inputs: + - type: log + enabled: true + tags: ["SwitchGearLogs"] + paths: + - /usr/share/filebeat/elk/switchgear.log + exclude_files: [".gz$"] + exclude_lines: ["^.*TRACE.*$"] + +output.logstash: + hosts: ["${LOGSTASH_HOST}:${LOGSTASH_PORT}"] + +processors: + - add_docker_metadata: + host: "unix:///host_docker/docker.sock" + - add_fields: + target: "" + fields: + node.name: "${HOST_PRIVATE_IP}" #custom node name