Splunk Search

multiple Case conditions?

karthi2809
Builder

Hi,

I am using multiple case conditions but the condition is not matching. In the third line of the code used AND condition for message=*End of GL* AND tracepoint=*Exception* .If the condition match make to success.In my case its showing both SUCCESS and ERROR in the table.

 

 

| eval Status=case(
    like('Status' ,"%SUCCESS%") ,"SUCCESS", 
    like('message' ,"%End of GL-import flow%") AND  like('tracePoint',"%EXCEPTION%") ,"SUCCESS",
    like('tracePoint',"%EXCEPTION%") AND like('priority' ,"%ERROR%"),"ERROR",
    like('Status',"%ERROR%"),"ERROR",
    like('priority',"%WARN%"),"WARN",
    like('priority',"GLImport Job Already Running, Please wait for the job to complete%"),"WARN",
    like('message',"%End of GL Import process - No files found for import to ISG%"), "ERROR", 1==1, "") 

 

 

 

Labels (2)
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

when your field names are not contained any special characters, it’s safer and easier to left ‘ away.

Basically those conditions seems to be ok.

Can you give some samples which are not working?

r. Ismo

0 Karma

karthi2809
Builder

The condition is not working for me 
like('message' ,"%End of GL-import flow%") AND like('tracePoint',"EXCEPTION") ,"SUCCESS",
If the message value=End of GL-import flow and tracepoint values=Exception then it should be SUCCESS.Screen shot attached below

index="mulesoft" applicationName="p-oracle-finance-ext" environment=DEV 
    (*End of GL-import flow*) OR (tracePoint="EXCEPTION") OR (priority="WARN" AND message="GLImport Job Already Running, Please wait for the job to complete*") 
    OR ( message="End of GL Import process - No files found for import to ISG") 
| rename content.File.fstatus as Status 
| eval Status=case(
    like('Status' ,"SUCCESS") ,"SUCCESS", 
    like('message' ,"%End of GL-import flow%") AND  like('tracePoint',"EXCEPTION") ,"SUCCESS",
    like('tracePoint',"EXCEPTION") AND like('priority' ,"%ERROR%"),"ERROR",
    like('Status',"ERROR"),"ERROR",
    like('priority',"WARN"),"WARN",
    like('priority',"GLImport Job Already Running, Please wait for the job to complete%"),"WARN",
    like('message',"%End of GL Import process - No files found for import to ISG%"), "ERROR", 1==1, "") 
| stats values(content.File.fid) as "TransferBatch/OnDemand" values(content.File.fname) as "BatchName/FileName" values(content.File.fprocess_message) as ProcessMsg 
    values(Status) as Status values(content.File.isg_file_batch_id) as OracleBatchID values(content.File.total_rec_count) as "Total Record Count" values(message) as message values(timestamp) as timestamp values(content.errorType) as errorType by correlationId 
| eval ProcessMsg= coalesce(ProcessMsg,errorType,message) 
| eventstats min(timestamp) AS Start_Time, max(timestamp) AS End_Time by correlationId 
| eval StartTime=round(strptime(Start_Time, "%Y-%m-%dT%H:%M:%S.%QZ")) 
| eval EndTime=round(strptime(End_Time, "%Y-%m-%dT%H:%M:%S.%QZ")) 
| eval ElapsedTimeInSecs=EndTime-StartTime 
| eval "Total Elapsed Time"=strftime(ElapsedTimeInSecs,"%H:%M:%S") 
| table Status Start_Time "TransferBatch/OnDemand" "BatchName/FileName" ProcessMsg OracleBatchID "Total Record Count" ElapsedTimeInSecs "Total Elapsed Time" correlationId 
| join correlationId type=left 
    [ search index="mulesoft" applicationName="p-oracle-finance-ext" environment=DEV 
        (message="API: START: /v1/revpro-to-oracle/onDemand*") OR (message="API: START: /v1/fin_Zuora_GL_Revpro_JournalImport") OR (message="API: START: /v1/revproGLImport/onDemand*") 
    | eval JobType=case(
        like('message',"API: START: /v1/revproGLImport/onDemand%"),"OnDemand",
        like('message',"API: START: /v1/revpro-to-oracle/onDemand%"),"OnDemand",
        like('message',"API: START: /v1/fin_Zuora_GL_Revpro_JournalImport"),"Scheduled") 
    | table JobType correlationId ] 
| table Status JobType Start_Time "TransferBatch/OnDemand" "BatchName/FileName" ProcessMsg OracleBatchID "Total Record Count" ElapsedTimeInSecs "Total Elapsed Time" correlationId 
| fields - ElapsedTimeInSecs 
| where JobType!=" "

 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You need to show sample data that doesn't work with the case function fails to produce expected result, then the actual results.  The stats just makes troubleshooting more difficult.  But even if you want to include stats, you still need to show sample data.

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Based on your SPL and screenshot it seems to be a MV field. Some yours stats have combined it from several correlationId or what ever you have after by on stats.

0 Karma

karthi2809
Builder

Stats combined the unique correlation ID.

0 Karma

isoutamo
SplunkTrust
SplunkTrust
And at same time it convert that field (result of case) to multivalue field which contains both those values.
As @yuanliu said, you must provide sample data which produce that "error", if you want that we can help you.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...