Splunk fields extraction for container logs
For the container logs, forwarded by the collectord, it is possible to specify field extractions rules, specific for image names, container names, or combination of them.
All container logs have source format, which includes container ID, container name, container image name, and stream.
1/docker/{docker_container_id}/{docker_container_name}/{docker_container_image}.{docker_stream}
Using this knowledge you can create field extraction rules for specific image or container, also including glob patterns, using wildcards.
As an example, you can specify field extraction for nginx container in props.conf using a wildcard character for
the container ID, container name, and docker stream. This field extraction applies to all containers created from
the nginx docker image.
1[source::/docker/*/*/nginx:*]
2EXTRACT-nginx-ingress-controller-http = ^(?P<remote_addr>[^ ]+)\s+\-\s+\[(?P<proxy_add_x_forwarded_for>[^\]]+)\]\s+\-\s+(?P<remote_user>[^ ]+)\s+\[(?P<time_local>[^\]]+)[^"\n]*"(?P<request>[^"]+)"\s+(?P<status>\d+)\s+(?P<body_bytes_sent>\d+)\s+"(?P<http_referer>[^"]+)"\s+"(?P<http_user_agent>[^"]+)"\s+(?P<request_length>\d+)\s+(?P<request_time>[^ ]+)\s+\[(?P<proxy_upstream_name>[^\]]+)]\s+(?P<upstream_addr>[^\s]+)\s+(?P<upstream_response_length>\d+)\s+(?P<upstream_response_time>[^\s]+)\s+(?P<upstream_status>\d+)$</code></pre>
You can also find how to use Splunk Fields Extractor to extract fields from container logs in our blog.