Running Grafana v12.1.1
I’m new to Grafana and Loki so please be gentle ![]()
I would imagine what I’m trying to do should be straightforward but I’m running into a wall and, from the searching I’ve done, other people are struggling with this as well.
I’m trying to filter HAProxy logs for various keywords against specific fields. My HAProxy logs are being sent at JSON and they’re being parsed fine by Loki.
I’m using a Textbox variable and the search works fine if I enter the appropriate variable but I’m trying to work out how to show all / don’t filter based on this variable if the variable is null / ““ / whatever an empty textbox translates to.
Any suggestions I can find online basically translate to a regex that is “use the value of the variable OR .*” but that’s always going to show all results.
In the code below, I’m using a JSON field “unique_id” but the plan is to have several of these e.g., filter by hostname, source IP, HTTP Verb, etc. I know the example below doesn’t have any handling for blank values, no point in including the non-working hacks I’ve attempted.
I can also make this work by setting the textbox to “.*” but that’s not very user friendly?
{app="haproxy-ingress",log_bucket="grafana"}
| json
| unique_id=~"^${UniqueID}$"
| line_format " {{ if eq .coraza_decision `deny` }} ! WAF !{{ else }} | {{ .status_code }} |{{ end }} {{ printf \"%15s\" .source_ip}} -> {{ printf \"%-4s\" .http_verb}} {{.http_uri}} "
Any help greatly appreciated