<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Custom Search Command over SSH in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81313#M20576</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I just stumbled across your question, and I happen to be developing a very similar Modular Input.  Basically, it uses Pexpect to SSH into a device, and executes a list of commands that you configure.  The output of each command is a multiline event.&lt;/P&gt;

&lt;P&gt;If you are interested in beta testing this App, email me at &lt;A href="mailto:jdonn@splunk.com"&gt;jdonn@splunk.com&lt;/A&gt;.  &lt;/P&gt;

&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Mon, 04 Nov 2013 00:28:18 GMT</pubDate>
    <dc:creator>jdonn_splunk</dc:creator>
    <dc:date>2013-11-04T00:28:18Z</dc:date>
    <item>
      <title>Python Custom Search Command over SSH</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81312#M20575</link>
      <description>&lt;P&gt;Greetz,&lt;/P&gt;

&lt;P&gt;For security purposes we wish to do a search from an untrusted host (could be compromised)&lt;BR /&gt;
and therefore cannot allow the remote indexers to be search peers as if the searchhead in question is compromised, they could do searches with deletes.&lt;/P&gt;

&lt;P&gt;I don't see any way to control what a searchhead does on an indexer? I saw something about a search peer account&lt;BR /&gt;
possibly being introduced in a release to restrict privileges?&lt;/P&gt;

&lt;P&gt;Can we do a custom search command that does a remote search via SSH that generates events and returns results so it looks like a "local" search?&lt;BR /&gt;
What would the output format be on the remote side?&lt;/P&gt;

&lt;P&gt;Any help is much appreciated!&lt;BR /&gt;
The SSH part is tested and works.&lt;/P&gt;

&lt;P&gt;I have the below but cannot code so it shows, I need help.&lt;BR /&gt;
I am not sure about the remote output format, must it be parsed, processed etc.?&lt;BR /&gt;
Can this even be done?&lt;/P&gt;

&lt;P&gt;I get "External search command 'helloworld' returned error code 1."&lt;/P&gt;

&lt;P&gt;And running the below hangs until interrupted:&lt;/P&gt;

&lt;P&gt;[splunk@anomaly splunk]$ ./bin/splunk cmd python etc/apps/search/bin/helloworld.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^CERROR
"Error : Traceback: Traceback (most recent call last):
File ""etc/apps/search/bin/helloworld.py"", line 14, in &amp;lt;module&amp;gt;
results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()
File ""/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.py"", line 310, in getOrganizedResults
results = readResults(input_str, settings)
File ""/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.py"", line 263, in readResults
first = False
KeyboardInterrupt
"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;etc/apps/search/local/commands.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[helloworld]
filename = helloworld.py
generating = true
streaming = true
supports_rawargs = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;etc/apps/search/bin/helloworld.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import re,sys,time,subprocess, splunk.Intersplunk

def hello(results, settings):
    results = []
    result = subprocess.check_output("ssh -i /home/splunk/.ssh/id_rsa 10.0.0.242 '/opt/splunkindexer/bin/splunk search 'index=test' -earliest_time -300d@d -latest_time @d -output rawdata -auth admin:changeyou -uri &lt;A href="https://127.0.0.1:8089'&amp;quot;" target="test_blank"&gt;https://127.0.0.1:8089'"&lt;/A&gt;, shell=True)
    results.append(result)
    return results

results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()
results = hello(results, settings)
splunk.Intersplunk.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2013 13:30:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81312#M20575</guid>
      <dc:creator>ephemeric</dc:creator>
      <dc:date>2013-10-03T13:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python Custom Search Command over SSH</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81313#M20576</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I just stumbled across your question, and I happen to be developing a very similar Modular Input.  Basically, it uses Pexpect to SSH into a device, and executes a list of commands that you configure.  The output of each command is a multiline event.&lt;/P&gt;

&lt;P&gt;If you are interested in beta testing this App, email me at &lt;A href="mailto:jdonn@splunk.com"&gt;jdonn@splunk.com&lt;/A&gt;.  &lt;/P&gt;

&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2013 00:28:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81313#M20576</guid>
      <dc:creator>jdonn_splunk</dc:creator>
      <dc:date>2013-11-04T00:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python Custom Search Command over SSH</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81314#M20577</link>
      <description>&lt;P&gt;Not following why you need to SSH in instead of just issuing a search using directly using the REST API available on the splunkd port (8089) - firewall issues or...?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2013 07:33:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81314#M20577</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2013-11-04T07:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python Custom Search Command over SSH</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81315#M20578</link>
      <description>&lt;P&gt;Have you managed to get the app published?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 20:04:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-Custom-Search-Command-over-SSH/m-p/81315#M20578</guid>
      <dc:creator>ferdydek</dc:creator>
      <dc:date>2017-02-21T20:04:08Z</dc:date>
    </item>
  </channel>
</rss>

