Splunk Dev

Custom search command with python stopped working - not returning ressult

smitra_cis
Observer

Hi, 

I created a custom search command following the instruction in the page and it was working fine (https://www.splunk.com/en_us/blog/tips-and-tricks/write-your-own-search-language.html)

however stopped working suddenly.  Tried to put some file creation statement, the files are not created - looks the python program is not running at all.

Python code (C:\Program Files\Splunk\etc\apps\search\bin)

import splunk.Intersplunk

def getShape(text):
phrase1 = "upload"
phrase2 = "TrustedInstaller"
description = []
if (phrase1 in text):
description.append("Infra")
elif (phrase2 in text):
description.append("InstallationGroup")
else:
description.append("Misc")
Corpus = pd.read_csv(r"E:\corpus_single.csv",encoding='latin-1')
Corpus.to_csv(r'E:\corpus_func.csv', index = False)
if len(description) == 0
return "normal"
return "_".join(description)

 

# get the previous search results
results,unused1,unused2 = splunk.Intersplunk.getOrganizedResults()
Corpus = pd.read_csv(r"E:\corpus_single.csv",encoding='latin-1')
Corpus.to_csv(r'E:\corpus_out.csv', index = False)
# for each results, add a 'shape' attribute, calculated from the raw event text
for result in results:
result["assignmentgrp"] = getShape(result["Message"])
# output results
splunk.Intersplunk.outputResults(results)

---------

Entry in command.conf

(folder :C:\Program Files\Splunk\etc\apps\search\default)

[getgroup]
filename = getgroup.py

---------------

Search Query 

source="winlog1.txt" | rex field=_raw "Message: <(?<Message>.*)>" | dedup Message | table Message, getgroup

--------

winlog1.txt sample data - having around 10 records 

2016-09-28 04:30:31, Info Message: <Ending TrustedInstaller initialization.>
2016-09-28 04:30:31, Info Message: <Starting the TrustedInstaller main loop.>
2016-09-28 04:30:31, Info Message: <TrustedInstaller service starts successfully.>
2016-09-28 04:30:31, Info Message: <Initializing online with Windows opt-in: False.>

 

Labels (2)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

Is there anything in C:\Program Files\Splunk\var\log\splunk\python.log ?

Its also worth checking the search log, Inspect your search through Job -> Inspect Job and then click the "search.log" link. 

Does this shine any light on things?

 

 

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...