Skip to content

Commit

Permalink
Update filebeat-yml-script.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bardabun committed May 26, 2024
1 parent 273888f commit 080a6aa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions filebeat-yml-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
import os
import socket
from ruamel.yaml import YAML
import subprocess

def get_git_tag():
try:
# Returns the most recent tag
git_tag = subprocess.check_output(["git", "describe", "--tags"], stderr=subprocess.STDOUT).strip().decode('utf-8')
except subprocess.CalledProcessError as e:
logging.error("Failed to get git tag: " + str(e.output.decode('utf-8')))
git_tag = "unknown"
return git_tag

def get_log_level():
default_level = "info"
Expand Down Expand Up @@ -94,6 +103,12 @@ def _add_shipping_data():
with open("docker-collector-logs/default_filebeat.yml") as default_filebeat_yml:
config_dic = yaml.load(default_filebeat_yml)

# Fetch the Git tag
git_tag = get_git_tag()

config_dic["output"]["logstash"]["headers"] = {
"User-Agent": f"logzio-docker-version-{git_tag}-logs"
}
config_dic["output"]["logstash"]["hosts"].append(logzio_url)
config_dic["filebeat.inputs"][0]["fields"] = {}
config_dic["filebeat.inputs"][0]["fields"]["token"] = logzio_token
Expand Down

0 comments on commit 080a6aa

Please sign in to comment.