Archive
Highlighted

External Commands calling perl script fails

Communicator

I have been able to have my external commands use subprocess to call commands because not all modules exist in the splunk environment and that has worked fine. I now need to call a perl script because the data I am retrieving is only accessible through a perl API. I need to call a perl script from within and external python command and I can't get it to work. It works great for shell scripts and python scripts but not for perl. The script works outside of splunk but not from within splunk. I must be not getting something from the environment within splunk but don't know what it is.


This works fine outside of splunk but does note even execute within splunk. (I didn't include the splunk imports and processing, just the function that it is calling.


#!/usr/bin/python

import subprocess
import os

def getemp(host):
  cmd = ("/usr/bin/perl","/opt/splunk/etc/apps/KtN/bin/mrilookup.pl",host)
  pseudohandle = subprocess.Popen(cmd,stdin=subprocess.PIPE,            stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False)
  pseudohandle.stdin.write(host)
  stdout, stderr = pseudohandle.communicate()
  pseudohandle.stdin.close()
  return  stdout.rstrip()

print getemp("bugs")
Tags (1)

Re: External Commands calling perl script fails

Communicator

I found if I take out the added per libs it works. How do I get the perl libs added? I tried both use lib xxx and push @INC xxx within the perl script and they appear to be ignored. If I run the script as the splunk user either way they work. It is only when the external command using subprocess call the script that it fails.

Highlighted

Re: External Commands calling perl script fails

Communicator

Finally figured it out. I added the PER5LIB path to the subproccess command via env={"PERL5LIB":"/pathtolib"}
It works!!!

View solution in original post