<?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: Cannot get external lookup to work in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74114#M18620</link>
    <description>&lt;P&gt;It certainly looks that way. Something in your lookup script is throwing an error. What I've done when I've developed dynamic lookups that I wanted to troubleshoot in the past is to redirect stderr to some file so I can see what errors the lookup is throwing.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;f = open("/path/to/some/file","w")
sys.stderr = f
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 Oct 2012 06:03:46 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2012-10-01T06:03:46Z</dc:date>
    <item>
      <title>Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74109#M18615</link>
      <description>&lt;P&gt;I am trying to set up a lookup in my test environment to hopefully push out to production.  I have created an app and set up the transforms and props with the following details(By the way, a clog is an internal process we use at my work):&lt;BR /&gt;
translforms.conf&lt;BR /&gt;
[extraClogDetails]&lt;BR /&gt;
external_cmd = clogvalues.py date popcode pages&lt;BR /&gt;
external_type = python&lt;BR /&gt;
fields_list = date, popcode, pages&lt;/P&gt;

&lt;P&gt;props.conf&lt;BR /&gt;
[clogsreceived]&lt;BR /&gt;
LOOKUP-pages = extraClogDetails date popcode pages OUTPUT pages&lt;/P&gt;

&lt;P&gt;I have created my external lookup script and when I run the script catting in an csv file, all seems fine:&lt;BR /&gt;
(Running Script from command line) python clogvalues.py date popcode pages &amp;lt; /tmp/test.csv&lt;BR /&gt;
(Output) &lt;BR /&gt;
date,popcode,pages&lt;BR /&gt;
2012-08-09,us_isp_nz3,42331&lt;BR /&gt;
2012-08-09,us_isp_nz5,44694&lt;/P&gt;

&lt;P&gt;(entries in test.csv)&lt;BR /&gt;
date,popcode,pages&lt;BR /&gt;
"2012-08-09","us_isp_nz3",&lt;BR /&gt;
"2012-08-09","us_isp_nz5",&lt;/P&gt;

&lt;P&gt;When I try to do a lookup from the command line, I get no output for pages:&lt;BR /&gt;
./splunk search "sourcetype=clogsreceived popcode="*callplus2_27" | lookup extraClogDetails date popcode pages OUTPUT pages"&lt;BR /&gt;
date=2012-08-09 00:00:00+10:00 popcode=us_isp_nz3 &lt;BR /&gt;
date=2012-08-09 00:00:00+10:00 popcode=us_isp_nz5&lt;/P&gt;

&lt;P&gt;I am not sure what I have missed and I am not getting any errors from splunk.  Is there anything further that I can check, or is there a better debug mode that will show me where I am going wrong.&lt;/P&gt;

&lt;P&gt;Any assistance would be appreciated.&lt;/P&gt;

&lt;P&gt;Regards Vince&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:31:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74109#M18615</guid>
      <dc:creator>vincesesto</dc:creator>
      <dc:date>2020-09-28T12:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74110#M18616</link>
      <description>&lt;P&gt;You shouldn't be supplying the OUTPUT field as an input field as well. You have this in your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;lookup extraClogDetails date popcode pages OUTPUT pages
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But it needs to be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;lookup extraClogDetails date popcode OUTPUT pages
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;so that &lt;CODE&gt;pages&lt;/CODE&gt; is only in the output, not on both sides.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 07:03:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74110#M18616</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-09-28T07:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74111#M18617</link>
      <description>&lt;P&gt;Hey Ayn,&lt;/P&gt;

&lt;P&gt;Thanks for your response.  I understand what you are saying but do you know how that will work with my python script.  In the examples provided, you are supposed to give a header that will include the empty field, in this case I have the header of:&lt;BR /&gt;
date, popcode, pages&lt;/P&gt;

&lt;P&gt;And my understanding is that splunk will fill in the blank page values...Will I need to amend my script to no longer look for the "pages" field in the header?&lt;/P&gt;

&lt;P&gt;Regards,&lt;/P&gt;

&lt;P&gt;Vince&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 07:17:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74111#M18617</guid>
      <dc:creator>vincesesto</dc:creator>
      <dc:date>2012-09-28T07:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74112#M18618</link>
      <description>&lt;P&gt;Splunk will look at the &lt;CODE&gt;fields_list&lt;/CODE&gt; in your lookup definition and send those fields to the lookup script, regardless of which fields you specify yourself in the actual lookup command. So, you don't need to worry about that yourself in your script.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2012 08:31:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74112#M18618</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-09-28T08:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74113#M18619</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
So I am no longer using the OUTPUT field, but now I am still not able to get my pages values filled.  I am getting the following output:&lt;BR /&gt;
splunk@crunchbang:~/bin$ ./splunk search "sourcetype="clogsreceived" popcode="us_isp_au1" | lookup clog_details date popcode OUTPUT pages"&lt;BR /&gt;
ERROR: Script for lookup table 'clog_details' returned error code 1.  Results may be incorrect.&lt;BR /&gt;
date=2012-08-09 popcode=us_isp_au1 up_page_limit=201348.0 low_page_limit=134232.0&lt;BR /&gt;
date=2012-08-08 popcode=us_isp_au1 up_page_limit=204788.4 low_page_limit=136525.6&lt;/P&gt;

&lt;P&gt;The ERROR seems to be killing my lookup. &lt;BR /&gt;
Vince&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:32:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74113#M18619</guid>
      <dc:creator>vincesesto</dc:creator>
      <dc:date>2020-09-28T12:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74114#M18620</link>
      <description>&lt;P&gt;It certainly looks that way. Something in your lookup script is throwing an error. What I've done when I've developed dynamic lookups that I wanted to troubleshoot in the past is to redirect stderr to some file so I can see what errors the lookup is throwing.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;f = open("/path/to/some/file","w")
sys.stderr = f
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2012 06:03:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74114#M18620</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-10-01T06:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74115#M18621</link>
      <description>&lt;P&gt;Hey Ayn,&lt;BR /&gt;
Just want to thank you for helping me with this.  I finally got this working as I was using the python psycopg2 library to connect to the database...Turns out this will not work with the splunk python.  I have set up a wrapper script to get this working finally.&lt;/P&gt;

&lt;P&gt;Thanks again.&lt;/P&gt;

&lt;P&gt;Regards, Vince&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2012 04:47:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74115#M18621</guid>
      <dc:creator>vincesesto</dc:creator>
      <dc:date>2012-10-02T04:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74116#M18622</link>
      <description>&lt;P&gt;Hello All,&lt;BR /&gt;
Just letting you know that this issue was caused by splunk not working with external python modules. Specifically in this case the psycopg2 module used to connect with postgres databases.  I was not able to load the module into the Splunk python environment so needed to resort to creating a wrapper script as per ticket:&lt;BR /&gt;
&lt;A href="http://splunk-base.splunk.com/answers/10839/scripted-lookup-script-doesnt-work-with-splunk-python-version-but-works-fine-with-python-27"&gt;http://splunk-base.splunk.com/answers/10839/scripted-lookup-script-doesnt-work-with-splunk-python-version-but-works-fine-with-python-27&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For those interested the wrapper script is very simple, and takes the command line arguements, and then sends them to your lookup script as per below.  This script is the one referenced in the transfors.conf for the external_cmd lookup configs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import os, sys
real_script = "/opt/splunk/etc/apps/BMSDBAccess/bin/clogvalues.py"
python_executable = "/usr/bin/python"
os.execv(python_executable, [ python_executable, real_script ] + sys.argv[1:])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That is all there is to it, but it does slow things down quite a bit having to go through this extra wrapper script to get the job done...I would be great for splunk to either include this module into their environment or resolve this issue as it was the last thing I was expecting.&lt;/P&gt;

&lt;P&gt;Regards Vince&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2012 00:49:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74116#M18622</guid>
      <dc:creator>vincesesto</dc:creator>
      <dc:date>2012-10-03T00:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get external lookup to work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74117#M18623</link>
      <description>&lt;P&gt;Vince can you please post your clogvalues.py script?&lt;BR /&gt;
Regards,&lt;BR /&gt;
Stefano&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2013 08:06:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-external-lookup-to-work/m-p/74117#M18623</guid>
      <dc:creator>stefano_guidoba</dc:creator>
      <dc:date>2013-10-10T08:06:40Z</dc:date>
    </item>
  </channel>
</rss>

