<?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: Custom command - Getinfo probe failed in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333375#M4925</link>
    <description>&lt;P&gt;it doesn't find any errors at startup.&lt;BR /&gt;
This is right method to use intersplunk?&lt;/P&gt;</description>
    <pubDate>Mon, 11 Dec 2017 13:28:21 GMT</pubDate>
    <dc:creator>drebai</dc:creator>
    <dc:date>2017-12-11T13:28:21Z</dc:date>
    <item>
      <title>Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333373#M4923</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;
I created a custom command for a comparison between json.&lt;BR /&gt;
The steps to create it:&lt;/P&gt;

&lt;P&gt;0) created fieldcompare folder in etc/apps (with bin, metadata and default subfolders)&lt;/P&gt;

&lt;P&gt;1) fieldcompare.py (in etc/apps/fieldcompare/bin)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# custom command

import splunk.Intersplunk  
import json
from splunklib.searchcommands import \
     dispatch, StreamingCommand, Configuration, Option, validators


 # long def function (searchleveljson) that looks for things in jsons
 #etc etc

(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
args, kwargs = splunk.Intersplunk.getKeywordsAndOptions()

if isgetinfo:
     # streaming, generating, retevs, reqsop, preop
    splunk.Intersplunk.outputInfo(True, False, False, False, None)


(results, dummyresults, settings) = splunk.Intersplunk.getOrganizedResults()

field1 = kwargs.get("field1", "field1")
field2 = kwargs.get("field2", "field2")

try:
    for result in results:
        try:
            j1 = json.load(field1)
            j2 = json.load(field2)
        except KeyError:
             # If either field is missing, simply ignore
            continue

        resultKey = list()
        resultValues = list()
        searchleveljson(j1,j2,resultKey,resultValues)

        result["mismatched keys"]=json.dumps(resultKey)
        result["Value diff"]=json.dumps(resultValues)


splunk.Intersplunk.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;2) commands.conf (in etc/apps/fieldcompare/default)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[fieldcompare]
filename = fieldcompare.py
supports_getinfo = true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;3) default.meta (in etc/apps/fieldcompare/metadata)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [commands/fieldcompare]
 access = read : [ * ], write : [ admin ]
 export = system

 [scripts/fieldcompare.py]
 access = read : [ * ], write : [ admin ]
 export = system
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;4) copy splunklib (with modularinput and searchcommands) &lt;STRONG&gt;in&lt;/STRONG&gt; etc/apps/fieldcompare/bin &lt;STRONG&gt;from&lt;/STRONG&gt; etc\apps\framework\contrib\splunk-sdk-python&lt;/P&gt;

&lt;P&gt;5) Restart splunk&lt;/P&gt;

&lt;P&gt;6) index=* etc etc | table expected actual | fieldcompare field1=expected field2=actual&lt;/P&gt;

&lt;P&gt;but I get an error that says:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Error in 'script': Getinfo probe failed for external search command 'fieldcompare'&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;What am I doing wrong?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
have a good day.&lt;/P&gt;

&lt;P&gt;Debora&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 10:26:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333373#M4923</guid>
      <dc:creator>drebai</dc:creator>
      <dc:date>2017-12-11T10:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333374#M4924</link>
      <description>&lt;P&gt;Are you getting any error when you start your splunk server? Any compilation error in your customcommand will get reported only at starting of Splunk server.&lt;/P&gt;

&lt;P&gt;Also you can check &lt;A href="https://splunkbase.splunk.com/app/3447/"&gt;https://splunkbase.splunk.com/app/3447/&lt;/A&gt;.  It has different way of writing streaming command.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 12:56:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333374#M4924</guid>
      <dc:creator>hardikJsheth</dc:creator>
      <dc:date>2017-12-11T12:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333375#M4925</link>
      <description>&lt;P&gt;it doesn't find any errors at startup.&lt;BR /&gt;
This is right method to use intersplunk?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 13:28:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333375#M4925</guid>
      <dc:creator>drebai</dc:creator>
      <dc:date>2017-12-11T13:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333376#M4926</link>
      <description>&lt;P&gt;I would suggest moving to the SDK (referenced in your script as &lt;CODE&gt;splunklib&lt;/CODE&gt; but not actually used).  Check out the &lt;A href="https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/bin/filter.py"&gt;filter.py&lt;/A&gt; example that comes with the SDK for guidance.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 23:51:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333376#M4926</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2017-12-11T23:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333377#M4927</link>
      <description>&lt;P&gt;Yes use of intersplunk is correct. &lt;/P&gt;

&lt;P&gt;Few things I just noticed from your code. You are creating tupple when fetching results. You should update that query as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you return result, it should be list of directories.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 05:57:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333377#M4927</guid>
      <dc:creator>hardikJsheth</dc:creator>
      <dc:date>2017-12-13T05:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333378#M4928</link>
      <description>&lt;P&gt;I tried to create the custom command in both ways.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Intersplunk way&lt;/EM&gt;:&lt;BR /&gt;
I added "import sys"  and removed import from splunklib.&lt;BR /&gt;
From splunk search page I read an error that asks to add &lt;STRONG&gt;GETINFO&lt;/STRONG&gt; or &lt;STRONG&gt;EXECUTE&lt;/STRONG&gt;&lt;BR /&gt;
I changed the command to:&lt;BR /&gt;
| fieldcompare &lt;STRONG&gt;EXECUTE&lt;/STRONG&gt; field1=x field2=y &lt;BR /&gt;
but I get a generic error 1.&lt;BR /&gt;
I add getOrganizedResults before outputResults but nothing has changed.&lt;BR /&gt;
I would just like to pass two parameters and get two new ones for each line but it seems more complicated than expected.&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;SDK way&lt;/EM&gt;:&lt;BR /&gt;
I followed the &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEU2"&gt;documentation&lt;/A&gt;.&lt;BR /&gt;
I started from SDK templates, taking inspiration from the examples and I created a class that extends a GeneratingCommand but the error is always the same:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Error in 'script': Getinfo probe failed for external search command 'jsoncompare'&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 10:47:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333378#M4928</guid>
      <dc:creator>drebai</dc:creator>
      <dc:date>2017-12-13T10:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333379#M4929</link>
      <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
I solved the problem with Intersplunk!&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 14:02:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333379#M4929</guid>
      <dc:creator>drebai</dc:creator>
      <dc:date>2017-12-13T14:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333380#M4930</link>
      <description>&lt;P&gt;Please post your solution as an answer and accept that answer so that others may benefit from your findings.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2017 14:17:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333380#M4930</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2017-12-13T14:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: Custom command - Getinfo probe failed</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333381#M4931</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Intersplunk solution:&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;apps/fieldcompare/bin/fieldcompare.py:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;# custom command script

import splunk.Intersplunk  
import json
import sys

def is_json(myjson):
    return type(myjson) == type({})

#found difference between two jsons 
def searchleveljson(json1,json2,resultKey,resultValues):
    keys=set(json1.keys())
    keys2=set(json2.keys())

    keys.update(keys2)
    for json_event in keys:
        if json_event not in json1:
            resultKey.append(json_event)
            resultValues.append("actual."+json_event+"."+json2[json_event])
            continue;
        if json_event not in json2:
            resultKey.append(json_event)
            resultValues.append("expected."+json_event+"."+json1[json_event])
            continue;
        v1 = json1[json_event]
        v2 = json2[json_event]
        if v1 != v2:
            if is_json(v1) and is_json(v2):
                searchleveljson(v1,v2,resultKey,resultValues)
            else:
                resultKey.append(json_event)
                diff = "actual."+json_event+"="+json2[json_event]
                diff+= " "
                diff+= "expected."+json_event+"="+json1[json_event]
                resultValues.append(diff)

(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
args, kwargs = splunk.Intersplunk.getKeywordsAndOptions()

if isgetinfo:
    # streaming, generating, retevs, reqsop, preop
    splunk.Intersplunk.outputInfo(True, False, False, False, None)


results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()

field1 = kwargs.get("json1", "field1")
field2 = kwargs.get("json2", "field2")


for result in results:
    try:
        #corrected errors for converting string to json
        #json.load(fieldx) -&amp;gt; json.loads(result[fieldx])
        j1 = json.loads(result[field1])
        j2 = json.loads(result[field2])
    except ValueError:
        pass

    resultKey = list()
    resultValues = list()
    searchleveljson(j1,j2,resultKey,resultValues)

    result["mismatched_keys"]=json.dumps(resultKey)
    result["value_diff"]=json.dumps(resultValues)


splunk.Intersplunk.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;apps/fieldcompare/default/custom.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[fieldcompare]
filename = fieldcompare.py
streaming=true
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;apps/fieldcompare/metadata/default.meta:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  [commands/fieldcompare]
  access = read : [ * ], write : [ admin ]
  export = system


 [scripts/fieldcompare.py]
 access = read : [ * ], write : [ admin ]
 export = system
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I deleted all other folders (spunk and splunklib)&lt;/P&gt;

&lt;P&gt;Restart splunk.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table column1 column2 | fieldcompare __EXECUTE__ json1=column1 json2=column2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the result is a table with the following columns:&lt;BR /&gt;
column1 | column2 | mismatched_keys | value_diff&lt;/P&gt;

&lt;P&gt;mismatched_keys contains all different keys &lt;BR /&gt;
value_diff contains all different value&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:17:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-command-Getinfo-probe-failed/m-p/333381#M4931</guid>
      <dc:creator>drebai</dc:creator>
      <dc:date>2020-09-29T17:17:01Z</dc:date>
    </item>
  </channel>
</rss>

