<?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 Preserving multi-value fields through custom search command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Preserving-multi-value-fields-through-custom-search-command/m-p/93584#M24113</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to build a Python custom search command. The command is run after a &lt;CODE&gt;transaction&lt;/CODE&gt;, and adds values corresponding to events in the transaction based on the business logic.&lt;/P&gt;

&lt;P&gt;This is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysourcetype | transaction User_ID keepevicted=true mvlist=true | where eventcount &amp;gt; 2 | positioning |  table *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the script for my &lt;CODE&gt;positioning&lt;/CODE&gt; command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python2.7
import splunk.Intersplunk

def handle_lines(enumerable):
    for i, line in enumerate(enumerable):
            # business logic goes here
            yield new_line

output = []
for line in handle_lines(search_results):
        output.append(line)
splunk.Intersplunk.outputResults(output)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(there's a reason for my seemingly redundant use of the generator pattern here)&lt;/P&gt;

&lt;P&gt;Even if handle_lines yields each line without doing anything to it, Splunk seems to lose its awareness of all the multi-value fields. Instead of this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/5Rgv3.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;I get this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/q1PN4.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;It does work if I change my &lt;CODE&gt;handle_lines()&lt;/CODE&gt; function to output them as an array:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def handle_lines(enumerable):
    for i, line in enumerate(enumerable):
        new_line = {}
        for attr in line:
            new_line[attr] = line[attr].split(' ')
        # business logic goes here
        yield new_line
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem here is that some of my fields have spaces, and this causes them to get broken into multi-valued fields as well. This wreaks havoc with what I'm trying to to back in Splunk - I'm assuming that each event has multiple values for each field corresponding to its &lt;CODE&gt;eventcount&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I'm surprised that I'm having this issue since I'm just using the data exactly as it's provided by &lt;CODE&gt;splunk.Intersplunk&lt;/CODE&gt;; I assumed the library would handle the multi-value field logic.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jul 2012 06:48:14 GMT</pubDate>
    <dc:creator>dbryan</dc:creator>
    <dc:date>2012-07-09T06:48:14Z</dc:date>
    <item>
      <title>Preserving multi-value fields through custom search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Preserving-multi-value-fields-through-custom-search-command/m-p/93584#M24113</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm trying to build a Python custom search command. The command is run after a &lt;CODE&gt;transaction&lt;/CODE&gt;, and adds values corresponding to events in the transaction based on the business logic.&lt;/P&gt;

&lt;P&gt;This is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=mysourcetype | transaction User_ID keepevicted=true mvlist=true | where eventcount &amp;gt; 2 | positioning |  table *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is the script for my &lt;CODE&gt;positioning&lt;/CODE&gt; command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python2.7
import splunk.Intersplunk

def handle_lines(enumerable):
    for i, line in enumerate(enumerable):
            # business logic goes here
            yield new_line

output = []
for line in handle_lines(search_results):
        output.append(line)
splunk.Intersplunk.outputResults(output)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(there's a reason for my seemingly redundant use of the generator pattern here)&lt;/P&gt;

&lt;P&gt;Even if handle_lines yields each line without doing anything to it, Splunk seems to lose its awareness of all the multi-value fields. Instead of this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/5Rgv3.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;I get this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/q1PN4.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;It does work if I change my &lt;CODE&gt;handle_lines()&lt;/CODE&gt; function to output them as an array:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def handle_lines(enumerable):
    for i, line in enumerate(enumerable):
        new_line = {}
        for attr in line:
            new_line[attr] = line[attr].split(' ')
        # business logic goes here
        yield new_line
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem here is that some of my fields have spaces, and this causes them to get broken into multi-valued fields as well. This wreaks havoc with what I'm trying to to back in Splunk - I'm assuming that each event has multiple values for each field corresponding to its &lt;CODE&gt;eventcount&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;I'm surprised that I'm having this issue since I'm just using the data exactly as it's provided by &lt;CODE&gt;splunk.Intersplunk&lt;/CODE&gt;; I assumed the library would handle the multi-value field logic.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2012 06:48:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Preserving-multi-value-fields-through-custom-search-command/m-p/93584#M24113</guid>
      <dc:creator>dbryan</dc:creator>
      <dc:date>2012-07-09T06:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Preserving multi-value fields through custom search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Preserving-multi-value-fields-through-custom-search-command/m-p/93585#M24114</link>
      <description>&lt;P&gt;I've considered that I might need a search-time transform to replace spaces within my fields with some other values prior to passing them to my custom command, but I'd really like to avoid this if possible.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jul 2012 08:08:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Preserving-multi-value-fields-through-custom-search-command/m-p/93585#M24114</guid>
      <dc:creator>dbryan</dc:creator>
      <dc:date>2012-07-09T08:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Preserving multi-value fields through custom search command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Preserving-multi-value-fields-through-custom-search-command/m-p/93586#M24115</link>
      <description>&lt;P&gt;Hello, I am the supreme reigning idiot.&lt;/P&gt;

&lt;P&gt;I was missing this in &lt;CODE&gt;commands.conf&lt;/CODE&gt; for the custom search command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;supports_multivalues = true
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jul 2012 03:02:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Preserving-multi-value-fields-through-custom-search-command/m-p/93586#M24115</guid>
      <dc:creator>dbryan</dc:creator>
      <dc:date>2012-07-10T03:02:09Z</dc:date>
    </item>
  </channel>
</rss>

