Splunk Search

How do I add a time range to a datamodel search that cannot use tstats?

scottrunyon
Contributor

I have a data model where the object is generated by a search which doesn't permit the DM to be accelerated which means no tstats. I am wanting to do a appendcols to get a delta between averages for two 30 day time ranges. The search I am trying to get to work is:

| datamodel TEST One search
| drop_dm_object_name("One")

| dedup host-ip plugin_id

| where severity > 0
| where earliest=-30d@d latest=+0s
| stats dc(plugin_id) AS signature_count by host-ip
| stats avg(signature_count) as current_avg
| appendcols [| datamodel TEST One search | drop_dm_object_name("One") | dedup host-ip plugin_id | where severity > 0 | where earliest=--60d@d latest=-30d@d | stats dc(plugin_id) AS signature_count by host-ip | stats avg(signature_count) as historical_avg]
| get_delta(current_avg,historical_avg)

I know the bold items are incorrect, but I am using them as place holders to show the time ranges that are broken out.

So what the heck am I doing wrong? Thanks in advance for any help.

1 Solution

somesoni2
Revered Legend

How about this (assuming your data model has time field)

| datamodel TEST One search | where _time>relative_time(now(),"-60d@d")
| eval period=if(_time>relative_time(now(),"-30d@d"),"current_avg","historical_avg")
| drop_dm_object_name("One") 
| dedup period host-ip plugin_id 
| where severity > 0
| stats dc(plugin_id) AS signature_count by period host-ip  
| stats avg(signature_count) as avg by period | eval temp=1
| xyseries temp period avg | fields - temp 
| get_delta(current_avg,historical_avg)

View solution in original post

0 Karma

somesoni2
Revered Legend

How about this (assuming your data model has time field)

| datamodel TEST One search | where _time>relative_time(now(),"-60d@d")
| eval period=if(_time>relative_time(now(),"-30d@d"),"current_avg","historical_avg")
| drop_dm_object_name("One") 
| dedup period host-ip plugin_id 
| where severity > 0
| stats dc(plugin_id) AS signature_count by period host-ip  
| stats avg(signature_count) as avg by period | eval temp=1
| xyseries temp period avg | fields - temp 
| get_delta(current_avg,historical_avg)
0 Karma

scottrunyon
Contributor

This works perfectly. Thank you for the help.

0 Karma

jarekczeking
Engager

When I use _time it still respects the time filter from the dialog box, which I want to avoid. Both conditions are checked, while only the one in query should be considered.

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...