Splunk Search

Display logs that have a unique field-value

Splunkster45
Communicator

Sorry for the confusing title. Let me explain

When I query this search

| rex field=_raw "Session (?<number>\\w+) (\\((?<username>\\w+)@|)"

I get the following output.

Session 11111 ended
Session 11111 (user1@<ipaddress>) started
Session 55555 (user2@<ipaddress>) started

What I want to do is see the sessions that have been started and not finished. I've been able to capture a field for both the number (11111,55555) and the user (user1, user2). The way I was thinking about doing this is to display only the logs that have a field:number-count equal to 1. In this case, I only want the line with 55555 to display (because there is only 1 instance of it) and do not want the number 1111 to display (as it appears twice).

What is the best way to go about displaying the fields that contains unique instances? Is there a better way to go about doing this?

Thanks in advance!

Tags (4)
0 Karma
1 Solution

Splunkster45
Communicator

Doing some more searching, I found this thread:

http://answers.splunk.com/answers/55060/only-alert-if-event-happens-x-times-but-display-all-events.h...

and now have an answer to my question. The query should look like this:
| eventstats count by number | search count = 1

Thanks for helping me along!

View solution in original post

Splunkster45
Communicator

Doing some more searching, I found this thread:

http://answers.splunk.com/answers/55060/only-alert-if-event-happens-x-times-but-display-all-events.h...

and now have an answer to my question. The query should look like this:
| eventstats count by number | search count = 1

Thanks for helping me along!

theouhuios
Motivator

try |eventstats count(number) as Value|where Value = 1

That should limit it to events which have one occurrence.

0 Karma

Splunkster45
Communicator

hmm... not quite. It looks like this just counts the number of occurrences of the field number as opposed to marking the events that have one occurrence.

0 Karma
Get Updates on the Splunk Community!

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...