Splunk Search

how to exclude a certain field value from results

ayenumula
Explorer

Search query: list the last known user (userid) on each host.

sourcetype=syslog source=/var/log/secure "pam_unix(sshd:session)" | rex "(?i) user (?P<userid>[^ ]+)" | stats latest(userid) as userid by host, _time | dedup host

I then want to exclude a particular user "system" from the result list.

I tried the NOT and "!=" in every part of the query but not working, can you help me with the search query

Tags (2)
1 Solution

Damien_Dallimor
Ultra Champion
.. | where userid != "system" | ...

or maybe tweak your regex

(?i)\suser\s(?!system)(?P<userid>\w+)

View solution in original post

Damien_Dallimor
Ultra Champion
.. | where userid != "system" | ...

or maybe tweak your regex

(?i)\suser\s(?!system)(?P<userid>\w+)

ayenumula
Explorer

Is there a certain way to exclude multiple users using | where userid != "system"

0 Karma

ayenumula
Explorer

Damien's answer: | where userid != "system". This worked as it included the host (row) which has "system" user but excluded "system" from the result set, it still displayed the host with other users.

I tried Alterdego's answer: "| search userid!=system". This did not work for me because it completely excluded the host (row) which contains the word "system" even thou it contains other users.

0 Karma

alterdego
Path Finder

Does the value "system" appear in the filed you create? If so then you should be able to pipe your original search to the search command and exclude the "system" value with "| search userid!=system".

sourcetype=syslog source=/var/log/secure "pam_unix(sshd:session)" | rex "(?i) user (?P[^ ]+)" | stats latest(userid) as userid by host, _time | dedup host | search userid!=system

Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...