<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)' in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213470#M62629</link>
    <description>&lt;P&gt;Thank you very much.&lt;BR /&gt;
It works! How you have suggested inserting an APPEND commnad to set "0" the duration_incident  field has resolved my issue.&lt;/P&gt;

&lt;P&gt;Thanks again&lt;BR /&gt;
Antonio&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jan 2017 06:56:23 GMT</pubDate>
    <dc:creator>antoniofacchi</dc:creator>
    <dc:date>2017-01-05T06:56:23Z</dc:date>
    <item>
      <title>Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213463#M62622</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;for a SLA project, I'm using Splunk to read Nagios the availability  status of  some services.&lt;BR /&gt;
Using  the condition &lt;STRONG&gt;"current_state=2 AND current_check_attempt=max_check_attempts"&lt;/STRONG&gt;, Nagios state a critical situation. My search works fine if some critical events are found, but if they aren't found I get the error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;because I can't get the &lt;STRONG&gt;last_time_ok&lt;/STRONG&gt; field in the &lt;STRONG&gt;stats count latest(last_time_critical) as  last_time_critical by last_time_ok&lt;/STRONG&gt;.&lt;BR /&gt;
The &lt;STRONG&gt;last_time_ok&lt;/STRONG&gt; field is important to understand ehen start a new incident.&lt;/P&gt;

&lt;P&gt;How can resolve? Here my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status  earliest=-1h SERVICESTATEID:sasv03qb:
 |eventstats earliest(_time) as start_period latest(_time) as end_period                        
 |eval duration_period=end_period - start_period 
 |eval duration_incident=if((current_state = 2),
 [search index=app_nagios sourcetype=ydms_status  earliest=-1h SERVICESTATEID:sasv03qb:   
     |where current_state=2 AND current_check_attempt=max_check_attempts |stats count latest(last_time_critical) as  last_time_critical by last_time_ok |eval end_incident=if(isnull(last_time_critical),0,strptime(last_time_critical,"%Y-%m-%d %H:%M:%S"))|eval start_incident=if(isnull(last_time_ok),0,strptime(last_time_ok,"%Y-%m-%d %H:%M:%S"))|eval duration_incident=end_incident - start_incident|stats sum(duration_incident) as duration_incident|return $duration_incident],0)|eval %unavail=round(duration_incident/(duration_period)*100,2)                         
|eval %= round((100 - '%unavail'),2)|eval %= round((100 - '%unavail'),2)|sort  %|head 1|fields %
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Many thanks for your support.&lt;BR /&gt;
Antonio&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:15:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213463#M62622</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2020-09-29T12:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213464#M62623</link>
      <description>&lt;P&gt;Looks like there is an ending ] bracket in the middle of the return statement.&lt;/P&gt;

&lt;P&gt;However I'm guessing that's a typo or the forum auto formatting because you didn't surround your code with code tags.&lt;/P&gt;

&lt;P&gt;To solve the problem when a field might be null try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ...| eval possibleNullField=if(isnull(possibleNullField),"NULL",possibleNullField) | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To be read as if this field is empty, make it equal the string of "NULL".  else, make it the value of itself.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 12:11:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213464#M62623</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2017-01-04T12:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213465#M62624</link>
      <description>&lt;P&gt;Hi jkat54,&lt;/P&gt;

&lt;P&gt;the &lt;STRONG&gt;]&lt;/STRONG&gt; is the end bracket of the subsearch. In any case, I've inserted |eval last_time_ok=if(isnull(last_time_ok),"NULL",last_time_ok) but I still got the Issue. I dont' should be any syntax error becuase If I change the earliest time to get some critical events the search works fine. I ship the newest search:&lt;BR /&gt;
&lt;STRONG&gt;*index=app_nagios sourcetype=ydms_status  earliest=-1mon SERVICESTATEID:sasv03qb:&lt;BR /&gt;
 |eventstats earliest(_time) as start_period latest(_time) as end_period&lt;BR /&gt;&lt;BR /&gt;
 |eval duration_period=end_period - start_period &lt;BR /&gt;
 |eval duration_incident=if((current_state = 2),&lt;BR /&gt;
 [search index=app_nagios sourcetype=ydms_status  earliest=-1mon SERVICESTATEID:sasv03qb:&lt;BR /&gt;&lt;BR /&gt;
     |where current_state=2 AND current_check_attempt=max_check_attempts|eval last_time_ok=if(isnull(last_time_ok),"NULL",last_time_ok) |stats count latest(last_time_critical) as  last_time_critical by last_time_ok |eval end_incident=if(isnull(last_time_critical),0,strptime(last_time_critical,"%Y-%m-%d %H:%M:%S"))|eval start_incident=if(isnull(last_time_ok),0,strptime(last_time_ok,"%Y-%m-%d %H:%M:%S"))|eval duration_incident=end_incident - start_incident|stats sum(duration_incident) as duration_incident|return $duration_incident],0)|eval %unavail=round(duration_incident/(duration_period)*100,2)&lt;BR /&gt;&lt;BR /&gt;
|eval %= round((100 - '%unavail'),2)|eval %= round((100 - '%unavail'),2)|sort  %|head 1|fields %&lt;/STRONG&gt;*&lt;/P&gt;

&lt;P&gt;Please let me know any other  workarounds.&lt;/P&gt;

&lt;P&gt;Many thanks for the support.&lt;BR /&gt;
Antonio&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:15:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213465#M62624</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2020-09-29T12:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213466#M62625</link>
      <description>&lt;P&gt;Try moving your subsearch out of your eval somehow.  It could be an append, etc.  Prior to the eval that needs it.&lt;/P&gt;

&lt;P&gt;You've got some condition where it can't return $duration_incident and you need to figure out what condition(s) that is and account for them.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 14:32:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213466#M62625</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2017-01-04T14:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213467#M62626</link>
      <description>&lt;P&gt;Hi jkat54,&lt;/P&gt;

&lt;P&gt;yes, now it works! I have added the following append in the middle to create a single event with &lt;CODE&gt;duration_incident=0&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;append[search index=app_nagios sourcetype=ydms_status earliest=-1h SERVICESTATEID:sasv03qb:|head 1|eval duration_incident=0]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here the newly search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status  earliest=-3mon SERVICESTATEID:sasv03qb:
 |eventstats earliest(_time) as start_period latest(_time) as end_period                        
 |eval duration_period=end_period - start_period 
 |eval duration_incident=if((current_state = 2  ),
 [search index=app_nagios sourcetype=ydms_status  earliest=-3mon SERVICESTATEID:sasv03qb:   
     |where current_state=2 AND current_check_attempt=max_check_attempts |stats count latest(last_time_critical) as  last_time_critical by last_time_ok |eval end_incident=if(isnull(last_time_critical),0,strptime(last_time_critical,"%Y-%m-%d %H:%M:%S"))|eval start_incident=if(isnull(last_time_ok),0,strptime(last_time_ok,"%Y-%m-%d %H:%M:%S"))|eval duration_incident=end_incident - start_incident|append[search index=app_nagios sourcetype=ydms_status  earliest=-1h SERVICESTATEID:sasv03qb:|head 1|eval duration_incident=0]|stats sum(duration_incident) as duration_incident|return $duration_incident],0)|eval %unavail=round(duration_incident/(duration_period)*100,2)                         
|eval %= round((100 - '%unavail'),2)|eval %= round((100 - '%unavail'),2)|sort  %|head 1|fields % *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you very much for your great support.&lt;/P&gt;

&lt;P&gt;Antonio&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 15:40:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213467#M62626</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2017-01-04T15:40:20Z</dc:date>
    </item>
    <item>
      <title>Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213468#M62627</link>
      <description>&lt;P&gt;can you convert this to a comment on my answer that suggested using append, and then mark my answer as the answer to give me credit for the idea please?  Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 21:16:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213468#M62627</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2017-01-04T21:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213469#M62628</link>
      <description>&lt;P&gt;How you've suggested, I insert an APPEND command to set "0"  duration_incidend field, and now it works very well.&lt;BR /&gt;
Thank you for your great support.&lt;BR /&gt;
Antonio&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 06:52:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213469#M62628</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2017-01-05T06:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213470#M62629</link>
      <description>&lt;P&gt;Thank you very much.&lt;BR /&gt;
It works! How you have suggested inserting an APPEND commnad to set "0" the duration_incident  field has resolved my issue.&lt;/P&gt;

&lt;P&gt;Thanks again&lt;BR /&gt;
Antonio&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 06:56:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Error-in-eval-command-The-expression-is-malformed-An-unexpected/m-p/213470#M62629</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2017-01-05T06:56:23Z</dc:date>
    </item>
  </channel>
</rss>

