<?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 dynamically generate Splunk search queries for Splunk alerts based on alert search times? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-generate-Splunk-search-queries-for-Splunk/m-p/141664#M39266</link>
    <description>&lt;P&gt;Great! I'd like to use the same method to crete a macro to create a condition in a search to analyze Twitter data.&lt;BR /&gt;
I have a form with some inputs fields the user can fill to select filters in a search. I have a "Hashtag" fiel with a default "&lt;EM&gt;" value, but if the user doesn't specify a value, I want add the "&lt;/EM&gt;" condition, not the "entities.hashtags{}.text=*" condition, because I want to extract tweets even if the entities.hashtags{}.text is not present (if the tweet hasn't any hashtag, there's no field at all).&lt;/P&gt;

&lt;P&gt;I've tried something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=twitter lang=* [search * | head 1| eval query = if("$field$" == "*","*","entities.hashtags{}.text=$field$") | fields query | format "" "" "" "" "" ""]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which works only if $field$=="*", otherwise if the value in the input field is "myhashtag" the subsearch returns&lt;BR /&gt;
"entities.hashtags{}.text=myhashtag" which doesn't match (Splunk looks for the STRING "entities.hashtags{}.text=myhashtag"&lt;/P&gt;

&lt;P&gt;Basically I should find a way to strip the "" at the beginning and end of the field "query".&lt;/P&gt;

&lt;P&gt;Any idea?&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Marco&lt;/P&gt;</description>
    <pubDate>Thu, 16 Oct 2014 10:45:24 GMT</pubDate>
    <dc:creator>marcoscala</dc:creator>
    <dc:date>2014-10-16T10:45:24Z</dc:date>
    <item>
      <title>How to dynamically generate Splunk search queries for Splunk alerts based on alert search times?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-generate-Splunk-search-queries-for-Splunk/m-p/141662#M39264</link>
      <description>&lt;P&gt;In order for me to create appropriate Splunk alerts for a certain process, I need to be able to dynamically generate the searches used by the alert based on the &lt;STRONG&gt;search time&lt;/STRONG&gt; used for the search. I emphasize "search time", because a lot of Splunk's functionality is based on the event time.&lt;/P&gt;

&lt;P&gt;When searching from StartSearchDate=YYYY_MM_DD at HH:MM:SS to EndSearchDate=YYYY_MM_DD at HH:MM:SS , I need to search for the following in a log: DataFile_($StartSearchDate - 1 day).dat&lt;/P&gt;

&lt;P&gt;The full search query will be:&lt;BR /&gt;
DataFile_($StartSearchDate - 1 day).dat + "Some static string"&lt;/P&gt;

&lt;P&gt;For example:&lt;BR /&gt;
With the search time range as 01/25/2014 03:00 - 01/25/2014 05:00, the search will be&lt;BR /&gt;
DataFile_20140124.dat + "Some static string"&lt;/P&gt;

&lt;P&gt;I will also need to take care of edge cases such as the first day of a new year and of a new month.&lt;/P&gt;

&lt;P&gt;Example: First day of 2014&lt;BR /&gt;
DataFile_20131231.dat + "Some static string"&lt;/P&gt;

&lt;P&gt;Example: First day of December 2014&lt;BR /&gt;
DataFile_20141130.dat + "Some static string"&lt;/P&gt;

&lt;P&gt;Is there a way to do this using Splunk alerts?&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:42:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-generate-Splunk-search-queries-for-Splunk/m-p/141662#M39264</guid>
      <dc:creator>FutureSight</dc:creator>
      <dc:date>2020-09-28T17:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically generate Splunk search queries for Splunk alerts based on alert search times?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-generate-Splunk-search-queries-for-Splunk/m-p/141663#M39265</link>
      <description>&lt;P&gt;You can build your query in a subsearch to utilize the time range.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=foo
[ stats count | addinfo
| eval query = "DataFile_" + strftime(relative_time(info_min_time, "-d"), "%Y%m%d") + ".dat some static string"
| fields query
]
other filters go here | more processing
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The subsearch will evaluate to whatever that &lt;CODE&gt;query&lt;/CODE&gt; field contains. Using the magic field name &lt;CODE&gt;query&lt;/CODE&gt; avoids the default behaviour of turning the subsearch into a &lt;CODE&gt;fieldname="value"&lt;/CODE&gt; filter.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Sep 2014 22:21:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-generate-Splunk-search-queries-for-Splunk/m-p/141663#M39265</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-09-25T22:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically generate Splunk search queries for Splunk alerts based on alert search times?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-generate-Splunk-search-queries-for-Splunk/m-p/141664#M39266</link>
      <description>&lt;P&gt;Great! I'd like to use the same method to crete a macro to create a condition in a search to analyze Twitter data.&lt;BR /&gt;
I have a form with some inputs fields the user can fill to select filters in a search. I have a "Hashtag" fiel with a default "&lt;EM&gt;" value, but if the user doesn't specify a value, I want add the "&lt;/EM&gt;" condition, not the "entities.hashtags{}.text=*" condition, because I want to extract tweets even if the entities.hashtags{}.text is not present (if the tweet hasn't any hashtag, there's no field at all).&lt;/P&gt;

&lt;P&gt;I've tried something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=twitter lang=* [search * | head 1| eval query = if("$field$" == "*","*","entities.hashtags{}.text=$field$") | fields query | format "" "" "" "" "" ""]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which works only if $field$=="*", otherwise if the value in the input field is "myhashtag" the subsearch returns&lt;BR /&gt;
"entities.hashtags{}.text=myhashtag" which doesn't match (Splunk looks for the STRING "entities.hashtags{}.text=myhashtag"&lt;/P&gt;

&lt;P&gt;Basically I should find a way to strip the "" at the beginning and end of the field "query".&lt;/P&gt;

&lt;P&gt;Any idea?&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Marco&lt;/P&gt;</description>
      <pubDate>Thu, 16 Oct 2014 10:45:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-generate-Splunk-search-queries-for-Splunk/m-p/141664#M39266</guid>
      <dc:creator>marcoscala</dc:creator>
      <dc:date>2014-10-16T10:45:24Z</dc:date>
    </item>
  </channel>
</rss>

