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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...