#!/bin/bash

F=/etc/filebeat/filebeat.yml
OPENSEARCH_PORT=9200

if [ -f $F ]; then
    PASS=$(grep "^[ 	]*\(export \)\?OPTIONS=" /scripts/ogfunctions 2>&1 |sed 's/\(.*\)pass=\(\w*\)\(.*\)/\2/')     ## taken from a sibling script
    PASS=${PASS:-"og"}
    PASS=OG+$(echo -n $PASS |sha256sum |cut -c1-12)      ## og KDF
    chmod 0600 $F
    sed -i -e "s/__OGLOG_IP__/$oglog/g"             \
           -e "s/__OGLOG_PORT__/$OPENSEARCH_PORT/g" \
           -e "s/__OPENSEARCH_PASSWORD__/$PASS/g"   \
           $F
    unset PASS

    mkdir -p /var/log/filebeat
    /usr/bin/filebeat -c $F --path.home /usr/share/filebeat --path.config /etc/filebeat --path.data /var/lib/filebeat --path.logs /var/log/filebeat &
fi
