<?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: How to do POST call / webhook from Splunk Dashboard on Click button in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404692#M6954</link>
    <description>&lt;P&gt;I don't know about overriding a dashboard's submit button.  That sounds like a bad idea.  But beyond that, you can put an html  simple XML element on the page and stuff arbitrary HTML and buttons and javascript to fire on them right there on the page.&lt;/P&gt;

&lt;P&gt;My bigger concern would be things like the browser's CORS.  I would not personally want to have to change the CORS of splunk itself to enable javascript running in my dashboard to make calls to a remote origin.  &lt;/P&gt;

&lt;P&gt;Also, you'd have to provide credentials to the javascript in the browser to be able to interact with the external service (unless it lacks authentication)&lt;/P&gt;

&lt;P&gt;What I would suggest is that you put your "webhook call" in a custom search command on the search head.  Then your dashboard can call your " | mycommand arg1 arg2 arg3 " -- and the webhook call occurs on the server.  Your custom command can then consult Splunk's credential store to get the authentication data it needs, make the call, and return any data to the dashboard.&lt;/P&gt;

&lt;P&gt;Just my two cents&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2019 18:26:45 GMT</pubDate>
    <dc:creator>dwaddle</dc:creator>
    <dc:date>2019-04-10T18:26:45Z</dc:date>
    <item>
      <title>How to do POST call / webhook from Splunk Dashboard on Click button</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404691#M6953</link>
      <description>&lt;P&gt;Suppose I have a test curl command which is working:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -k &lt;A href="http://ip:port/get_config" target="test_blank"&gt;http://ip:port/get_config&lt;/A&gt; -d tgt=juniper -d tgt_type=glob
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;now I need to figure out how to issue a &lt;CODE&gt;POST call&lt;/CODE&gt; from Splunk dashboard and what the call format needs to be.&lt;/P&gt;

&lt;P&gt;so here is a thing :&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;1)&lt;/STRONG&gt; I have 2 inputs say &lt;CODE&gt;tgt&lt;/CODE&gt; and &lt;CODE&gt;tgt_type&lt;/CODE&gt; (could be a dropdown/input box) and submit button :&lt;BR /&gt;
For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form script="test1.js"&amp;gt;
  &amp;lt;label&amp;gt;test&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="true" autoRun="false"&amp;gt;
    &amp;lt;input type="dropdown" token="tgt" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;tgt&amp;lt;/label&amp;gt;
      &amp;lt;choice value="juniper"&amp;gt;juniper&amp;lt;/choice&amp;gt;
    &amp;lt;/input&amp;gt;
    &amp;lt;input type="dropdown" token="tgt_type" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;tgt_type&amp;lt;/label&amp;gt;
      &amp;lt;choice value="glob"&amp;gt;glob&amp;lt;/choice&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;2)&lt;/STRONG&gt; Once I select the values and click on the &lt;CODE&gt;submit&lt;/CODE&gt; button, I should make a POST request/webhook using any method ajax or js,etc.&lt;/P&gt;

&lt;P&gt;consider a POST URL is &lt;CODE&gt;&lt;A href="http://ip:port/hook/get_config?tgt=$tgt$&amp;amp;tgt_type=$tgt_type$" target="test_blank"&gt;http://ip:port/hook/get_config?tgt=$tgt$&amp;amp;tgt_type=$tgt_type$&lt;/A&gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Thanks in Advance. &lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 18:09:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404691#M6953</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-04-10T18:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to do POST call / webhook from Splunk Dashboard on Click button</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404692#M6954</link>
      <description>&lt;P&gt;I don't know about overriding a dashboard's submit button.  That sounds like a bad idea.  But beyond that, you can put an html  simple XML element on the page and stuff arbitrary HTML and buttons and javascript to fire on them right there on the page.&lt;/P&gt;

&lt;P&gt;My bigger concern would be things like the browser's CORS.  I would not personally want to have to change the CORS of splunk itself to enable javascript running in my dashboard to make calls to a remote origin.  &lt;/P&gt;

&lt;P&gt;Also, you'd have to provide credentials to the javascript in the browser to be able to interact with the external service (unless it lacks authentication)&lt;/P&gt;

&lt;P&gt;What I would suggest is that you put your "webhook call" in a custom search command on the search head.  Then your dashboard can call your " | mycommand arg1 arg2 arg3 " -- and the webhook call occurs on the server.  Your custom command can then consult Splunk's credential store to get the authentication data it needs, make the call, and return any data to the dashboard.&lt;/P&gt;

&lt;P&gt;Just my two cents&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 18:26:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404692#M6954</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2019-04-10T18:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to do POST call / webhook from Splunk Dashboard on Click button</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404693#M6955</link>
      <description>&lt;P&gt;sorry i am new to dev,how can I make the custom command to call the API which can pass args. &lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 18:52:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404693#M6955</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-04-10T18:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to do POST call / webhook from Splunk Dashboard on Click button</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404694#M6956</link>
      <description>&lt;P&gt;@mayurr98 &lt;/P&gt;

&lt;P&gt;Go through below links for reference.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://www.hurricanelabs.com/blog/splunk-custom-endpoints-part-1-the-basics"&gt;https://www.hurricanelabs.com/blog/splunk-custom-endpoints-part-1-the-basics&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://www.hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-2-cleaning-the-data"&gt;https://www.hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-2-cleaning-the-data&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://www.hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-3-posting-the-data"&gt;https://www.hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-3-posting-the-data&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://www.hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-4-getting-the-data"&gt;https://www.hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-4-getting-the-data&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 05:14:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404694#M6956</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-11T05:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to do POST call / webhook from Splunk Dashboard on Click button</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404695#M6957</link>
      <description>&lt;P&gt;Hi @mayurr98,&lt;/P&gt;

&lt;P&gt;As per @dwaddle suggestion, here is sample script which fire POST request to HEC URL with custom search command.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;$SPLUNK_HOME/etc/apps/myapp/bin/test.py&lt;/STRONG&gt; (Please change mode of execution for this script For exa. &lt;CODE&gt;chmod 750 test.py&lt;/CODE&gt; for linux)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import requests, splunk.Intersplunk, json

keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()
if 'tgt' in argvals:
    target = argvals.get("tgt", None)

if 'tgt_type' in argvals:
    target_type = argvals.get("tgt_type", None)


if not target:
    splunk.Intersplunk.parseError("'tgt' argument not provided")

if not target_type:
    splunk.Intersplunk.parseError("'tgt_type' argument not provided")

try:
    head={"Authorization":"Splunk &amp;lt;HEC Token&amp;gt;", "Content-Type": "application/json"}
    url="https://localhost:8088/services/collector/event"
    data={"sourcetype": "test", "event": {"tgt": target, "tgt_type": target_type}}
    r = requests.post(url, data=json.dumps(data), headers=head, verify=False)
except Exception, e:
    splunk.Intersplunk.parseError(e)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In above script I have disabled certificate verification in my lab but please remove &lt;CODE&gt;verify=False&lt;/CODE&gt; in production environment if you have enabled HEC over SSL so that it will verify certificate.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;$SPLUNK_HOME/etc/apps/myapp/default/commands.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[testcommand]
filename = test.py
local = true
generating = true
supports_rawargs = false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;$SPLUNK_HOME/etc/apps/myapp/metadata/default.meta&lt;/STRONG&gt; (Here I have restricted &lt;CODE&gt;testcommand&lt;/CODE&gt; to admin only but you can adjust permission based on your requirement)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[commands]
access = read : [ * ], write : [ admin ]
export = system

[commands/testcommand]
access = read : [ admin ], write : [ admin ]
export = system
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Search Window&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| testcommand tgt=juniper tgt_type=glob
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you run above command it will ingest event in HEC with JSON format and event raw data will be &lt;CODE&gt;{"tgt": "juniper", "tgt_type": "glob"}&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 10:13:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404695#M6957</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-04-11T10:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to do POST call / webhook from Splunk Dashboard on Click button</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404696#M6958</link>
      <description>&lt;P&gt;Thanks with few modifications it worked:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import requests, splunk.Intersplunk, json

keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()
if 'tgt' in argvals:
     target = argvals.get("tgt", None)

if 'tgt_type' in argvals:
     target_type = argvals.get("tgt_type", None)


if not target:
     splunk.Intersplunk.parseError("'tgt' argument not provided")

if not target_type:
     splunk.Intersplunk.parseError("'tgt_type' argument not provided")

results = []
result = {}

try:
     head = {'Content-Type': "application/x-www-form-urlencoded"}
     url="api"
     data={"tgt": target, "tgt_type": target_type}
     r = requests.post(url, data=json.dumps(data), headers=head)
     if r.status_code == 200:
        result['response'] = r.content
        results.append(result)
        splunk.Intersplunk.outputResults(results)
     else:
        result['response'] = "Failed"
        results.append(result)
        splunk.Intersplunk.outputResults(results)
except Exception, e:
     splunk.Intersplunk.parseError(e)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Apr 2019 17:40:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404696#M6958</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2019-04-11T17:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to do POST call / webhook from Splunk Dashboard on Click button</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404697#M6959</link>
      <description>&lt;P&gt;You could also consider the &lt;A href="https://splunkbase.splunk.com/app/4146/"&gt;Web Tools Add-on&lt;/A&gt; , this provides a curl command in Splunk&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2019 02:44:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-do-POST-call-webhook-from-Splunk-Dashboard-on-Click/m-p/404697#M6959</guid>
      <dc:creator>gjanders</dc:creator>
      <dc:date>2019-04-13T02:44:11Z</dc:date>
    </item>
  </channel>
</rss>

