I want to calculate todays date data and previous day data from the host. Please suggest SPL for this.
Hi @uagraw01,
if in yyour search you can use only the index time fields (index, sourcetyoe, source and host) you can use "|metasearch", having someting like this:
| metasearch index=_internal earliest=-d@d latest=now
| eval date_year=strftime(_time,"%Y"), date_month=strftime(_time,"%B"),date_mday=strftime(_time,"%d")
| eval now_date_year=strftime(now(),"%Y"), now_date_month=strftime(now(),"%B"),now_date_mday=strftime(now(),"%d")
| eval day=if(date_year=now_date_year AND date_month=now_date_month AND date_mday=now_date_mday,"Today","Previous")
| stats count BY day
| delta count AS diff
| reverse
| table diff
| head 1
Ciao.
Giuseppe
hi @uagraw01 just curious - earliest and latest variables are ok or not ok?
Hi @uagraw01,
see if this example solves your need:
index=_internal
| eval day=if(date_year=strftime(now(),"%Y") AND date_month=lower(strftime(now(),"%B")) AND date_mday=strftime(now(),"%d"),"Today","Previous")
| stats count BY day
Ciao.
Giuseppe
@gcusello I want the difference between pervious day count of the host and current day count of the host. I want comparison panel in my dashboard
Hi @uagraw01,
as I said, I don't know in deep your need, but you can use my approach.
so using a search like mine you can display the count of events of today and previous day so you can compare the two numbers.
If you want more help, you should share more infos, e.g.:
so if you want to display the diference in numer of logging hosts between today and yesterday, you could run something like this:
index=_internal earliest=-d@d latest=now
| eval day=if(date_year=strftime(now(),"%Y") AND date_month=lower(strftime(now(),"%B")) AND date_mday=strftime(now(),"%d"),"Today","Previous")
| stats dc(host) AS hosts BY day
| delta hosts AS diff
| table diff
Ciao.
Giuseppe
Ciao.
Giuseppe
@gcusello Can you suggest me another method. I mean another SPL. Because this search is very slow while executing.
Hi @uagraw01,
if in yyour search you can use only the index time fields (index, sourcetyoe, source and host) you can use "|metasearch", having someting like this:
| metasearch index=_internal earliest=-d@d latest=now
| eval date_year=strftime(_time,"%Y"), date_month=strftime(_time,"%B"),date_mday=strftime(_time,"%d")
| eval now_date_year=strftime(now(),"%Y"), now_date_month=strftime(now(),"%B"),now_date_mday=strftime(now(),"%d")
| eval day=if(date_year=now_date_year AND date_month=now_date_month AND date_mday=now_date_mday,"Today","Previous")
| stats count BY day
| delta count AS diff
| reverse
| table diff
| head 1
Ciao.
Giuseppe
@gcusello It is working fine now . Thanks for yours extended help.
Hi @uagraw01,
good for you, please accept the answer for the other people of Community.
Ciao and happy splunking.
Giuseppe
Below is "no result" i am getting. I need todays day count, previous day count and the difference between todays count and previous day count. From the above query as you suggested not getting any results.
Hi @uagraw01,
this is because you have only today's events!
enlarge your data frame and you'll have results.
Ciao.
Giuseppe