Splunk Enterprise

Eval statement help

jerinvarghese
Communicator

HI All,

I need your help in getting a value set for a particular keyword matching 2 parameters with eval statement.

Below is  my query.

 

 

index=itsm
    ~truncated~

    | eval CRITICAL=if(Impact="1-Extensive" AND Urgency="1-Critical",1,0) 
    | eval CRITICAL=if(Impact="2-Significant" AND Urgency="1-Critical",1,0) 
    | eval CRITICAL=if(Impact="1-Extensive" AND Urgency="2-High",1,0) 
    
    | eval HIGH=if(Impact="2-Significant" AND Urgency="3-Medium",1,0) 
    | eval HIGH=if(Impact="2-Significant" AND Urgency="4-Low",1,0) 
    | eval HIGH=if(Impact="2-Significant" AND Urgency="2-High",1,0) 
    | eval HIGH=if(Impact="1-Extensive" AND Urgency="3-Medium",1,0) 
    | eval HIGH=if(Impact="1-Extensive" AND Urgency="4-Low",1,0) 
    
    | eval MEDIUM=if(Impact="3-Moderate" AND Urgency="1-Critical",1,0) 
    | eval MEDIUM=if(Impact="3-Moderate" AND Urgency="2-High",1,0) 
    | eval MEDIUM=if(Impact="3-Moderate" AND Urgency="3-Medium",1,0) 
    | eval MEDIUM=if(Impact="4-Minor" AND Urgency="1-Critical",1,0) 
    | eval MEDIUM=if(Impact="4-Minor" AND Urgency="2-High",1,0) 
    
    | eval LOW=if(Impact="3-Moderate" AND Urgency="4-Low",1,0)
    | eval LOW=if(Impact="4-Minor" AND Urgency="4-Low",1,0)
    | eval LOW=if(Impact="4-Minor" AND Urgency="3-Medium",1,0)
    
    
    | table Incident_Number, Impact, Urgency, CRITICAL, HIGH, MEDIUM, LOW

 

 

 

I will get Incident_Number, Impact and Urgency from the index. I tried above combination, but am not getting exact value.

 

CRITICAL, HIGH, MEDIUM, LOW : are the combination of impact and urgency.

 

below is the table that am looking for. please help me with this.

 

Incident_Number

Impact

Urgency

CRITICAL

HIGH

MEDIUM

LOW

INC000013677484

4-Minor

4-Low

0

0

0

1

INC000013677686

2-Significant

2-High

0

1

0

0

Labels (1)
0 Karma
1 Solution

damann
Communicator

Let's look at the following example:
You got an event with impact="1-Extensive" and Urgency="1-critical"

your first eval sets CRITICAL to TRUE.
Your second eval sets CRITICAL to FALSE as your third one does.

You can solve your problem by using a case statement:

| eval CRITICAL=case(Impact="1-Extensive" AND Urgency="1-Critical",1,
Impact="2-Significant" AND Urgency="1-Critical",1,
Impact="1-Extensive" AND Urgency="2-High",1,
1=1,0)

 

repeat above approach with your eval HIGH, MEDIUM and LOW

View solution in original post

0 Karma

damann
Communicator

Let's look at the following example:
You got an event with impact="1-Extensive" and Urgency="1-critical"

your first eval sets CRITICAL to TRUE.
Your second eval sets CRITICAL to FALSE as your third one does.

You can solve your problem by using a case statement:

| eval CRITICAL=case(Impact="1-Extensive" AND Urgency="1-Critical",1,
Impact="2-Significant" AND Urgency="1-Critical",1,
Impact="1-Extensive" AND Urgency="2-High",1,
1=1,0)

 

repeat above approach with your eval HIGH, MEDIUM and LOW

0 Karma

to4kawa
Ultra Champion
index=itsm
    ~truncated~ 
| eval Impact_value=substr(Impact,1,1), Urgency_value=substr(Uragency,1,1) 
| eval status=case(Impact_value <= 2 AND Impact_value + Urgency_value <= 3,"CRITICAL"
    ,Impact_value <= 2 AND Impact_value + Urgency_value <= 5,"HIGH"
    ,Impact_value <= 4 AND Impact_value + Urgency_value <= 6,"MEDIUM"
    ,ture(),"LOW") 
| stats count values(Impact) as Impact values(Urgency) as Urgency by Incident_Number status 
| eval {status} = count 
| fields - status count 
| table Incident_Number Impact Urgency CRITICAL HIGH MEDIUM LOW 
| fillnull CRITICAL HIGH MEDIUM LOW

The case sentence is easier to understand here.

 

0 Karma

jerinvarghese
Communicator

query is helpful , but seems little complex in initial state. but it worked.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Having repeated eval statements setting the same field means only the last one matters.  Try using case, instead.

index=itsm
    ~truncated~

    | eval CRITICAL=case(Impact="1-Extensive" AND Urgency="1-Critical",1, Impact="2-Significant" AND Urgency="1-Critical",1, Impact="1-Extensive" AND Urgency="2-High",1,1==1,0) 
    
    | eval HIGH=case(Impact="2-Significant" AND Urgency="3-Medium",1, 
    Impact="2-Significant" AND Urgency="4-Low",1, Impact="2-Significant" AND Urgency="2-High",1, Impact="1-Extensive" AND Urgency="3-Medium",1, Impact="1-Extensive" AND Urgency="4-Low",1, 1==1, 0) 
    
    | eval MEDIUM=case(Impact="3-Moderate" AND Urgency="1-Critical",1,
Impact="3-Moderate" AND Urgency="2-High",1, Impact="3-Moderate" AND Urgency="3-Medium",1, Impact="4-Minor" AND Urgency="1-Critical",1, Impact="4-Minor" AND Urgency="2-High",1, 1==1, 0) 
    
    | eval LOW=case(Impact="3-Moderate" AND Urgency="4-Low",1, Impact="4-Minor" AND Urgency="4-Low",1, Impact="4-Minor" AND Urgency="3-Medium",1, 1==1, 0)
    
    | table Incident_Number, Impact, Urgency, CRITICAL, HIGH, MEDIUM, LOW

 

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...