Dashboards & Visualizations

How to calculate on one event into different category ?

Jouman
Path Finder

Hi all,

I want to analyze several events and the fields in them.
Origianally, I use case() to capture one field(Causse) in A_EVENT, and 2 fields(Type, Scenario) in B_event.

 

 

(index="idx_message" Name="A_EVENT" OR Name="B_Event")
| rename "Data.Cause" as A_cause `comment("belong to A_Event")`
| rename "Data.Type" as B_type `comment("belong to B_Event")`
| rename "Data.Scenario" as B_scenario `comment("belong to B_Event")`

| eval Scenario_name=case(
Name="A_EVENT" AND A_cause=0, "A Cause: X reason",
Name="A_EVENT" AND A_cause=1, "A Cause: Y reason",
Name="B_Event" AND B_type=0, "B Type: a category",
Name="B_Event" AND B_type=1, "B Type: b category",
Name="B_Event" AND B_scenario=0, "B Scenario: description 1",
Name="B_Event" AND B_scenario=1, "B Scenario: description 2",
true(), null)

| where isnotnull(Scenario_name)

| chart limit=0 count by Scenario_name 

 

 

However, while I check the output, the output will be

Scenario_namecount
A Cause: X reason1
A Cause: Y reason2
B Type: a category3
B Type: b category4

 

The scenario "B Scenario: description 1" and "B Scenario: description 2" are missing.

I found the reason comes from "B Scenario" and "B Type" is used to verdict the same event, if I use case(), I am unable to get any "B Scenario" because all the events will be verdicted as "B Type" already.

Is there any way to generate such output?

Scenario_namecount
A Cause: X reason1
A Cause: Y reason2
B Type: a category3
B Type: b category4
B Scenario: description 12
B Scenario: description 25

 

Thanks.

Labels (1)
0 Karma
1 Solution

yeahnah
Motivator

Hi @Jouman 

OK I see and you're right the case statement will not work here.  

Here's a run anywhere example that you could try.

 

index=dummy
| append [ | makeresults count=10 | streamstats count 
  | eval raw=if((count%2) = 0, "Name=A_EVENT Data.Cause=0:Name=B_Event Data.Type=0 Data.Scenario=1", "Name=A_EVENT Data.Cause=1:Name=B_Event Data.Type=1 Data.Scenario=0")
        ,raw=split(raw, ":")
  | mvexpand raw
  | rename raw AS _raw
]
| extract  ``` use verbose mode ```
| rename Data_* AS Data.*
  ``` ^^^ create dummy events ^^^ ```
| rename "Data.Cause" as A_cause `comment("belong to A_Event")`
| rename "Data.Type" as B_type `comment("belong to B_Event")`
| rename "Data.Scenario" as B_scenario `comment("belong to B_Event")`
``` event B has two possible scenario types so make a new multivalue field then split and duplicate events by scenario type ```
| eval event_type=split(if(Name=="B_Event", "B_type=".B_type.":B_scenario=".B_scenario, "A_cause=".A_cause), ":")
| mvexpand event_type
| table Name event_type
| eval Scenario_name=case(
   Name="A_EVENT" AND event_type="A_cause=0", "A Cause: X reason",
   Name="A_EVENT" AND event_type="A_cause=1", "A Cause: Y reason",
   Name="B_Event" AND event_type="B_type=0", "B Type: a category",
   Name="B_Event" AND event_type="B_type=1", "B Type: b category",
   Name="B_Event" AND event_type="B_scenario=0", "B Scenario: description 1",
   Name="B_Event" AND event_type="B_scenario=1", "B Scenario: description 2",
   true(), null())
| stats count BY Scenario_name

 

 Hope that helps

View solution in original post

yeahnah
Motivator

Hi @Jouman 

OK I see and you're right the case statement will not work here.  

Here's a run anywhere example that you could try.

 

index=dummy
| append [ | makeresults count=10 | streamstats count 
  | eval raw=if((count%2) = 0, "Name=A_EVENT Data.Cause=0:Name=B_Event Data.Type=0 Data.Scenario=1", "Name=A_EVENT Data.Cause=1:Name=B_Event Data.Type=1 Data.Scenario=0")
        ,raw=split(raw, ":")
  | mvexpand raw
  | rename raw AS _raw
]
| extract  ``` use verbose mode ```
| rename Data_* AS Data.*
  ``` ^^^ create dummy events ^^^ ```
| rename "Data.Cause" as A_cause `comment("belong to A_Event")`
| rename "Data.Type" as B_type `comment("belong to B_Event")`
| rename "Data.Scenario" as B_scenario `comment("belong to B_Event")`
``` event B has two possible scenario types so make a new multivalue field then split and duplicate events by scenario type ```
| eval event_type=split(if(Name=="B_Event", "B_type=".B_type.":B_scenario=".B_scenario, "A_cause=".A_cause), ":")
| mvexpand event_type
| table Name event_type
| eval Scenario_name=case(
   Name="A_EVENT" AND event_type="A_cause=0", "A Cause: X reason",
   Name="A_EVENT" AND event_type="A_cause=1", "A Cause: Y reason",
   Name="B_Event" AND event_type="B_type=0", "B Type: a category",
   Name="B_Event" AND event_type="B_type=1", "B Type: b category",
   Name="B_Event" AND event_type="B_scenario=0", "B Scenario: description 1",
   Name="B_Event" AND event_type="B_scenario=1", "B Scenario: description 2",
   true(), null())
| stats count BY Scenario_name

 

 Hope that helps

Jouman
Path Finder

@yeahnah  Thank you very much. I tried and the code works well. This really helps me a lot.

0 Karma

yeahnah
Motivator

Hi @Jouman 

It's always preferable to provide an example of the raw event(s).  Obfuscate or remove sensitive data, if any.
Please use the Insert/Edit code sample when adding example data

yeahnah_0-1682570993237.png

 

0 Karma

Jouman
Path Finder

@yeahnah  Thanks for the suggestion. I rewrite my question and hope that would be clear.

Thank you!

0 Karma
Get Updates on the Splunk Community!

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

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...