import { constants, copyFile } from "node:fs/promises"; import { join } from "node:path"; import { Alpine } from "../alpine.js"; import { buildRepro, reproRun } from "../helpers/repro-run.js"; const parsersPath = "/etc/fluent-bit/parsers.conf"; export async function installFluentBit(alpine: Alpine): Promise { const bin = await buildFluentBit(); await saveParsers(alpine); await alpine.addPackages(["musl-fts", "yaml"]); await copyFile( bin, alpine.path("/usr/local/bin/fluent-bit"), constants.COPYFILE_FICLONE ); } // ## Script generators // Returns a logScript to be used with runit for logging to Loki export function runitLokiLogger(parser: FluentBitParser, name: string): string { return `#!/bin/sh exec chpst -u nobody:nobody /usr/local/bin/fluent-bit \ --parser='${parsersPath}' \ --input=stdin \ --prop=parser='${parser}' \ --output=loki \ --prop=labels='job=fluentbit,stream=${name}' `; } // ## Parsers export enum FluentBitParser { Json = "json", Logfmt = "logfmt", // Raw toma todo lo que haya en una lĂ­nea y lo guarda en `message`. No recomendado. Raw = "raw", Forgejo = "forgejo", Ntpsec = "ntpsec", Dhcpcd = "dhcpcd", } async function saveParsers(alpine: Alpine): Promise { // https://github.com/fluent/fluent-bit/blob/master/conf/parsers.conf await alpine.writeFile( parsersPath, // https://rubular.com/ ` [PARSER] name logfmt format logfmt [PARSER] name raw format regex regex ^(?.*?)$ [PARSER] name forgejo format regex regex ^((?