Splunk Search

Is this the correct way to extract successful and failed logins from /var/log/secure in a search?

sureshsala
Explorer

I need help with the regular expression for field extraction of login status:

Successful:

source="/var/log/secure" | rex field=_raw " user (?[^ ]+)"| search user="*" | chart count BY host,user 

Failed:

source="/var/log/secure" | rex field=_raw " invalid user (?[^ ]+)"| search user="*" | chart count BY host,user 

Is this the right way to do it, or there is a better way?

Please help.

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Assuming your regex is correctly extracting the users, I would try like this (I would always throw the index and sourcetype as well)

Successfull

index=yourIndex sourcetype=yourSourcetype source="/var/log/secure" "session opened for user " | rex field=_raw "session opened for user (?<user>[^ ]+)"  | chart count BY host,user

Failed

index=yourIndex sourcetype=yourSourcetype  source="/var/log/secure" fail OR invalid | rex field=_raw " invalid user (?<user>[^ ]+)" | chart count BY host,user 

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Assuming your regex is correctly extracting the users, I would try like this (I would always throw the index and sourcetype as well)

Successfull

index=yourIndex sourcetype=yourSourcetype source="/var/log/secure" "session opened for user " | rex field=_raw "session opened for user (?<user>[^ ]+)"  | chart count BY host,user

Failed

index=yourIndex sourcetype=yourSourcetype  source="/var/log/secure" fail OR invalid | rex field=_raw " invalid user (?<user>[^ ]+)" | chart count BY host,user 

sureshsala
Explorer

@somesoni2 Awesome, thanks a lot but failed regex is added NULL user and I am unable to figure out.

0 Karma

sureshsala
Explorer

Answer:

source="/var/log/secure" input_userauth_request AND (fail OR invalid) | rex field=_raw " invalid user (?[^ ]+)" | chart count BY host,user
0 Karma

sundareshr
Legend

What does the log entry look like? Can you share one event with successful logon and one with failed logon?

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...