Refine your search:

I know the answers site has a description for having one Python program call another, which includes a custom module, but this seems to be more geared for scripted inputs or alerts. http://splunk-base.splunk.com/answers/8/can-i-add-python-modules-to-the-splunk-environment. I have a custom module that works outside of Splunk in Python 2.6, but I need to use this within a lookup Python script. The script will have parameters passed within it as labeled in transforms.conf. The custom module will eventually call native C/C++ code. The module builds itself into an egg file. I can't simply drop this file into Splunk's Python 2.6 site-packages directory as even the import didn't work. How do I let Splunk know about this module so that the lookup Python script can import and use it?

asked 26 Jun '11, 20:25

ndoshi's gravatar image

ndoshi
4.6k110
accept rate: 0%


2 Answers:

Try using a wrapper script. The one described in the answer you link to is possibly more complex than what's needed for lookups. I solved this problem yesterday using a wrapper, as follows.

wrapper.py:

import os

NEW_PYTHON_PATH = '/usr/bin/python'

os.environ['PYTHONPATH'] = NEW_PYTHON_PATH
my_process = '/opt/splunk/etc/apps/zgp/bin/lookup.py')

os.execv(my_process, ())
link

answered 28 Jun '11, 12:40

BryantD's gravatar image

BryantD
181
accept rate: 100%

Thanks for your reply. I think the the field header arguments would have to be put in the myprocess = ... part. Lowell provided an even easier answer in a past post for my module that happens to be in an egg: Lowell wrote "Instead I recommend creating .egg files, putting them in your own lib folder, and explicitly doing a sys.path.append("/your/lib/whatever.egg") before your import."

(28 Jun '11, 17:32) ndoshi

As an aside, I was able to call a script with this:

#!/bin/bash
/usr/bin/python /path/to/python/script.py

.. andit found all my moduldes and worked fine.

link

answered 03 Feb, 13:18

rosslord's gravatar image

rosslord
11
accept rate: 0%

My original question was for lookup scripts as lookups call Python directly and do not call shell scripts.

(06 Feb, 06:12) ndoshi
Post your answer
toggle preview

Follow this question

Log In to enable email subscriptions

RSS:

Answers

Answers + Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×189
×87
×40

Asked: 26 Jun '11, 20:25

Seen: 870 times

Last updated: 06 Feb, 06:12

Copyright © 2005-2012 Splunk, Inc. All rights reserved.