Splunk Search

Simple syntax to filter data by _raw value

razlani
Explorer

Hi all - I'm new here (literally an hour old) so go easy.

I've read through parts of the docs and am currently using:

host=crm index=main tag=error | eval kek = regex_raw = "foo@bar.com" | stats count by kek

On data like:

2015-01-16 13:00:19,747 [foo@bar.com] ERROR jelly.fish.cake......

To try and play with data filtered by counting errors from particular usernames in the raw data like so.

I'm almost there but get an error message about using eval on boolean data (the docs of which I've read); but which I've still yet to nail the syntax for.

I've tried using rex, an if statement with eval (as suggested), tostring() (as suggested) and phrasing it differently like piping the data into the eval... but that simply pipes all of the data rather than the usernames I'm interested in - and it seems like I just can't get the syntax right.

Could you please tell me how I could filter data by the email address and count them like I'm trying?

Thanks so much!!

raz

Tags (4)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Assuming you want to filter a single email address, your example could written something like this:

host=crm index=main tag=error "foo@bar.com" | stats count(_time)

This pulls all events from the main index where the host field has the value "crm", are tagged as "error", and contain "foo@bar.com" somewhere in them. It then counts the events found.

Something more generic might be:

host=crm index=main tag=error | rex "\[(?P<addr>[^\]]+)\]" | stats count(_time) by addr

Again, we're looking at all events from the main index where the host field has the value "crm" and are tagged as "error". The rex command extracts anything between square brackets from the _raw field (by default) and puts it into a field called "addr". We then count each addr found.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Assuming you want to filter a single email address, your example could written something like this:

host=crm index=main tag=error "foo@bar.com" | stats count(_time)

This pulls all events from the main index where the host field has the value "crm", are tagged as "error", and contain "foo@bar.com" somewhere in them. It then counts the events found.

Something more generic might be:

host=crm index=main tag=error | rex "\[(?P<addr>[^\]]+)\]" | stats count(_time) by addr

Again, we're looking at all events from the main index where the host field has the value "crm" and are tagged as "error". The rex command extracts anything between square brackets from the _raw field (by default) and puts it into a field called "addr". We then count each addr found.

---
If this reply helps you, Karma would be appreciated.

razlani
Explorer

Thank you both!

0 Karma

somesoni2
Revered Legend

Try this

Get count by email address

host=crm index=main tag=error |  rex "\[(?<kek>.[^\]]+)\]" | stats count by kek

razlani
Explorer

would make both answers correct if I could

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Event Series: Splunk Observability Metrics Cost Optimization

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...

Deep insights, no barriers: Splunk Observability Cloud Free Edition

As software delivery cycles continue to accelerate, observability shouldn’t be a luxury — it should be a ...