Splunk Search

External Commands calling perl script fails

rdownie
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)
1 Solution

rdownie
Communicator

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

View solution in original post

rdownie
Communicator

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

rdownie
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.

Get Updates on the Splunk Community!

Stay Connected: Your Guide to July and August Tech Talks, Office Hours, and Webinars!

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...

Edge Processor Scaling, Energy & Manufacturing Use Cases, and More New Articles on ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Get More Out of Your Security Practice With a SIEM

Get More Out of Your Security Practice With a SIEMWednesday, July 31, 2024  |  11AM PT / 2PM ETREGISTER ...