Splunk Search

How to detect a newly sessionid with SPL and alert.

umou7
Explorer

I want to do a security log monitoring and using splunk alert feature to send email notifications.

 

The security log and trigger condition is like this:

 

_time, SessionID,  filedA, fieldB

yyyymmdd,11111, xxxx,yyyyy

yyyymmdd,11111,bbbb,ccccc

yyyymmdd,22222,bbbb,ccccc

........

 

as this is a syslog monitoring task ,  I want to trigger an alert whenever a newly SessionID is detected.

It means the same SessionIDwill not be notified twice.

 

My SPL will be like below:

....| stats count by SessionID

 

Regarding to the alert configuration, which condition should I use?
Or is it possible to do this mostly in the base SPL?

 

Regards,

 

 

Tags (3)
0 Karma
1 Solution

Nisha18789
Builder

hi @umou7 , another option would be to write the session ids to summary index (you get this option when you create a report). However lookups are faster and you can use a KV store lookup which is faster than a lookup file. 

logic for alert with lookup will be like :

...| table _time, sessionid, otherfield1

| join type=outer sessionid

     [ search |inputlookup sessionhistory.csv

        |table sessionid | eval found_in_history=1]

| where isnull(found_in_history)

|outputlookup sessionhistory.csv append=true

 

now set alert action as email when result count > 0

 

Remember, first time when you are create the lookup you have to run a query for all time to populate the sessionid in the lookup, after that above alert logic will keep appending. 

View solution in original post

0 Karma

Nisha18789
Builder

hi @umou7 , below can be the approach for this:

1) create an inputlookup with all the sessionid's which are present in the log till now.

2) in the alert logic, join with this lookup you created in step1 and filter out the session id which does not match with the session id in lookup. Append this new session_id in the lookup created in step 1 and use alert action to send email if more than zero records found.

If you need help with the query, please let me know.

Please upvote my response if this answers your question.

 

 

 

0 Karma

umou7
Explorer

Thank you very much @Nisha18789  .

I am also considering of using a lookup table.

But I am worry about that the lookuptable will become larger and larger so that it will give an impact on performance.

Could you give me some advice on this?

It would be appreciated if you could give me an example of the query with bellow approaches you mentioned.

Did you mean that put step 1)  in a scheduled search, and put step 2) only in the alert logic ?

 

 

 

 

0 Karma

Nisha18789
Builder

hi @umou7 , another option would be to write the session ids to summary index (you get this option when you create a report). However lookups are faster and you can use a KV store lookup which is faster than a lookup file. 

logic for alert with lookup will be like :

...| table _time, sessionid, otherfield1

| join type=outer sessionid

     [ search |inputlookup sessionhistory.csv

        |table sessionid | eval found_in_history=1]

| where isnull(found_in_history)

|outputlookup sessionhistory.csv append=true

 

now set alert action as email when result count > 0

 

Remember, first time when you are create the lookup you have to run a query for all time to populate the sessionid in the lookup, after that above alert logic will keep appending. 

0 Karma

umou7
Explorer

Thank so much @Nisha18789 ,

This is what I wanted and it works well as expected.

I will populated the sessionids to a KV store lookup as you suggested.

 

Regards,

Mou

 

0 Karma
Get Updates on the Splunk Community!

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 ...

March Community Office Hours Security Series Uncovered!

Hello Splunk Community! In March, Splunk Community Office Hours spotlighted our fabulous Splunk Threat ...

Stay Connected: Your Guide to April Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars in April. This post ...