Splunk Search

AND OR not working correctly

davidcraven02
Communicator

I am getting the below error when trying to form an AND & OR in my query.

Error in 'eval' command: The expression is malformed. Expected ).

My eval is below:

| eval Action=if((MonitoringStatus="Not Monitored") AND(like(Path,"%Hosting%") 
 AND Location="Varonis" 
 OR(7DayBackUpStatus="Not Backed Up") "Action Required","No Action Required") 
Tags (2)
0 Karma

mayurr98
Super Champion

Hey

Try this !

 | eval Action=if(((MonitoringStatus="Not Monitored") AND (like(Path,"%Hosting%")) AND Location="Varonis" OR  '7DayBackUpStatus'="Not Backed Up"), "Action Required", "No Action Required")

Let me know if this helps you !

davidcraven02
Communicator

Sorry I marked this accepted prematurely. it doesn't seem the OR statement is kicking in as there are more than 50 rows of data that are listed as 'Not Backed Up'

0 Karma

micahkemp
Champion

I've updated my answer to also take into consideration two alternate searches (grouped AND/OR with parentheses to make it more clear) that may correct your logic issue as well.

0 Karma

mayurr98
Super Champion

I do not know how to deal with fieldname starting with a number i may be wrong
Can you change the fieldname to sevendaybackupstatus

  | eval Action=if(((MonitoringStatus="Not Monitored") AND (like(Path,"%Hosting%")) AND Location="Varonis" OR  sevendaybackupstatus="Not Backed Up"), "Action Required", "No Action Required")

OR

Try this

 | rename “7DayBackUpStatus” as sevendaybackupstatus | eval Action=if(((MonitoringStatus="Not Monitored") AND (like(Path,"%Hosting%")) AND Location="Varonis" OR  sevendaybackupstatus="Not Backed Up"), "Action Required", "No Action Required")
0 Karma

micahkemp
Champion

The field name that starts with the number 7 needs to be in single quotes:

| eval Action=if(
    (MonitoringStatus="Not Monitored")
    AND (
        like(Path,"%Hosting%")
        AND Location="Varonis" 
        OR  '7DayBackUpStatus'="Not Backed Up"
    ), "Action Required", "No Action Required")

I suggest putting parentheses when you mix AND and OR. I'm not sure what your intent might be, but you may consider one of these variants:

| eval Action=if(
    (MonitoringStatus="Not Monitored")
    AND (
        (like(Path,"%Hosting%") AND Location="Varonis")
        OR  '7DayBackUpStatus'="Not Backed Up"
    ), "Action Required", "No Action Required")

| eval Action=if(
    (MonitoringStatus="Not Monitored")
    AND (
        like(Path,"%Hosting%")
        AND (Location="Varonis" OR '7DayBackUpStatus'="Not Backed Up")
    ), "Action Required", "No Action Required")

somesoni2
SplunkTrust
SplunkTrust

Try this (you're missing a closing braces on conditions and command before "Action Required")

| eval Action=if((MonitoringStatus="Not Monitored") AND 
( like(Path,"%Hosting%")  AND Location="Varonis" OR (7DayBackUpStatus="Not Backed Up")),  "Action Required","No Action Required") 
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...