Security

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

simingmplatform
New Member

Hi ALL,
need help for a using case here.

we are trying to setup alert based on below data
value1 ( the average of past 7days since yesterday)
value2 ( the average of yesterday's day)

if value2 is lower than 70% of value1 , trigger alerts.
below is what I use to setup this query

index=main topoName=EnrichmentTopology datacenter=NA desc=ENR131 earliest=-7d@d latest=-2d@d | stats avg(value) as 7day by desc | appendcols [ search index=main topoName=EnrichmentTopology datacenter=NA desc=ENR131 earliest=-2d@d latest=-1d@d | stats avg(value) as 1day by desc] | eval diff=(7day-1day)

but it always return me
Error in 'eval' command: The expression is malformed. Expected ).

any idea ? thx a lot

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Yes, eval is allowed with stats. The problem appears to be with the field names which begin with digits. Put them inside single quotes to force Splunk to treat them as field names. ... | eval diff=('7day'-'1day')

---
If this reply helps you, Karma would be appreciated.

View solution in original post

jpolvino
Builder

You may want to consider using multisearch:

| multisearch
[search index=main topoName=EnrichmentTopology datacenter=NA desc=ENR131 earliest=-7d@d latest=-2d@d | stats avg(value) as prevWeek]
[search index=main topoName=EnrichmentTopology datacenter=NA desc=ENR131 earliest=-2d@d latest=-1d@d | stats avg(value) as prevDay]
| eval alert=if(prevDay<(prevWeek*0.7),"Alert","No alert")

It doesn't look like you need a "by" clause in your stats, since there is only 1 value for desc.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Yes, eval is allowed with stats. The problem appears to be with the field names which begin with digits. Put them inside single quotes to force Splunk to treat them as field names. ... | eval diff=('7day'-'1day')

---
If this reply helps you, Karma would be appreciated.

simingmplatform
New Member

correct, its after we use day7 and day1 , issue is gone, thx

0 Karma

simingmplatform
New Member

everything works before | eval part , I guess we cannot use eval with stats ?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...