Security

Compare results from 2 searches

RahulMisra1
Explorer

Hi, 

 

I am running a search to get count of IP';s from yesterday & last month.

index=<> source="/****" IP!="10.*" [| inputlookup ip_tracking.csv | rename MIDS AS MID | format ] earliest=-30d@d latest=now| eval ReportKey="Last30Day"|append [search index=<> source=""/****"" IP!="10.*" [| inputlookup ip_tracking.csv | rename MIDS AS MID | format ] earliest=-1d@d latest=@d | eval ReportKey="yesterday"]| eval Day=if(_time<=relative_time(now(),"-30d@d"),"yesterday","Last30Day")
| stats count(eval(Day="yesterday")) AS yesterday count(eval(Day="Last30Day")) AS Last30Day BY IP

 

 

This search is giving me all results in Month but not in yesterday. Can you help me in correcting the query

RahulMisra1_0-1718112201454.png

 

0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@RahulMisra1 It looks like you have double accounting - you are counting yesterday twice because your first search is -30 days to NOW, which includes yesterday and then you append yesterday's data, so you will effectively count yesterday twice.

You don't actually need the append as you already have the data from the first search to calculate yesterday.

One question though - is your last 30 days supposed to include yesterday - anyway this search should work

index=<> source="/****" IP!="10.*" earliest=-30d@d latest=now 
[
  | inputlookup ip_tracking.csv 
  | rename MIDS AS MID 
  | format 
] 
``` If the data time is -1d to end of day, then the data is yesterday ```
| eval Day=if(_time>=relative_time(now(),"-1d@d") AND _time<=relative_time(now(),"@d"),"yesterday","Last30Day") 
``` Now count yesterday, but then count last 30 days as ALL items, which 
    includes yesterday ```
| stats count(eval(Day="yesterday")) AS yesterday count AS Last30Day BY IP

The final count as last30Day will just count all items in the search including yesterday - if you want that to exclude yesterday BUT also include today up to now, then use your original eval statement in the count.

 

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@RahulMisra1 It looks like you have double accounting - you are counting yesterday twice because your first search is -30 days to NOW, which includes yesterday and then you append yesterday's data, so you will effectively count yesterday twice.

You don't actually need the append as you already have the data from the first search to calculate yesterday.

One question though - is your last 30 days supposed to include yesterday - anyway this search should work

index=<> source="/****" IP!="10.*" earliest=-30d@d latest=now 
[
  | inputlookup ip_tracking.csv 
  | rename MIDS AS MID 
  | format 
] 
``` If the data time is -1d to end of day, then the data is yesterday ```
| eval Day=if(_time>=relative_time(now(),"-1d@d") AND _time<=relative_time(now(),"@d"),"yesterday","Last30Day") 
``` Now count yesterday, but then count last 30 days as ALL items, which 
    includes yesterday ```
| stats count(eval(Day="yesterday")) AS yesterday count AS Last30Day BY IP

The final count as last30Day will just count all items in the search including yesterday - if you want that to exclude yesterday BUT also include today up to now, then use your original eval statement in the count.

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Double-check the calculation for the Day field.  Events less than a day old will have *greater* timestamps than older events.

eval Day=if(_time>=relative_time(now(),"-1d@d"),"yesterday","Last30Day")
---
If this reply helps you, Karma would be appreciated.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...