splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

search_command.py: Failed to parse transport header

Open serj-p opened this issue 9 years ago • 7 comments

When I run the basic example of FilterCommand I am getting this error when enable

enableheader = true or passauth = true

in commands.conf for this command.

External search command 'filter' returned error code 1. Script output = "'splunkVersion:6.5.1\n' chunked 1.0,244,0 {"inspector":{"messages":[["ERROR","RuntimeError at \"/Applications/Splunk/etc/apps/App/bin/splunk-sdk/splunklib/searchcommands/search_command.py\", line 858 : Failed to parse transport header: splunkVersion:6.5.1\n"]]},"finished":true}"

serj-p avatar Dec 11 '16 14:12 serj-p

Based on the error messages it looks like you're using search command protocol v2. This would be the case if you set chunked = true in commands.conf. Is that is the case neither enableheader or passauth are valid. Thankfully, they also aren't required for what you want splunkd to do: pass authentication-related facts.

Before I go on, please send your default and local commands.conf files and I'll confirm this. Thanks.

David-Noble-at-work avatar Dec 11 '16 18:12 David-Noble-at-work

Thank you for a quick reply. I have the following in commands conf

[filter]
filename = filter.py
streaming = true
retainsevents = true
overrides_timeorder = true
enableheader = true
passauth = true

serj-p avatar Dec 11 '16 18:12 serj-p

So it looks like I was mistaken. You've not specified chunked = true. I'm assuming that you're setting passauth = true so that you can issue requests to splunkd. Is that true?

If it is true, try replacing passauth = true with requires_srinfo = true. You should then be able to use the service property on your command object to issue requests to splunkd.

One more question: Can you send a sanitized version of your app?

I will not be able to debug today, but can debug tomorrow, if need be, especially if requres_srinfo = true does not solve your problem. Having some form of your source code will make this easier.

David-Noble-at-work avatar Dec 11 '16 19:12 David-Noble-at-work

Yes, my aim is to be able to query kv store from the command periodically. Command is meant to be run by triggered alert.

I changed conf to

[filter]
filename = filter.py
streaming = true
retainsevents = true
overrides_timeorder = true
requires_srinfo = true

and almost the same

``Failed to parse transport header: infoPath:/Applications/Splunk/var/run/splunk/dispatch/admin__admin__App__searchBarSearch_1481484455.226/externSearchResultsInfo.csv\n```

command code

from __future__ import absolute_import, division, print_function, unicode_literals
import os
import sys

sys.path.append(os.getcwd() + '/splunk-sdk')
from splunklib.searchcommands.streaming_command import StreamingCommand
from splunklib.searchcommands import dispatch, Configuration

@Configuration()
class CountMatchesCommand(StreamingCommand):
    def stream(self, records):
        for record in records:
            yield record

dispatch(CountMatchesCommand, sys.argv, sys.stdin, sys.stdout, __name__)

I run it from the app this way

* | head 1 | filter

serj-p avatar Dec 11 '16 19:12 serj-p

it selects v2 protocol as I see from the debug

serj-p avatar Dec 11 '16 19:12 serj-p

I'll debug this tomorrow. Until then please:

  • send a tarball containing a sanitized version of your entire app
  • try setting chunked chunked = false
  • if that doesn't work, try setting chunked = true and removing all other settings but 'filename'

David-Noble-at-work avatar Dec 11 '16 20:12 David-Noble-at-work

Closing due to inactivity

snickers2029 avatar Feb 23 '18 18:02 snickers2029