<?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: custom command : how to append dynamically columns in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187552#M2516</link>
    <description>&lt;P&gt;Thank you, but in taht case I assume the column name is fix to 'r' and 'x'. I would like to read it from a variable.&lt;/P&gt;

&lt;P&gt;If you have a small example it would help, I'm not familiar to programming, to I don't know what I need to search for it the docs...&lt;/P&gt;

&lt;P&gt;Many thanks&lt;/P&gt;</description>
    <pubDate>Sun, 22 Dec 2013 09:43:09 GMT</pubDate>
    <dc:creator>sbsbb</dc:creator>
    <dc:date>2013-12-22T09:43:09Z</dc:date>
    <item>
      <title>custom command : how to append dynamically columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187550#M2514</link>
      <description>&lt;P&gt;I try to write a python command that generates results.&lt;BR /&gt;
My problem is, that I have "n" columns, and the name of them is might be different from line to line. I can't make it with the normal results.append/outputresult&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    results.append({'_time' : time, '_raw' : output})   
    si.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How could I do that, it there a way to append line by line, with the columns defined in variables ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;append["line1"]
    appendcol["_time"]=time
    appendcol[r]=rr
    appendcol[s]=ss
append["line2"]
    appendcol["_time"]=time
    appendcol[x]=xx
    appendcol[y]=yy
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Dec 2013 02:52:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187550#M2514</guid>
      <dc:creator>sbsbb</dc:creator>
      <dc:date>2013-12-22T02:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: custom command : how to append dynamically columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187551#M2515</link>
      <description>&lt;P&gt;Of course can you use append and outputresults, and I'm assuming you're using InterSplunk libraries. &lt;CODE&gt;results&lt;/CODE&gt; is simply a python &lt;CODE&gt;list&lt;/CODE&gt; of &lt;CODE&gt;dict&lt;/CODE&gt;s. You can append and add whatever you want to such a list:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;results.append({'_time': time, '_raw': output, 'r' : rr, 's': ss})
results.append({'_time': time, '_raw': output, 'x' : xx, 'y': yy})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and there are many other ways to work with &lt;CODE&gt;list&lt;/CODE&gt;s and &lt;CODE&gt;dicts&lt;/CODE&gt;s:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.python.org/2.7/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange"&gt;http://docs.python.org/2.7/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.python.org/2.7/library/stdtypes.html#mapping-types-dict"&gt;http://docs.python.org/2.7/library/stdtypes.html#mapping-types-dict&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2013 04:07:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187551#M2515</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-12-22T04:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: custom command : how to append dynamically columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187552#M2516</link>
      <description>&lt;P&gt;Thank you, but in taht case I assume the column name is fix to 'r' and 'x'. I would like to read it from a variable.&lt;/P&gt;

&lt;P&gt;If you have a small example it would help, I'm not familiar to programming, to I don't know what I need to search for it the docs...&lt;/P&gt;

&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2013 09:43:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187552#M2516</guid>
      <dc:creator>sbsbb</dc:creator>
      <dc:date>2013-12-22T09:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: custom command : how to append dynamically columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187553#M2517</link>
      <description>&lt;P&gt;Well, then you would use &lt;CODE&gt;r&lt;/CODE&gt; instead of &lt;CODE&gt;'r'&lt;/CODE&gt;. There are many excellent online tutorials of Python that can explain how the basic constructs and syntax work.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2013 09:48:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187553#M2517</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-12-22T09:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: custom command : how to append dynamically columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187554#M2518</link>
      <description>&lt;P&gt;I was able to make it work :&lt;BR /&gt;
result={'_time': ttime} # getting the time field in the result row&lt;BR /&gt;
result[ host]=str(m.getElementsByTagName('metricValue')[0].firstChild.data) #append new column in result row&lt;BR /&gt;
results.append(result) # append result_row in results array&lt;BR /&gt;
si.outputResults(results) # output all results&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:32:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/custom-command-how-to-append-dynamically-columns/m-p/187554#M2518</guid>
      <dc:creator>sbsbb</dc:creator>
      <dc:date>2020-09-28T15:32:23Z</dc:date>
    </item>
  </channel>
</rss>

