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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...