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!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

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

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...