<?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 can I run a python script from a dashboard? in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338026#M5536</link>
    <description>&lt;P&gt;Thanks niketnilay.&lt;/P&gt;

&lt;P&gt;What I needed was to verify the last digit based on the 11 digits before.&lt;BR /&gt;
However, this is a great solution to validate numbers.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2018 18:42:19 GMT</pubDate>
    <dc:creator>guimilare</dc:creator>
    <dc:date>2018-01-31T18:42:19Z</dc:date>
    <item>
      <title>How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338021#M5531</link>
      <description>&lt;P&gt;Hello Splunkers.&lt;/P&gt;

&lt;P&gt;Can a dashboard run a python script?&lt;/P&gt;

&lt;P&gt;My scenario is: the user have a text input field to write a 12 digit number.&lt;BR /&gt;
The last digit is a check-digit, and it assures that the user will perform a search on a valid 12 digit number.&lt;/P&gt;

&lt;P&gt;However, the only way I can check the number is by a python script.&lt;BR /&gt;
The script receives the number, does so maths to garantee that the number is correct and returns &lt;STRONG&gt;True&lt;/STRONG&gt; or &lt;STRONG&gt;False&lt;/STRONG&gt;.&lt;/P&gt;

&lt;P&gt;So, what I need is: when the user inserts the number in the text input field and click on "Submit", the python script receives the number and return True or False so I can work with the number in the searches.&lt;/P&gt;

&lt;P&gt;Is it feasible?&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;BR /&gt;
Regards, GMA&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 15:49:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338021#M5531</guid>
      <dc:creator>guimilare</dc:creator>
      <dc:date>2018-01-29T15:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338022#M5532</link>
      <description>&lt;P&gt;Absolutely. I'd do this with an external lookup, as documented here:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.1/Knowledge/Configureexternallookups" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.1/Knowledge/Configureexternallookups&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;This will allow you to use your python script in any Splunk search with access to the lookup. Let's say you name the lookup &lt;CODE&gt;validate_number&lt;/CODE&gt;, and you name the token for the text input field &lt;CODE&gt;input_number&lt;/CODE&gt;. Then your search would be something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval input_number=$input_number$
| lookup validate_number number AS input_number OUTPUT validation_result
| fields - _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That should return a table of input_number values and their validation_result values.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:52:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338022#M5532</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2020-09-29T17:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338023#M5533</link>
      <description>&lt;P&gt;Hi elliotproebstel,&lt;/P&gt;

&lt;P&gt;I'm trying to do as sugested (and it really seems the right direction), but was unable to do so.&lt;BR /&gt;
I wrote a script in python to receive the number and return the validation.&lt;/P&gt;

&lt;P&gt;In CLI, it works:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;/opt/splunk/bin/python ver_check_digit.py 1644432
cardid,status
1644432,False
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, when I run the search in SH, I get the following error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Script for lookup table 'ver_check_digit' returned error code 1. Results my be incorrect.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is my python script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python

import csv
import sys
import socket

def ver_check_digit(value):
    int_value = int(value)
    str_value = str(int_value)
    count = 1
    total_sum = 0

    while count &amp;lt; len(str_value):
        count = count + 1
        extracted_digit = str_value[-count]
        extracted_digit = int(extracted_digit)

        if count % 2 == 0:
            extracted_digit = extracted_digit * 2
            if extracted_digit &amp;gt; 9:
                extracted_digit = extracted_digit - 9

        total_sum = total_sum + extracted_digit

    check_digit = (total_sum * 9) % 10

    if str(check_digit) == str_value[-1]:
        return True
    else:
        return False


def main():

    cardidfield = sys.argv[1]
    status = ver_check_digit(cardidfield)
    myList = [cardidfield,status]
    myString = ",".join(map(str, myList))
    print "cardid,status"
    print myString


main()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any ideas why this is happening?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 16:06:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338023#M5533</guid>
      <dc:creator>guimilare</dc:creator>
      <dc:date>2018-01-31T16:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338024#M5534</link>
      <description>&lt;P&gt;Yes, the issue here is how Splunk passes data to/from external lookups. Splunk is going to format the data going into the script as a CSV file, and it expects the data being passed back to it to also be formatted as a CSV file. I'd recommend reading through that link above again and also digging into the &lt;CODE&gt;dnslookup&lt;/CODE&gt; script for an example of how to use the python csv library to read the input and write the output back to Splunk.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 16:11:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338024#M5534</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-01-31T16:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338025#M5535</link>
      <description>&lt;P&gt;@guimilare if your requirement is to validate 12 digit number as valid text input you can use JavaScript Regex for the same in SimpleXML itself using &lt;CODE&gt;&amp;lt;eval&amp;gt;&lt;/CODE&gt; tag inside text box &lt;CODE&gt;&amp;lt;change&amp;gt;&lt;/CODE&gt; event handler to &lt;CODE&gt;match()&lt;/CODE&gt; required regex.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;change&amp;gt;
      &amp;lt;eval token="validationResult"&amp;gt;if(match(value, &amp;amp;quot;^[0-9]+$&amp;amp;quot;) AND len($value$)=12, &amp;amp;quot;TRUE&amp;amp;quot;, &amp;amp;quot;FALSE&amp;amp;quot;)&amp;lt;/eval&amp;gt;
    &amp;lt;/change&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/4244i2A4E9BD044BE1D5C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Following is the run anywhere dashboard code for attached screenshot:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Text Numeric Value Validation&amp;lt;/label&amp;gt;
    &amp;lt;fieldset submitButton="false"&amp;gt;
     &amp;lt;input type="text" token="selText"&amp;gt;
       &amp;lt;label&amp;gt;Enter Only Digits&amp;lt;/label&amp;gt;
       &amp;lt;change&amp;gt;
         &amp;lt;eval token="validationResult"&amp;gt;if(match(value, &amp;amp;quot;^[0-9]+$&amp;amp;quot;) AND len($value$)=12, &amp;amp;quot;TRUE&amp;amp;quot;, &amp;amp;quot;FALSE&amp;amp;quot;)&amp;lt;/eval&amp;gt;
       &amp;lt;/change&amp;gt;
     &amp;lt;/input&amp;gt;
   &amp;lt;/fieldset&amp;gt;
   &amp;lt;row&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;table&amp;gt;
         &amp;lt;search&amp;gt;
           &amp;lt;query&amp;gt;| makeresults
  | eval InputText="$selText$"
  | eval InputLength=len("$selText$")
  | eval ValidationResult="$validationResult$" 
  | table InputText InputLength ValidationResult&amp;lt;/query&amp;gt;
           &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
         &amp;lt;/search&amp;gt;
         &amp;lt;option name="count"&amp;gt;20&amp;lt;/option&amp;gt;
         &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
         &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
         &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
         &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
         &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
         &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
       &amp;lt;/table&amp;gt;
     &amp;lt;/panel&amp;gt;
   &amp;lt;/row&amp;gt;
 &amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2018 16:33:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338025#M5535</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-01-31T16:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338026#M5536</link>
      <description>&lt;P&gt;Thanks niketnilay.&lt;/P&gt;

&lt;P&gt;What I needed was to verify the last digit based on the 11 digits before.&lt;BR /&gt;
However, this is a great solution to validate numbers.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 18:42:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338026#M5536</guid>
      <dc:creator>guimilare</dc:creator>
      <dc:date>2018-01-31T18:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338027#M5537</link>
      <description>&lt;P&gt;Thanks elliotproebstel!&lt;/P&gt;

&lt;P&gt;There was an error in my python script.&lt;BR /&gt;
Everything is working now! &lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 18:43:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338027#M5537</guid>
      <dc:creator>guimilare</dc:creator>
      <dc:date>2018-01-31T18:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338028#M5538</link>
      <description>&lt;P&gt;it will be great if you share what error you  have fixed in script&lt;BR /&gt;
Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 18:57:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338028#M5538</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-01-31T18:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a python script from a dashboard?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338029#M5539</link>
      <description>&lt;P&gt;You can create a new command in splunk, is really easy, &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.2/Search/Writeasearchcommand"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.2/Search/Writeasearchcommand&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 19:10:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-can-I-run-a-python-script-from-a-dashboard/m-p/338029#M5539</guid>
      <dc:creator>felipesewaybric</dc:creator>
      <dc:date>2018-01-31T19:10:56Z</dc:date>
    </item>
  </channel>
</rss>

