Splunk Search

Eventstats, eval and "category" assignment

betto86
Engager

Hi all 🙂

I need you help because I can't figure out how to solve this problem.
Suppose we have a table, made of two fields, as the one following:

Name    Value

A        1.1  
A        0.3  
A        1.9  
A        1.2  
A        0.9  
B        0.9  
B        0.9  
B        1.1  
B        1.6  

I need to create a new field (Id) in order to assign to values for each name, a sort of category following this rule:

Values with the same ID are contiguous values in range 0.7 < Value < 1.3. If the value is out of this interval, assign a new Id. When parsing a new Name value, the Id must restart from 0.

That is, I need to obtain this table:

Name    Value    Id

A        1.1     0   
A        0.3     1
A        1.9     2
A        1.2     3
A        0.9     3
B        0.9     0
B        0.9     0
B        1.1     0
B        1.6     1

This is a part of my search:

eval id = 0 |
streamstats current=t global=f window=2 first(id) as precId last(Value) as currValue  by Name |
eval id=if((currValue  > 0.7 AND currValue  < 1.3), precId, precId+1) |
table myTime,  process, destip, _time , absTmp, mediana, rapporto, id, heartId, currRapporto, precId, newId

I'm just parsing each row with streamstats, taking information from the previous row in order to know the correct Id to assign to the parsed row. But it seems not to work.

Any help or suggestion will be appreciated,

thank you guys! 🙂

Tags (1)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Consider this:

| stats count | eval foo = "A-1.1,A-0.3,A-1.9,A-1.2,A-0.9,B-0.9,B-0.9,B-1.1,B-1.6" | makemv foo delim="," | mvexpand foo | eval Name = replace(foo, "-.*", "") | eval Value = tonumber(replace(foo, ".*-", "")) | fields - count foo | eval temp = if(0.7 < Value AND Value < 1.3, 0, 1) | delta temp as delta | eval temp = if(delta == -1, 1, temp) | streamstats sum(temp) as Id by Name | fields - temp delta
0 Karma
Get Updates on the Splunk Community!

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...