#!/bin/bash
# ./fbInstall.sh -env oppein -app pg -docker (mdx logs)
#  ./fbInstall.sh -env uat -cust gaoshan (pm2 logs)
echo "install filebeat"

while [ $# -gt 0 ]; do
  COMMAND=$1
  case $COMMAND in
    -env)
      env=$2
      shift 2
      ;;
    -cust)
      cust=$2
      shift 2
      ;;
    -docker)
      docker=true
      shift
      ;;
    *)
      break
      ;;
  esac
done

fbTpl="filebeat.pm2.yml"
if [[ $docker ]]; then
  fbTpl="filebeat.container.yml"
fi
wget http://tool.epm2demo.cn/elk/filebeat-7.11.2-x86_64.rpm
yum install -y filebeat-7.11.2-x86_64.rpm
wget http://tool.epm2demo.cn/elk/$fbTpl -O /etc/filebeat/filebeat.yml

sed -i "s/cust:.*/cust: $cust/g" /etc/filebeat/filebeat.yml
sed -i "s/env:.*/env: $env/g" /etc/filebeat/filebeat.yml

systemctl restart filebeat