<?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: need help on dashboard to display count by query string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306765#M92037</link>
    <description>&lt;P&gt;As requested can you provide some sample events so that you can perform a field extraction?&lt;/P&gt;</description>
    <pubDate>Wed, 29 Nov 2017 11:20:21 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-29T11:20:21Z</dc:date>
    <item>
      <title>need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306758#M92030</link>
      <description>&lt;P&gt;i have a list of query strings (these are just strings not a field)&lt;BR /&gt;
(eg. Too many open files, CPU Starvation detected, java.sql.SQLException: Cannot obtain connection, thread(s) in total in the server that may be hung, Trust Association Init Error, problems occurred during startup for, OutOfMemoryError)&lt;BR /&gt;
My requirement is to save these strings in a field and then run a query like&lt;BR /&gt;
index=abc sourcetype=xyz "field_name" |stats count by field_name&lt;/P&gt;

&lt;P&gt;but i am unable to figure out how to save these query strings in field_name. My intention is to get a table with one column as query strings and the other column to hold the corresponding count values for each string.&lt;BR /&gt;
Like:&lt;BR /&gt;
field_name                                                                                             count&lt;BR /&gt;
OutOfMemoryError                                                                               123&lt;BR /&gt;
Too many open files                                                                               234&lt;BR /&gt;
CPU Starvation detected                                                                        345&lt;BR /&gt;
java.sql.SQLException: Cannot obtain connection                            456&lt;BR /&gt;
thread(s) in total in the server that may be hung                              567&lt;BR /&gt;
Trust Association Init Error                                                                    678&lt;BR /&gt;
problems occurred during startup for                                                 789&lt;/P&gt;

&lt;P&gt;also it would be great if i can include the corresponding hosts as well for each string.&lt;BR /&gt;
Any help/suggestions? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:58:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306758#M92030</guid>
      <dc:creator>soumyasaha25</dc:creator>
      <dc:date>2020-09-29T16:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306759#M92031</link>
      <description>&lt;P&gt;Hmmm.  &lt;/P&gt;

&lt;P&gt;That depends on where you are getting the strings.  &lt;/P&gt;

&lt;P&gt;Assuming that you have a fixed list of strings, then the way I would go about it is to put the list of strings into a csv or lookup file with one column.&lt;/P&gt;

&lt;P&gt;You can then use the &lt;CODE&gt;format&lt;/CODE&gt; command as part of a strategy to create your extract.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookcsv mylist.csv | table myfield 
| format "(" "" "" "" "OR" ")" 
| rex field=search mode=sed "s/myfield=//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above will create a field called &lt;CODE&gt;search&lt;/CODE&gt; that contains a value like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( "value1" OR "value2" OR ... )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you put that into square braces as a subsearch, then the value of &lt;CODE&gt;search&lt;/CODE&gt; will be dropped as a literal into the main search.&lt;/P&gt;

&lt;P&gt;Next, you do the same thing again to create a rex that will match each literal.  We sort the field in descending alpha order, because that automatically will cause longer items to sort before shorter items like this &lt;CODE&gt;(&amp;lt;myfield&amp;gt;golfer|golf|go)&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | inputlookcsv mylist.csv 
 | table myfield 
 | sort 0 - myfield
 | format "(" "" "" "" "OR" ")" 
 | rex field=search mode=sed "s/myfield=//g s/ OR /|/g s/(/(?&amp;lt;myfield&amp;gt;/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After testing for reasonability, the above goes in a rex line as below.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw [ the above lines of code]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then you run it into your &lt;CODE&gt;stats&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 07:08:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306759#M92031</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-11-29T07:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306760#M92032</link>
      <description>&lt;P&gt;@soumyasaha25 you would need to use regular expressions to extract the errors from log based on the pattern and save as field_name. For us to assist you would need to provide some sample events.&lt;/P&gt;

&lt;P&gt;You would need to start with &lt;CODE&gt;rex&lt;/CODE&gt; command and then convert the same to Field Extractions using Splunk's Interactive Filed Extraction and using regular expression from rex command.&lt;/P&gt;

&lt;P&gt;If your Errors are limited to 7 listed above then there could be a bit expensive option to use &lt;CODE&gt;searchmatch()&lt;/CODE&gt; function with &lt;CODE&gt;eval&lt;/CODE&gt; command. But it is better to use Field Extraction if you know the pattern to extract fields using Regular Expressions. So kindly provide us with raw events as they appear in your logs and mask/anonymize any sensitive information.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 07:14:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306760#M92032</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-29T07:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306761#M92033</link>
      <description>&lt;P&gt;Thanks for your suggestions.&lt;BR /&gt;
Actually (if possible) i trying to get the logic incorporated in a single field (that holds multiple values).&lt;BR /&gt;
my intention being if there are more strings coming up in the future i dont have to change the entire query.&lt;BR /&gt;
i tried to use a lookup but i think somewhere i am missing something.&lt;BR /&gt;
I have about 15 strings as of now. Hence looking for a solution so that the field values are dynamically populated on the search query without having to hard code it.&lt;BR /&gt;
the regex approach is what i am using now is working fine.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 08:35:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306761#M92033</guid>
      <dc:creator>soumyasaha25</dc:creator>
      <dc:date>2017-11-29T08:35:43Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306762#M92034</link>
      <description>&lt;P&gt;Hi @soumyasaha25 ,&lt;/P&gt;

&lt;P&gt;Can you please try this search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc sourcetype=xyz
| eval ErrorMsg=
case(
like(_raw,"%Too many open files%"),"Too many open files",
like(_raw,"%CPU Starvation detected%"),"CPU Starvation detected",
like(_raw,"%java.sql.SQLException: Cannot obtain connection%"),"java.sql.SQLException: Cannot obtain connection",
like(_raw,"%thread(s) in total in the server that may be hung%"),"thread(s) in total in the server that may be hung",
like(_raw,"%Trust Association Init Error%"),"Trust Association Init Error",
like(_raw,"%problems occurred during startup for%"),"problems occurred during startup for",
like(_raw,"%OutOfMemoryError%"),"OutOfMemoryError",
1=1,"Other"
)
|stats count by ErrorMsg
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 08:49:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306762#M92034</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-29T08:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306763#M92035</link>
      <description>&lt;P&gt;i am trying to run the search as below&lt;BR /&gt;
somehow the last part of the regex  s/(/(?search_string/g throws an error - Error in 'rex' command: Regex: missing closing parenthesis. i tried using s/(/(?)/g, but that throws the same error.&lt;/P&gt;

&lt;P&gt;I ran the  code as below&lt;BR /&gt;
| inputlookup search_string.csv&lt;BR /&gt;
| table search_string&lt;BR /&gt;
| sort 0 - search_string&lt;BR /&gt;
| format "(" "" "" "" "OR" ")" &lt;BR /&gt;
| rex field=search mode=sed ""s/search_string=//g s/ OR /|/g"&lt;/P&gt;

&lt;P&gt;and got the below results&lt;BR /&gt;
( "thread(s) in total in the server that may be hung" | "problems occurred during startup for" | "java.sql.SQLException: Cannot obtain connection:" | "java.lang.OutOfMemoryError for" | "com.ibm.websphere.ce.cm.StaleConnectionException:" | "WSVR0607W" | "WSVR0605W" | "UnsatisfiedLinkError" | "Too many open files" | "The port may already be in use" | "SSLHandshakeException" | "SSL Handshake Failed" | "SQLException: Failed to start database" | "SECJ0418I" | "SECJ0384E: Trust Association Init Error" | "OutOfMemoryError" | "HMGR0152W: CPU Starvation detected" | "EJPEJ0069E" | "Communication function detecting the error:" | "CPU Starvation detected" )&lt;/P&gt;

&lt;P&gt;Also, once this syntax issue is sorted the final query should look like (please correct me if i am wrong) &lt;/P&gt;

&lt;P&gt;index=abc sourcetype=xyz | rex field=_raw [&lt;BR /&gt;
| inputlookup search_string.csv&lt;BR /&gt;
| table search_string&lt;BR /&gt;
| sort 0 - search_string&lt;BR /&gt;
| format "(" "" "" "" "OR" ")" &lt;BR /&gt;
| rex field=search mode=sed ""s/search_string=//g s/ OR /|/g/ s/(/(?search_string/g"]&lt;BR /&gt;
|stats count by search_string, host&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:58:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306763#M92035</guid>
      <dc:creator>soumyasaha25</dc:creator>
      <dc:date>2020-09-29T16:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306764#M92036</link>
      <description>&lt;P&gt;Thank you for your suggestion.&lt;BR /&gt;
This is working perfectly, but i am also looking at the feasibility to use the lookup file so that in a rare event if there are any changes/addition/deletion to the query strings, no one touches the actual query, just a change/addition/deletion in the lookup file would be enough.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 10:07:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306764#M92036</guid>
      <dc:creator>soumyasaha25</dc:creator>
      <dc:date>2017-11-29T10:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306765#M92037</link>
      <description>&lt;P&gt;As requested can you provide some sample events so that you can perform a field extraction?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 11:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306765#M92037</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-29T11:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: need help on dashboard to display count by query string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306766#M92038</link>
      <description>&lt;P&gt;I am currently using this query, it is working fine but now i need to add 2 more columns in the lookup file to display jvm name and cluster name&lt;BR /&gt;
Below is the current query:&lt;/P&gt;

&lt;P&gt;index = abc sourcetype="xyz" [|inputlookup search_string.csv | return 100 $search_string]&lt;BR /&gt;
| rename _raw as rawText&lt;BR /&gt;
| eval match_string=[|inputlookup search_string.csv |stats values(search_string) as query | eval query=mvjoin(query,",") | fields query | format "" "" "" "" "" ""]&lt;BR /&gt;
| eval match_string=split(match_string,",") &lt;BR /&gt;
| mvexpand match_string &lt;BR /&gt;
| where like(rawText,"%"+match_string+"%")&lt;BR /&gt;
| stats values(host) AS HostName count by match_string&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:14:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/need-help-on-dashboard-to-display-count-by-query-string/m-p/306766#M92038</guid>
      <dc:creator>soumyasaha25</dc:creator>
      <dc:date>2020-09-29T18:14:16Z</dc:date>
    </item>
  </channel>
</rss>

