I need to extract a part related to the container_name from the log file name and use it as a field in the fluentbit output.
For example given a log file name:
kube.default.var.log.containers.xml-builder-66587b7696-ns9bq_default_xml-builder-ded2966c8929ad811b9468916a071b6fbb445034ac014e28af23654c1ba4ca4a.log
I would like to extract from it and use the part:
xml-builder-66587b7696
In the documentation I saw that the Tag and Tag_Regex could be used but it is not clear on how to extract the fields based on this information...
Below is a part of my fluentbit configuration:
data:
# Configuration files: server, input, filters and output
# ======================================================
fluent-bit.conf: |
[SERVICE]
Flush 1
Log_Level info
Daemon off
Parsers_File parsers.conf
HTTP_Server On
HTTP_Listen 0.0.0.0
HTTP_Port 2020
@INCLUDE input-kubernetes.conf
@INCLUDE filter-kubernetes.conf
@INCLUDE output-kafka.conf
input-kubernetes.conf: |
[INPUT]
Name tail
Tag kube.default.*
Path /var/log/containers/*default*.log
Parser docker
Tag kube.<namespace_name>.<pod_name>.<container_name>
Tag_Regex (?<pod_name>[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)_(?<namespace_name>[^_]+)_(?<container_name>.+)-
DB /var/log/flb_kube.db
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
My question: How can I use the information from the Tag and Tag_Regexp to use it in the filter that performs Modify operation?
[FILTER]
Name record_modifier
Match *
Record custom_field <what to add here?>
It seems that the code below will not work:
[FILTER]
Name record_modifier
Match *
Record custom_field kube.<namespace_name>.<pod_name>.<container_name>
Is there any way to extract this information (container_name) from the log file name or some other approach should be used (let's say kubernetes plugin and then customization of the output with adding or modifying the information returned by kubernetes)?
Thank you.