<?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: Using timechart command isn't working for renaming. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469694#M132174</link>
    <description>&lt;P&gt;I've not found much good documentation on foreach, but have learnt mainly through experimentation.&lt;/P&gt;

&lt;P&gt;However, you can do neat things, for example if you have fields such as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;X_A_nnn
X_A_zzz
X_B_nnn
X_B_zzz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can do interesting things like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval X_A_nnn=1
| eval X_A_zzz=2
| eval X_B_nnn=21
| eval X_B_zzz=22
| foreach X_*_* [ eval newField_&amp;lt;&amp;lt;MATCHSEG2&amp;gt;&amp;gt;_&amp;lt;&amp;lt;MATCHSEG1&amp;gt;&amp;gt;='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', tmpField_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;="&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which really give you powerful field processing functionality. What it then does it allow you to ensure you use standardised field naming conventions so that foreach can become useful.&lt;/P&gt;

&lt;P&gt;Have fun with it&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jun 2020 03:30:35 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2020-06-03T03:30:35Z</dc:date>
    <item>
      <title>Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469687#M132167</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;When using &lt;STRONG&gt;timechart&lt;/STRONG&gt; without a &lt;STRONG&gt;BY&lt;/STRONG&gt; this works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;index IN (idx)
    AND host IN (server)
    AND source IN (ssl_access_log)
    AND sourcetype=access_combined
    AND method IN (GET,POST)
    AND file="confirm.jsp"
    AND date_hour&amp;gt;=6 AND date_hour&amp;lt;=22 latest=+1d@d
| eval certsFiled=case(file="confirm.jsp","1") 
| timechart count span=2min
| timewrap d series=short
| where _time &amp;gt;= relative_time(now(), "@d+6h+55min") AND _time &amp;lt;= relative_time(now(), "@d+22h")

| eval colname0 = strftime(relative_time(now(), "@d"),"%D-%a")
| eval colname1 = strftime(relative_time(now(), "-d@d"), "%D-%a")
| eval colname2 = strftime(relative_time(now(), "-2d@d"), "%D-%a")
| eval {colname0} = s0
| eval {colname1} = s1
| eval {colname2} = s2
| fields - s* col*
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, once adding the BY clause, the logic no longer works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;index IN (idx) sourcetype IN (ssl_access_log)
    AND date_hour&amp;gt;=17 AND date_hour&amp;lt;=20 Exception OR MQException earliest=-7d@d latest=+1d@d 
| rex "\s(?&amp;lt;exception&amp;gt;[a-zA-Z\.]+Exception)[:\s]" 
| search exception=* 
| eval exception=case(exception="MQException","mqX",
    exception="com.ibm.mq.MQException","mqXibm") 
| timechart count span=1m BY exception 
| timewrap d series=short 
| where _time &amp;gt;= relative_time(now(), "@d+17h") AND _time &amp;lt;= relative_time(now(), "@d+20h") 

| eval colname0 = strftime(relative_time(now(), "@d"),"%D-%a") 
| eval colname1 = strftime(relative_time(now(), "-d@d"), "%D-%a") 
| eval colname2 = strftime(relative_time(now(), "-2d@d"), "%D-%a") 
| eval {colname0} = s0 
| eval {colname1} = s1 
| eval {colname2} = s2 
| fields - s* col*
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This includes many more days (colname) and exceptions (removed for brevity).&lt;/P&gt;
&lt;P&gt;UPDATE: Here is the chart without renaming.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/9025i9979D276B923FA25/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;BR /&gt;Instead of &lt;STRONG&gt;ibmMqExcpttn_s7&lt;/STRONG&gt; it should read &lt;STRONG&gt;Mon 5/25/20 ibmMqExcptn&lt;/STRONG&gt;. _s6 would beTue; _s5 would be Wed; etc.&lt;BR /&gt;Thanks and God bless,&lt;BR /&gt;Genesius&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 18:03:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469687#M132167</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2020-06-08T18:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469688#M132168</link>
      <description>&lt;P&gt;The &lt;CODE&gt;by&lt;/CODE&gt; clause does not rename fields.  It groups results by the specified field(s).&lt;/P&gt;

&lt;P&gt;You changed more than just &lt;CODE&gt;timechart&lt;/CODE&gt;.  Have you verified the additional lines did not introduce an error?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 17:04:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469688#M132168</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-06-01T17:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469689#M132169</link>
      <description>&lt;P&gt;@richgalloway &lt;BR /&gt;
I haven't seen any errors.&lt;/P&gt;

&lt;P&gt;I know BY clause is not renaming. What I mean is after adding the BY exception clause the number of columns increased from 3 to 21+ cols. The column name (s0..s2) was prepended by the exception (mqX, mqIbmX).&lt;/P&gt;

&lt;P&gt;What we want to be displayed is &lt;STRONG&gt;mqX_Tues-5/26/20&lt;/STRONG&gt;, &lt;STRONG&gt;mqIbmX_Wed-5/27/20&lt;/STRONG&gt;, etc.&lt;/P&gt;

&lt;P&gt;Is there a field name of the columns generated in the timechart/timewrap which we can reference with rename or replace or eval {} ?&lt;/P&gt;

&lt;P&gt;Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 17:42:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469689#M132169</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2020-06-01T17:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469690#M132170</link>
      <description>&lt;P&gt;Adding &lt;CODE&gt;by exception&lt;/CODE&gt; will create a column for each possible value of the exception field.&lt;/P&gt;

&lt;P&gt;You may be able to use the &lt;CODE&gt;foreach&lt;/CODE&gt; command to accomplish the task.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foreach mq* [eval {&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = strftime(relative_time(now(), "@d"),"%D-%a")]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Examine the outputs of the two &lt;CODE&gt;timestamp&lt;/CODE&gt; commands to see exactly what is available to you.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 17:58:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469690#M132170</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-06-01T17:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469691#M132171</link>
      <description>&lt;P&gt;I am not totally sure what you want to finally see in the visualisation, however, once you use a split BY clause, the fields names will become named according to your data, so the normal way to handle this situation is to use foreach.&lt;/P&gt;

&lt;P&gt;So, I would do something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval exception="X_".exception
 | timechart count span=1m BY exception 
 | timewrap d series=short 
 | where _time &amp;gt;= relative_time(now(), "@d+17h") AND _time &amp;lt;= relative_time(now(), "@d+20h") 
 | foreach X_* [ eval s=replace("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;", ".*_s(\d+)$", "\1"), f=replace("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;", "([^_]*)_s.*", "\1"), fmt=printf("-%dd@d", s), col=f.strftime(relative_time(_time, fmt), ":%D-%a"), {col}='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' ]
 | fields - X_*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will give you columns with the original exception name and date for as many exceptions and series you have. What this logic is doing is&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Making the exception value something unique by prefixing the exception value with X_ (use whatever you expect to be unique)&lt;/LI&gt;
&lt;LI&gt;Get the series # from the new timecharted field name _sNN into new field s&lt;/LI&gt;
&lt;LI&gt;Remove the series name from the new field name into new field f&lt;/LI&gt;
&lt;LI&gt;Create the relative date value from the _time field based on series number into new field fmt&lt;/LI&gt;
&lt;LI&gt;Create the new desired column name into field col&lt;/LI&gt;
&lt;LI&gt;Finally make the col field become the new column name with the original value and remove original X_ fields&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Note, if you change the prefix X_ then the foreach command needs to change to reflect your chosen prefix.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 22:44:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469691#M132171</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-06-01T22:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469692#M132172</link>
      <description>&lt;P&gt;My bad. I should have written (reversed).&lt;BR /&gt;
What we want to be displayed is &lt;STRONG&gt;Tues-5/26/20:mqX&lt;/STRONG&gt;; &lt;STRONG&gt;Wed-5/27/20:mqIbmX&lt;/STRONG&gt;, etc.&lt;BR /&gt;
Thanks and God bless,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 12:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469692#M132172</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2020-06-02T12:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469693#M132173</link>
      <description>&lt;P&gt;Wow! @bowesmana that is something else! Thank you.&lt;BR /&gt;
Now I wish I understood the solution. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I've used &lt;STRONG&gt;foreach&lt;/STRONG&gt; in a previous d/b, but it was a copy-N-paste job. Since then, I've Googled "foreach Splunk" and the returns were less than helpful. Do you know of any resources that explain this in greater detail? I think once I have a grasp of this command I will be able to produce more informative d/b's for my clients.&lt;/P&gt;

&lt;P&gt;For instance, if I understood this command fully I could swap the date and the exception. I'll test some changes when I have the time.&lt;/P&gt;

&lt;P&gt;Thanks again and God bless.&lt;BR /&gt;
Stay safe and healthy, you and yours,&lt;BR /&gt;
Genesius&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 12:11:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469693#M132173</guid>
      <dc:creator>genesiusj</dc:creator>
      <dc:date>2020-06-02T12:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using timechart command isn't working for renaming.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469694#M132174</link>
      <description>&lt;P&gt;I've not found much good documentation on foreach, but have learnt mainly through experimentation.&lt;/P&gt;

&lt;P&gt;However, you can do neat things, for example if you have fields such as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;X_A_nnn
X_A_zzz
X_B_nnn
X_B_zzz
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;you can do interesting things like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval X_A_nnn=1
| eval X_A_zzz=2
| eval X_B_nnn=21
| eval X_B_zzz=22
| foreach X_*_* [ eval newField_&amp;lt;&amp;lt;MATCHSEG2&amp;gt;&amp;gt;_&amp;lt;&amp;lt;MATCHSEG1&amp;gt;&amp;gt;='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', tmpField_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;="&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which really give you powerful field processing functionality. What it then does it allow you to ensure you use standardised field naming conventions so that foreach can become useful.&lt;/P&gt;

&lt;P&gt;Have fun with it&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 03:30:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-timechart-command-isn-t-working-for-renaming/m-p/469694#M132174</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-06-03T03:30:35Z</dc:date>
    </item>
  </channel>
</rss>

