refs #1719 adds filebeat function installer

filebeat-installer
Luis Gerardo Romero Garcia 2025-03-18 07:33:03 +01:00
parent 86a5c81f71
commit 71291cc8d2
1 changed files with 36 additions and 0 deletions

View File

@ -144,6 +144,41 @@ def boottoolsInitrdGenerate (osrelease):
os.chdir ('/tmp')
shutil.rmtree ('undone')
def setup_filebeat():
deb_path = "/etc/filebeat/filebeat-oss-7.12.1-amd64.deb"
try:
# Instalar Filebeat desde el .deb directamente
subprocess.run(["dpkg", "-i", "--force-overwrite", deb_path], check=True)
# (Opcional) Garantizar permisos adecuados sobre los certificados y configuraciones
subprocess.run(["chmod", "644", "/etc/filebeat/ogagent-fb.mytld.crt.pem"], check=True)
subprocess.run(["chmod", "600", "/etc/filebeat/ogagent-fb.mytld.key.pem"], check=True)
subprocess.run(["chmod", "644", "/etc/ssl/certs/ca.crt.pem"], check=True)
subprocess.run(["chmod", "644", "/etc/filebeat/filebeat.yml"], check=True)
# Añadir entrada al /etc/hosts
oglog_ip = os.getenv('OGAGENTCFG_OGLOG_IP', '192.168.2.4')
with open('/etc/hosts', 'a') as f:
f.write(f"{oglog_ip} oglog-os.mytld\n")
# Ejecutar Filebeat directamente sin systemd
subprocess.Popen([
"/usr/bin/filebeat",
"-c", "/etc/filebeat/filebeat.yml",
"--path.home", "/usr/share/filebeat",
"--path.config", "/etc/filebeat",
"--path.data", "/var/lib/filebeat",
"--path.logs", "/var/log/filebeat"
])
print("Filebeat instalado y ejecutándose correctamente.")
except subprocess.CalledProcessError as e:
print(f"Error instalando Filebeat: {e}")
except Exception as ex:
print(f"Error inesperado al configurar Filebeat: {ex}")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
@ -165,3 +200,4 @@ if __name__ == '__main__':
boottoolsRemovePackages()
setup_resolvconf() ## do this again, since someone seems to be overwriting the file
boottoolsInitrdGenerate (args.osrelease)
setup_filebeat()