Installation

Getting error foe External lookup, Script execution failed for external search command

abhishekkalokhe
Explorer

Hi 
I am working on External lookup, below is my code

new.py

import csv
import os,sys
import subprocess
import requests
import sys
import json

infile = sys.stdin
outfile = sys.stdout
r = csv.DictReader(infile)
result = 0
new_fieldnames = ["clientip", "fraud_score", "country_code", "success"] 
w = csv.DictWriter(outfile, fieldnames=new_fieldnames)
w.writeheader()

apiURL = "my-api"
clientip = sys.argv[1]
URL = apiURL + clientip
r = requests.get(URL)
data = r.json()
result = {"clientip":str(data["host"]),"fraud_score": str(data["fraud_score"]), "country_code":str(data["country_code"]), "success":str(data["success"])}
w.writerow(result)

Above code is giving output as below:-

/opt/splunk/bin/splunk cmd python /opt/splunk/etc/apps/TA-test/bin/new.py 172.168.0.2
clientip,fraud_score,country_code,success
172.168.0.2,75,US,True


0 Karma

abhishekkalokhe
Explorer

I am using below transforms.conf

[new]
allow_caching = 0
case_sensitive_match = 1
external_cmd = new.py clientip
fields_list = clientip,fraud_score,country_code,success

And getting this error - Script execution failed for external search command '/opt/splunk/etc/apps/TA-test/bin/new.py'.

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...