Splunk Search

How to filter a record among multiple events

febbi
Explorer

I have a table like in splunk this:

appname valuetime
app1102020-12-30
app1122020-12-31
app2232020-12-30
app2202020-12-31

 

I want to filter the records that the value is increasing while the time. In this case, we can only find 

(app1, 12 2020-12-31)

How could I write the splunk sql to implement this?

Labels (1)
0 Karma
1 Solution

tread_splunk
Splunk Employee
Splunk Employee

No problem.  The solution I posted works for multiple rows per app.

Just add...

| streamstats count by app
| eval count="Row ".count
| xyseries app count value

Definitely worth getting to grips with xyseries and untable commands. 

View solution in original post

0 Karma

tread_splunk
Splunk Employee
Splunk Employee
index=_internal 
| rename sourcetype as app 
| timechart count span=5m by app partial=f limit=0 
| untable _time,app,count 
| sort app,_time,count 
| streamstats count as counter by app
| eventstats count as total by app 
| streamstats sum(count) as prevCount by app window=1 current=f global=f 
| eval delta=count-prevCount 
| where counter=total AND delta>0

How about this?  Lines 1-5 are to create some test data.  The rest is the solution.

0 Karma

tread_splunk
Splunk Employee
Splunk Employee

I've used

| streamstats sum(count) as prevCount by app window=1 current=f global=f 

 

...instead of delta because I've assumed  you want / need the "by app" clause.

I've also assumed you only want to know when the most recent event (per app) has a larger value than the previous event

0 Karma

febbi
Explorer

Thanks for your answer, but it still doesn't work for me. 

Are there ant ways to convert the table to 

appnamerow1row2
app11012
app22330

Then I can compare the "row1 < row2".

Thanks again

Tags (1)
0 Karma

tread_splunk
Splunk Employee
Splunk Employee

Will each app (app1, app2 etc)  only ever have 2 values?

0 Karma

febbi
Explorer

Each app may have several values, we need to convert the values to different columns according to the same app.

0 Karma

tread_splunk
Splunk Employee
Splunk Employee

No problem.  The solution I posted works for multiple rows per app.

Just add...

| streamstats count by app
| eval count="Row ".count
| xyseries app count value

Definitely worth getting to grips with xyseries and untable commands. 

0 Karma

febbi
Explorer

It works for me!, Thanks very much!

0 Karma

tread_splunk
Splunk Employee
Splunk Employee
index=_internal 
| rename sourcetype as app 
| timechart count span=5m by app partial=f limit=0 
| untable _time,app,count 
| sort app, _time 
| streamstats count as counter by app 
| eventstats count as total by app 
| where counter=1 OR counter=total 
| table app count _time 
| rename count as value 
| streamstats count by app 
| eval count="Row ".count 
| xyseries app count value

Assuming you only have 2 rows per app, and you already have the data as per your table, then you just need the last 3 lines in the above.  Everything above that is to generate some test data in the same format as your table.

0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @febbi,

Please try below;

| sort time
| delta value as value_diff
| where value_diff > 0
If this reply helps you an upvote and "Accept as Solution" is appreciated.
0 Karma

febbi
Explorer

Thanks for your answer, but it still doesn't work for me. 

Are there ant ways to convert the table to 

appnamerow1row2
app11012
app22330

Then I can compare the "row1 < row2".

Thanks again

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

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