Splunk Search

Sum of values and max (or last) value in the same query

piretro999
New Member

Hello I have to build up a query on Splunk, on wich I am a real newbie.
I have a sheet in wich every record contains a name, an event, some points related to the single event and a sum of the points that comes from all the previous events plus the present one.
E.G.
|Person |Action |Pt |Tot|
|John |"eats a pie" | 1 | 1|
|John |"does a jump" | 3| 4|
|John |"goes to bed" | 5| 9|
|Tim |"tells a lie" | 7| 11 |

The query should show should be something like this
|Person |Pt|Tot|
|John | 9| 9|
|Tim | 7| 11|

As a next step, if the two values does not match (like for Tim), then an alert is raised.
What query can I implement?
Thank you.
Paolo

Tags (1)
0 Karma

adonio
Ultra Champion

hello there,
considering the Tot field values are accumulative and accurate you can try something like this maybe:
... your search ... | stats sum(Pt) as Points max(Tot) as accum_total by Person
then apply your alert rule either in search or while saving as an alert.
in search | where Point!=accum_total
in alert | search Point!=accum_total
hope it helps

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try something like this

your base search which gives fields Person, Action Pt Tot
| stast sum(Pt) as Pt max(Tot) as Tot by Person
| where Pt!=Tot

You can setup alert using this query when "number of events is greater than 0" (means there is a mismatch in Pt and Tot)

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

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