<?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: External Lookup script Never works in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/External-Lookup-script-Never-works/m-p/32363#M6732</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;make sure you have imported the csv library:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import csv #for splunk batch input/output
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;additional to this you need to add a loop to read each line and enrich each line and give it back into std output. here is a sample which reads the client ip, executes the method scorelookup and brings the values back.&lt;/P&gt;

&lt;P&gt;br&lt;BR /&gt;
matthias&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def main():
    #print 'starte main'

    if len(sys.argv) != 3:
        print "Usage: python [ip field] [threatscore]"
        sys.exit(0)
    r = csv.reader(sys.stdin)
    w = csv.writer(sys.stdout)
    clientip = sys.argv[1]
    threatscore = sys.argv[2]

    header = []
    first = True

    for line in r:
        if first:
            header = line
            if clientip not in header:
                print "IP field must exist in CSV data"
                sys.exit(0)
            csv.writer(sys.stdout).writerow(header)
            w = csv.DictWriter(sys.stdout, header)
            first = False
            continue

        # Read the result
        result = {}
        i = 0
        while i &amp;lt; len(header):
            if i &amp;lt; len(line):
                result[header[i]] = line[i]
            else:
                result[header[i]] = ''
            i += 1

        # Perform the lookup
        if len(result[clientip]):
            ts = scorelookup(result[clientip])
            out = "%s,%s" % (result[clientip],ts)
            print out

main()

#f.close()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Jul 2013 06:02:37 GMT</pubDate>
    <dc:creator>Matthias_BY</dc:creator>
    <dc:date>2013-07-19T06:02:37Z</dc:date>
    <item>
      <title>External Lookup script Never works</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-Lookup-script-Never-works/m-p/32362#M6731</link>
      <description>&lt;P&gt;From the url
 &lt;A href="http://blogs.splunk.com/2009/09/14/enriching-data-with-db-lookups-part-2/" rel="nofollow"&gt;http://blogs.splunk.com/2009/09/14/enriching-data-with-db-lookups-part-2/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;i read the following excerpt&lt;/P&gt;

&lt;P&gt;“The Python program gets its city field input via standard CSV input from Splunk, calls SQL to find the corresponding country, and produces the aggregate CSV output that contains the city with its correlated country”&lt;/P&gt;

&lt;P&gt;On further analyzing this statement I infer
“Splunk Web interface Serializes input  to Stdin and the Python Script using a CSV reader object reads the input from Stdin”&lt;/P&gt;

&lt;P&gt;Hence the presence of following code snippet in Python external lookup script
r = csv.reader(sys.stdin)&lt;/P&gt;

&lt;P&gt;Having said that the value of variable “r” is empty and the lookup script does nothing&lt;/P&gt;

&lt;P&gt;I  arrived at this statement by printing debugging statements to log file&lt;/P&gt;

&lt;P&gt;Is there anyone who can help with this?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2011 05:12:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-Lookup-script-Never-works/m-p/32362#M6731</guid>
      <dc:creator>bansi</dc:creator>
      <dc:date>2011-01-26T05:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: External Lookup script Never works</title>
      <link>https://community.splunk.com/t5/Splunk-Search/External-Lookup-script-Never-works/m-p/32363#M6732</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;make sure you have imported the csv library:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import csv #for splunk batch input/output
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;additional to this you need to add a loop to read each line and enrich each line and give it back into std output. here is a sample which reads the client ip, executes the method scorelookup and brings the values back.&lt;/P&gt;

&lt;P&gt;br&lt;BR /&gt;
matthias&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def main():
    #print 'starte main'

    if len(sys.argv) != 3:
        print "Usage: python [ip field] [threatscore]"
        sys.exit(0)
    r = csv.reader(sys.stdin)
    w = csv.writer(sys.stdout)
    clientip = sys.argv[1]
    threatscore = sys.argv[2]

    header = []
    first = True

    for line in r:
        if first:
            header = line
            if clientip not in header:
                print "IP field must exist in CSV data"
                sys.exit(0)
            csv.writer(sys.stdout).writerow(header)
            w = csv.DictWriter(sys.stdout, header)
            first = False
            continue

        # Read the result
        result = {}
        i = 0
        while i &amp;lt; len(header):
            if i &amp;lt; len(line):
                result[header[i]] = line[i]
            else:
                result[header[i]] = ''
            i += 1

        # Perform the lookup
        if len(result[clientip]):
            ts = scorelookup(result[clientip])
            out = "%s,%s" % (result[clientip],ts)
            print out

main()

#f.close()
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2013 06:02:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/External-Lookup-script-Never-works/m-p/32363#M6732</guid>
      <dc:creator>Matthias_BY</dc:creator>
      <dc:date>2013-07-19T06:02:37Z</dc:date>
    </item>
  </channel>
</rss>

