Splunk Search

Give results by email and days of the week on one row with Yes, No or Null for the past week

CSULeigh
Explorer

I am trying to get the data into a chart from an index were a user may answer a question daily. 

This is what I need to produce:

emailsunmontuewedthufrisat
bob@email.com-NONONOYes--
aaron@email.comYes--NO---
chuck@email.comNONONOYesNO-Yes


This i s what I am currently getting:

emailsunmontuewedthufrisat
bob@email.com----Yes--
bob@email.com---NO---
bob@email.com--NO----
bob@email.com-NO-----
aaron@email.com---NO---
aaron@email.com---NO---
aaron@email.comYes------
chuck@email.com--NO----
chuck@email.com----NO--
chuck@email.com---Yes---
chuck@email.comNO------
chuck@email.com-NO-----
chuck@email.com------Yes


Here is what I have so far, but I am stuck and not to sure what process I should use:
index=someindex 
| eval qualdayOfWeek=strftime(_time, "%a")
| rex field=_raw "is\s(?<status>(NO|YES))\sto"
| eval sun=if(qualdayOfWeek="Sun", $status$, "-")
| eval mon=if(qualdayOfWeek="Mon", $status$, "-")
| eval tue=if(qualdayOfWeek="Tue", $status$, "-")
| eval wed=if(qualdayOfWeek="Wed", $status$, "-")
| eval thu=if(qualdayOfWeek="Thu", $status$, "-")
| eval fri=if(qualdayOfWeek="Fri", $status$, "-")
| eval sat=if(qualdayOfWeek="Sat", $status$, "-")
| table email, sun, mon, tue, wed, thu, fri, sat

Labels (5)
0 Karma
1 Solution

gcato
Contributor

Hi @CSULeigh 

You want to use stats to group by email.  Give this a try...

 

index=someindex 
| eval qualdayOfWeek=strftime(_time, "%a")
| rex field=_raw "is\s(?<status>(NO|YES))\sto"
| eval {qualdayOfWeek}=case(
          qualdayOfWeek="Sun", $status$
         ,qualdayOfWeek="Mon", $status$
         ,qualdayOfWeek="Tue", $status$
         ,qualdayOfWeek="Wed", $status$
         ,qualdayOfWeek="Thu", $status$
         ,qualdayOfWeek="Fri", $status$
         ,qualdayOfWeek="Sat", $status$
         ,true(), "-" )   
| table email, Sun, Mon, Tue, Wed, Thu, Fri, Sat
| stats values(*) AS * BY email

 

I've also shown how to use an eval "case" statement with a field name substitution i.e. {field} - not that it really matters and could use eval.  You could also "rename" the colums to lowercase if you prefer (| rename Sun AS sun Mon AS mon Tue AS ...).

Also note that you if you time period goes over multiple weeks that you may have more than one result per week day column.

Hope this helps.

 

View solution in original post

0 Karma

thambisetty
SplunkTrust
SplunkTrust
index=someindex 
| eval qualdayOfWeek=strftime(_time, "%a")
| rex field=_raw "is\s(?<status>(NO|YES))\sto"
| eval sun=if(qualdayOfWeek="Sun", $status$, "-")
| eval mon=if(qualdayOfWeek="Mon", $status$, "-")
| eval tue=if(qualdayOfWeek="Tue", $status$, "-")
| eval wed=if(qualdayOfWeek="Wed", $status$, "-")
| eval thu=if(qualdayOfWeek="Thu", $status$, "-")
| eval fri=if(qualdayOfWeek="Fri", $status$, "-")
| eval sat=if(qualdayOfWeek="Sat", $status$, "-")
| stats values(status) as status by email, sun, mon, tue, wed, thu, fri, sat
————————————
If this helps, give a like below.
0 Karma

gcato
Contributor

Hi @CSULeigh 

You want to use stats to group by email.  Give this a try...

 

index=someindex 
| eval qualdayOfWeek=strftime(_time, "%a")
| rex field=_raw "is\s(?<status>(NO|YES))\sto"
| eval {qualdayOfWeek}=case(
          qualdayOfWeek="Sun", $status$
         ,qualdayOfWeek="Mon", $status$
         ,qualdayOfWeek="Tue", $status$
         ,qualdayOfWeek="Wed", $status$
         ,qualdayOfWeek="Thu", $status$
         ,qualdayOfWeek="Fri", $status$
         ,qualdayOfWeek="Sat", $status$
         ,true(), "-" )   
| table email, Sun, Mon, Tue, Wed, Thu, Fri, Sat
| stats values(*) AS * BY email

 

I've also shown how to use an eval "case" statement with a field name substitution i.e. {field} - not that it really matters and could use eval.  You could also "rename" the colums to lowercase if you prefer (| rename Sun AS sun Mon AS mon Tue AS ...).

Also note that you if you time period goes over multiple weeks that you may have more than one result per week day column.

Hope this helps.

 

0 Karma
Get Updates on the Splunk Community!

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

A Guide To Cloud Migration Success

As enterprises’ rapid expansion to the cloud continues, IT leaders are continuously looking for ways to focus ...

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...