<?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 whois command: Problem with passing keyword to function [Python] in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Custom-whois-command-Problem-with-passing-keyword-to-function/m-p/73128#M1024</link>
    <description>&lt;P&gt;Disclaimer, I haven't given your code above a test but my thoughts are...&lt;/P&gt;

&lt;P&gt;Firstly, without looking at the intersplunk stuff again I couldn't say how it arrives but its probably safer to cast it as a string, do something like &lt;CODE&gt;host=str(host2)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Secondly, I always find logging helpful in these situations, look up the Python logging module or just write to a file to keep a record of your variable values so you can see where things are going wrong.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.python.org/2/library/logging.html"&gt;http://docs.python.org/2/library/logging.html&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Dec 2012 11:33:45 GMT</pubDate>
    <dc:creator>Drainy</dc:creator>
    <dc:date>2012-12-26T11:33:45Z</dc:date>
    <item>
      <title>Custom whois command: Problem with passing keyword to function [Python]</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-whois-command-Problem-with-passing-keyword-to-function/m-p/73127#M1023</link>
      <description>&lt;P&gt;Hello Splunk Community,&lt;/P&gt;

&lt;P&gt;This is my small whois command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.Intersplunk as si
import logging
import py_whois

def whois():
    host2,options = si.getKeywordsAndOptions()
    #host = "amazon.it"
    flags = 0
    nic_client = py_whois.NICClient()
    results = []
    result = nic_client.whois_lookup(None, host2, flags)
    lines = result.split('\n')
    for line in lines:
        results.append({"Whois Information for " + host : line})
    results.append({"Whois Information for " + host : line})
    #results.append({"hostname" : host2})
    return results

try: 
    results = whois()
except:
    import traceback
    stack =  traceback.format_exc()
    results = splunk.Intersplunk.generateErrorResults("Error : Traceback: " + str(stack))
si.outputResults( results )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've got the code for the py_whois.NICClient class from here:&lt;BR /&gt;&lt;BR /&gt;
&lt;A href="http://code.activestate.com/recipes/577364-whois-client/"&gt;http://code.activestate.com/recipes/577364-whois-client/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Now, when I hardcode the host-string (i.e. amazon.it in the example above), the script works fine, but it fails when I pass the host-string I got as a keywords (getKeywordsAnd..). Do I need to convert the variable to another format before it can be passed to this function?&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;commands.conf&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;
[swhois]&lt;BR /&gt;&lt;BR /&gt;
filename = swhois.py&lt;/P&gt;

&lt;P&gt;Many thanks!&lt;/P&gt;

&lt;P&gt;Best regards,&lt;BR /&gt;
Stephan&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2012 09:44:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-whois-command-Problem-with-passing-keyword-to-function/m-p/73127#M1023</guid>
      <dc:creator>stephan_berger</dc:creator>
      <dc:date>2012-12-26T09:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Custom whois command: Problem with passing keyword to function [Python]</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-whois-command-Problem-with-passing-keyword-to-function/m-p/73128#M1024</link>
      <description>&lt;P&gt;Disclaimer, I haven't given your code above a test but my thoughts are...&lt;/P&gt;

&lt;P&gt;Firstly, without looking at the intersplunk stuff again I couldn't say how it arrives but its probably safer to cast it as a string, do something like &lt;CODE&gt;host=str(host2)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Secondly, I always find logging helpful in these situations, look up the Python logging module or just write to a file to keep a record of your variable values so you can see where things are going wrong.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.python.org/2/library/logging.html"&gt;http://docs.python.org/2/library/logging.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2012 11:33:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-whois-command-Problem-with-passing-keyword-to-function/m-p/73128#M1024</guid>
      <dc:creator>Drainy</dc:creator>
      <dc:date>2012-12-26T11:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Custom whois command: Problem with passing keyword to function [Python]</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Custom-whois-command-Problem-with-passing-keyword-to-function/m-p/73129#M1025</link>
      <description>&lt;P&gt;Thanks for your help, Drainy, but I found the answer while looking at this thread:&lt;BR /&gt;&lt;BR /&gt;
&lt;A href="http://splunk-base.splunk.com/answers/3935/debugging-custom-splunk-search-commands"&gt;Debugging custom splunk search command&lt;/A&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;args, kwargs = splunk.Intersplunk.getKeywordsAndOptions()
..
parameter1 = args[0]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;ARGS is an array. I thought I have tested this as well.. nevermind, thanks again.&lt;/P&gt;

&lt;P&gt;Best regards,&lt;BR /&gt;
Stephan&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2012 12:23:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Custom-whois-command-Problem-with-passing-keyword-to-function/m-p/73129#M1025</guid>
      <dc:creator>stephan_berger</dc:creator>
      <dc:date>2012-12-26T12:23:07Z</dc:date>
    </item>
  </channel>
</rss>

