<?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 Help needed with Custom Command in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65112#M897</link>
    <description>&lt;P&gt;Hi there, I have just started working on Splunk and is totally new to Python.&lt;BR /&gt;
For my situation, I would like to create a custom command just like any other commands(e.g. Top/ Rare), I would like my custom command to display the current system time.&lt;/P&gt;

&lt;P&gt;here is my Python script:&lt;BR /&gt;
CurrentTime.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import time;

localtime = time.localtime(time.time())
print "Local current time :", localtime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And here is my commands.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[CurrentTime]
type = python
filename = CurrentTime.py
streaming = false
generating = false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not sure if the above codes are correct, but if they were functional, what should I do to actually get it to display the current system time on my Splunk app?&lt;/P&gt;</description>
    <pubDate>Tue, 17 Sep 2013 03:20:23 GMT</pubDate>
    <dc:creator>bloodstrife</dc:creator>
    <dc:date>2013-09-17T03:20:23Z</dc:date>
    <item>
      <title>Help needed with Custom Command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65112#M897</link>
      <description>&lt;P&gt;Hi there, I have just started working on Splunk and is totally new to Python.&lt;BR /&gt;
For my situation, I would like to create a custom command just like any other commands(e.g. Top/ Rare), I would like my custom command to display the current system time.&lt;/P&gt;

&lt;P&gt;here is my Python script:&lt;BR /&gt;
CurrentTime.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import time;

localtime = time.localtime(time.time())
print "Local current time :", localtime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And here is my commands.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[CurrentTime]
type = python
filename = CurrentTime.py
streaming = false
generating = false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not sure if the above codes are correct, but if they were functional, what should I do to actually get it to display the current system time on my Splunk app?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2013 03:20:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65112#M897</guid>
      <dc:creator>bloodstrife</dc:creator>
      <dc:date>2013-09-17T03:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with Custom Command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65113#M898</link>
      <description>&lt;P&gt;It is output by a screen if I make modifications in this way. &lt;BR /&gt;
Please learn it to see a document and a sample. I think that it is simple and can refer to &lt;STRONG&gt;uniq.py&lt;/STRONG&gt; of the search.&lt;/P&gt;

&lt;P&gt;CurrentTime.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import time
from splunk.Intersplunk import getOrganizedResults, outputResults, getKeywordsAndOptions
results, dummy, settings = getOrganizedResults()

#localtime = time.localtime(time.time())
localtime = time.asctime(time.localtime())

results = []
event = {}
event['message'] = "Local current time :" + localtime
results.append(event)
outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/sample_11.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2013 07:20:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65113#M898</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2013-09-17T07:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with Custom Command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65114#M899</link>
      <description>&lt;P&gt;Hi bloodstrife&lt;/P&gt;

&lt;P&gt;after you put your script into &lt;CODE&gt;etc/apps/YourApp/bin&lt;/CODE&gt; folder and placed the &lt;CODE&gt;commands.conf&lt;/CODE&gt; into &lt;CODE&gt;etc/apps/YourApp/default&lt;/CODE&gt; folder, restart Splunk and switch to YourApp. There simply enter the following search command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | CurrentTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and this will run your command.&lt;/P&gt;

&lt;P&gt;But I tested your script and the output is none. Here is a quick and dirty rewrite to get it printing current time in csv like output that Splunk likes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import time;
mytime = time.localtime(time.time())
print "my_year ,my_mon ,my_mday ,my_hour ,my_min ,my_sec ,my_wday ,my_yday" 
print "%s, %s, %s ,%s ,%s ,%s ,%s ,%s" % (mytime.tm_year, mytime.tm_mon, mytime.tm_mday, mytime.tm_hour, mytime.tm_min, mytime.tm_sec, mytime.tm_wday, mytime.tm_yday)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm pretty sure there are better ways to do this in python &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
But nevertheless hope that helps ....&lt;/P&gt;

&lt;P&gt;Cheers, MuS&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2013 07:24:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65114#M899</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2013-09-17T07:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with Custom Command</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65115#M900</link>
      <description>&lt;P&gt;Or you could just do this to get the exact time the event was processed (different for each event)&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval current_time=time()&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Or this to get the time the search was kicked off:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| eval current_time=now()&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2013 12:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Help-needed-with-Custom-Command/m-p/65115#M900</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-09-17T12:23:43Z</dc:date>
    </item>
  </channel>
</rss>

