diff --git a/src/flux/log-message.go b/src/flux/log-message.go index f871280..bf9fb26 100644 --- a/src/flux/log-message.go +++ b/src/flux/log-message.go @@ -4,12 +4,14 @@ import log "github.com/sirupsen/logrus" var ( HostFieldName string // name of "host" field in json log message - MessageFieldName string // name of "message" field in json log message - RouteFieldName string // name of "route" field in json log message + ProgramFieldName string // name of "program" field + MessageFieldName string // name of "message" field + RouteFieldName string // name of "route" field ) func init() { HostFieldName = GetenvStr("FLUX_HOST_FIELD_NAME", "HOST") + ProgramFieldName = GetenvStr("FLUX_PROGRAM_FIELD_NAME", "PROGRAM") MessageFieldName = GetenvStr("FLUX_MESSAGE_FIELD_NAME", "MESSAGE") RouteFieldName = GetenvStr("FLUX_ROUTE_FIELD_NAME", "ROUTE") } @@ -20,6 +22,10 @@ func (l LogMessage) Host() string { return l.getFieldStr(HostFieldName) } +func (l LogMessage) Program() string { + return l.getFieldStr(ProgramFieldName) +} + func (l LogMessage) Message() string { return l.getFieldStr(MessageFieldName) } @@ -30,6 +36,7 @@ func (l LogMessage) Route() string { func (l LogMessage) Validate() bool { return l.hasField(HostFieldName) && + l.hasField(ProgramFieldName) && l.hasField(MessageFieldName) && l.hasField(RouteFieldName) } diff --git a/src/flux/worker.go b/src/flux/worker.go index ccf372a..ce4180b 100644 --- a/src/flux/worker.go +++ b/src/flux/worker.go @@ -81,9 +81,10 @@ func (w *Worker) Process(message LogMessage) { Debug("worker: parsed tags and values after script") } - // add hostname as tag to point - // NOTE: it overwrites any "tag_host" value from regexp and script + // add hostname and program as tag to influx point + // NOTE: it overwrites any "tag_host" and "tag_program" value from regexp and script tags["host"] = message.Host() + tags["program"] = message.Program() log.WithField("tags", tags). WithField("values", values).