<?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: How to edit the eval syntax in my search to assign a value based on the result of a subsearch? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278395#M84037</link>
    <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status   earliest=-0mon@mon SERVICESTATEID:sasv03qb:
  | eventstats earliest(_time) as start_period latest(_time) as end_period                    
  | eval duration_period=end_period - start_period
  |eval end_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
 | sort - _time | head 1 | eval end_incident=strptime(last_time_critical,"%Y-%m-%d %H:%M:%S") | appendpipe[| stats count as end_incident | where end_incident=0]|return $end_incident],0)|eval start_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
 | sort - _time | head 1 | eval start_incident=strptime(last_time_ok,"%Y-%m-%d %H:%M:%S") | appendpipe[| stats count as end_incident | where end_incident=0]|return $start_incident],0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;There were couple of typos as well in my previous attempt. Try this one&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status   earliest=-0mon@mon SERVICESTATEID:sasv03qb:
   | eventstats earliest(_time) as start_period latest(_time) as end_period                    
   | eval duration_period=end_period - start_period
   |eval end_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: current_state=2 | stats count latest(last_time_critical) as  last_time_critical | eval end_incident=if(isnull(last_time_critical),0,strptime(last_time_critical,"%Y-%m-%d %H:%M:%S"))|return $end_incident],0)|eval start_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: current_state=2 | stats count latest(last_time_ok) as  last_time_ok | eval start_incident=if(isnull(last_time_ok),0,strptime(last_time_ok,"%Y-%m-%d %H:%M:%S"))|return $start_incident],0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 13 Dec 2016 16:06:31 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-12-13T16:06:31Z</dc:date>
    <item>
      <title>How to edit the eval syntax in my search to assign a value based on the result of a subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278394#M84036</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm working with Nagios events, with  field "current_state" equal 2, Nagios is indicating a critical situation. The events with "current_state=2" are very few. My following search works fine if "current_state=2" events  are found, but if they aren't  found I get the error: &lt;BR /&gt;
&lt;STRONG&gt;Error in 'eval' command: The expression is malformed. An unexpected character is reached at ',0)'.&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status   earliest=-0mon@mon SERVICESTATEID:sasv03qb:
 | eventstats earliest(_time) as start_period latest(_time) as end_period                    
 | eval duration_period=end_period - start_period
 |eval end_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
| sort - _time | head 1 | eval end_incident=strptime(last_time_critical,"%Y-%m-%d %H:%M:%S") |return $end_incident],0)|eval start_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
| sort - _time | head 1 | eval start_incident=strptime(last_time_ok,"%Y-%m-%d %H:%M:%S") |return $start_incident],0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I want to do, if there aren't "current_state=2" events, is to set at 0 the fields &lt;STRONG&gt;start_incident&lt;/STRONG&gt; and &lt;STRONG&gt;end_incident&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;Many thanks&lt;BR /&gt;
Antonio&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:06:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278394#M84036</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2020-09-29T12:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit the eval syntax in my search to assign a value based on the result of a subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278395#M84037</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status   earliest=-0mon@mon SERVICESTATEID:sasv03qb:
  | eventstats earliest(_time) as start_period latest(_time) as end_period                    
  | eval duration_period=end_period - start_period
  |eval end_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
 | sort - _time | head 1 | eval end_incident=strptime(last_time_critical,"%Y-%m-%d %H:%M:%S") | appendpipe[| stats count as end_incident | where end_incident=0]|return $end_incident],0)|eval start_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
 | sort - _time | head 1 | eval start_incident=strptime(last_time_ok,"%Y-%m-%d %H:%M:%S") | appendpipe[| stats count as end_incident | where end_incident=0]|return $start_incident],0)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;There were couple of typos as well in my previous attempt. Try this one&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status   earliest=-0mon@mon SERVICESTATEID:sasv03qb:
   | eventstats earliest(_time) as start_period latest(_time) as end_period                    
   | eval duration_period=end_period - start_period
   |eval end_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: current_state=2 | stats count latest(last_time_critical) as  last_time_critical | eval end_incident=if(isnull(last_time_critical),0,strptime(last_time_critical,"%Y-%m-%d %H:%M:%S"))|return $end_incident],0)|eval start_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: current_state=2 | stats count latest(last_time_ok) as  last_time_ok | eval start_incident=if(isnull(last_time_ok),0,strptime(last_time_ok,"%Y-%m-%d %H:%M:%S"))|return $start_incident],0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Dec 2016 16:06:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278395#M84037</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-12-13T16:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit the eval syntax in my search to assign a value based on the result of a subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278396#M84038</link>
      <description>&lt;P&gt;Hi someone2,&lt;/P&gt;

&lt;P&gt;it works very well!!!!&lt;/P&gt;

&lt;P&gt;Thank you very much for your great support.&lt;/P&gt;

&lt;P&gt;Regards&lt;BR /&gt;
Antonio&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 08:37:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278396#M84038</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2016-12-14T08:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit the eval syntax in my search to assign a value based on the result of a subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278397#M84039</link>
      <description>&lt;P&gt;Hi somesoni2,&lt;/P&gt;

&lt;P&gt;I did two change at your search and it works very well!!!&lt;BR /&gt;
Excuse me could you explain me the meaning of  your:&lt;BR /&gt;
&lt;EM&gt;appendpipe[| stats count as **start_incident&lt;/EM&gt;* | where &lt;STRONG&gt;start_incident&lt;/STRONG&gt;=0]*&lt;/P&gt;

&lt;P&gt;Thank you very much for your great support!!!!&lt;BR /&gt;
Antonio&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=app_nagios sourcetype=ydms_status   earliest=-0mon@mon SERVICESTATEID:sasv03qb:
   | eventstats earliest(_time) as start_period latest(_time) as end_period                    
   | eval duration_period=end_period - start_period
   |eval end_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
  | sort - _time | head 1 | eval end_incident=strptime(last_time_critical,"%Y-%m-%d %H:%M:%S") | appendpipe[| stats count as end_incident | where end_incident=0]|return $end_incident],0)|eval start_incident=if(current_state = 2,[search index=app_nagios sourcetype=ydms_status  earliest=-0mon@mon SERVICESTATEID:sasv03qb: | search current_state=2         
  | sort - _time | head 1 | eval start_incident=strptime(last_time_ok,"%Y-%m-%d %H:%M:%S") | appendpipe[| stats count as **start_incident** | where **start_incident**=0]|return $start_incident],0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:04:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278397#M84039</guid>
      <dc:creator>antoniofacchi</dc:creator>
      <dc:date>2020-09-29T12:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit the eval syntax in my search to assign a value based on the result of a subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278398#M84040</link>
      <description>&lt;P&gt;The &lt;CODE&gt;| stats count as start_incident&lt;/CODE&gt; in the appendpipe will return value 0 if there are no rows are available before that. In that case, since there are no rows before that, we'll keep the row returned by stats (thats why we've &lt;CODE&gt;| where start_incident=0&lt;/CODE&gt;). The result of appendpipe-stats will not  be used if there are rows available before that.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2016 17:12:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278398#M84040</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-12-14T17:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit the eval syntax in my search to assign a value based on the result of a subsearch?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278399#M84041</link>
      <description>&lt;P&gt;@antoniofacchi - Did the answer provided by somesoni2 help provide a working solution to your question? If yes, please don't forget to resolve this post by clicking "Accept" below his answer. &lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 05:09:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-the-eval-syntax-in-my-search-to-assign-a-value-based/m-p/278399#M84041</guid>
      <dc:creator>aaraneta_splunk</dc:creator>
      <dc:date>2016-12-16T05:09:21Z</dc:date>
    </item>
  </channel>
</rss>

