Splunk Search

Combine multiple events for reporting

ndkhoiits
Explorer

Hi,

I'm using splunk for caching the log and reporting, now I need to query in splunk for user action and generate a report. My case will be showed as following

I had several events in a log like :

Now I want to list all actions made by user who read article with articleId is art1. Which search statement can help me?

Tags (2)
0 Karma

lguinn2
Legend

Best case: extract the fields for email, action and article. Then your search will look like this:

yoursearchhere [ search action=Read article="art1" | dedup email | fields email ]

If you must create the fields on-the-fly, the search becomes much more complex:

yoursearchhere [ search yousearchhere  "art1" 
| rex "\[(?<email>\S+@\S+)\]\s(?<action>\S+)\s.*?\:(?<article>.*)"
| search action=Read article=art1 | dedup email | fields email ]

You might want to read the documentation on creating field extractions.

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try below query. Replace "email" with sourcetype of yours:-

sourcetype=email | rex "\[(?P<User>[^@]+)" | search [search sourcetype=email | rex "\[(?P<User>[^@]+)" | rex "\] (?P<Action>[^:]+):(?P<Item>.+)"| table _raw, User, Action,Item | where Action="Read articleId" AND Item="art1"| table User]
0 Karma

somesoni2
SplunkTrust
SplunkTrust

What is your source/log file name? instead of "sourcetype=email", use "source=<>" and try.

0 Karma

ndkhoiits
Explorer

I used your query and always returns no result for that

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Sorry for type. I mean to say that replace "sourcetype=email" with whatever sourcetype you're using. Updated the answer now.

0 Karma

ndkhoiits
Explorer

Hi @somesoni2, what you mean about sourcetype command in your query?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...