<?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 Custom Command Help in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439495#M125019</link>
    <description>&lt;P&gt;All, &lt;/P&gt;

&lt;P&gt;I am no developer and burned a couple hours on the making custom commands docs and conf sessions and feel like I am no closer. So hoping someone can give me a basic template to wrap this in? &lt;/P&gt;

&lt;P&gt;Basically I have this script (works on python 2 and 3 unchanged). I'd like to pass my custom command a value which is a securitycode and return the value from my script. How can I get this done? Anyone have a template? &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python3.5
import sys


hsh = [
     (1 , 'Known Violators'),
     (2 , 'Blocked Country'),
     (4 , 'Browser Integrity Check'),
     (8 , 'Known Violator User Agent'),
    (16 , 'Rate Limited'),
    (32 , 'Known Violator Honeypot Access'),
    (64 , 'Referrer Block'),
   (128 , 'Session Length Exceeded'),
   (256 , 'Pages Per Session Exceeded'),
   (512 , 'Bad User Agents'),
  (1024 , 'Aggregator User Agents'),
  (2048 , 'Filtered IP'),
  (4096 , 'JavaScript Not Loaded'),
  (8192 , 'JavaScript Check Failed'),
 (16384 , 'Identifier Validation Error'),
 (32768 , 'Known Violator Automation Tool'),
 (65536 , 'Form Spam Submission'),
(131072 , 'Unverified Signature'),
(262144 , 'IP Pinning Failure'),
(524288 , 'Invalid JavaScript Test Results'),
(1048576 , 'Organization Block'),
(2097152 , 'Known Violator Data Center'),
(4194304 , 'ACL User Agent'),
(8388608 , 'ACL ID'),
(16777216 , 'ACL Header'),
(134217728 , 'ACL Extension'),
(268435456 , 'Missing Unique ID'),
(536870912 , 'Requests Per Minute')
]

def help():
    print("threat_extract.py threat_number")

if __name__ == '__main__':
    if len(sys.argv) != 2:
        help()
        exit()

    threat_number = int(sys.argv[1])

    print(','.join([v for k, v in hsh if k &amp;amp; threat_number]))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Oct 2018 21:24:20 GMT</pubDate>
    <dc:creator>daniel333</dc:creator>
    <dc:date>2018-10-19T21:24:20Z</dc:date>
    <item>
      <title>Custom Command Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439495#M125019</link>
      <description>&lt;P&gt;All, &lt;/P&gt;

&lt;P&gt;I am no developer and burned a couple hours on the making custom commands docs and conf sessions and feel like I am no closer. So hoping someone can give me a basic template to wrap this in? &lt;/P&gt;

&lt;P&gt;Basically I have this script (works on python 2 and 3 unchanged). I'd like to pass my custom command a value which is a securitycode and return the value from my script. How can I get this done? Anyone have a template? &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/env python3.5
import sys


hsh = [
     (1 , 'Known Violators'),
     (2 , 'Blocked Country'),
     (4 , 'Browser Integrity Check'),
     (8 , 'Known Violator User Agent'),
    (16 , 'Rate Limited'),
    (32 , 'Known Violator Honeypot Access'),
    (64 , 'Referrer Block'),
   (128 , 'Session Length Exceeded'),
   (256 , 'Pages Per Session Exceeded'),
   (512 , 'Bad User Agents'),
  (1024 , 'Aggregator User Agents'),
  (2048 , 'Filtered IP'),
  (4096 , 'JavaScript Not Loaded'),
  (8192 , 'JavaScript Check Failed'),
 (16384 , 'Identifier Validation Error'),
 (32768 , 'Known Violator Automation Tool'),
 (65536 , 'Form Spam Submission'),
(131072 , 'Unverified Signature'),
(262144 , 'IP Pinning Failure'),
(524288 , 'Invalid JavaScript Test Results'),
(1048576 , 'Organization Block'),
(2097152 , 'Known Violator Data Center'),
(4194304 , 'ACL User Agent'),
(8388608 , 'ACL ID'),
(16777216 , 'ACL Header'),
(134217728 , 'ACL Extension'),
(268435456 , 'Missing Unique ID'),
(536870912 , 'Requests Per Minute')
]

def help():
    print("threat_extract.py threat_number")

if __name__ == '__main__':
    if len(sys.argv) != 2:
        help()
        exit()

    threat_number = int(sys.argv[1])

    print(','.join([v for k, v in hsh if k &amp;amp; threat_number]))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 21:24:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439495#M125019</guid>
      <dc:creator>daniel333</dc:creator>
      <dc:date>2018-10-19T21:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Command Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439496#M125020</link>
      <description>&lt;P&gt;To not answer your question, you could probably just use a lookup if this is all the command is going to do. &lt;/P&gt;

&lt;P&gt;To ask a question, how would you envision this custom command working exactly?  How would you want to use it in a search exactly?  &lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 01:25:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439496#M125020</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2018-10-20T01:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Command Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439497#M125021</link>
      <description>&lt;P&gt;Thanks for replying. &lt;/P&gt;

&lt;P&gt;I am kinda forcing this as a custom command as a learning opportunity, but hitting a wall. never done one, so thought I would use the excuse. &lt;/P&gt;

&lt;P&gt;I am expecting to pass a value (a numeric field) from the log called vendorerrorcode. &lt;/P&gt;

&lt;P&gt;mysearch | mycustomcommand vendorerrorcode &lt;/P&gt;

&lt;P&gt;and get a returned field an array of all the possible error codes returned from the script above. &lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 14:02:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439497#M125021</guid>
      <dc:creator>daniel333</dc:creator>
      <dc:date>2018-10-23T14:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Command Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439498#M125022</link>
      <description>&lt;P&gt;i haven't done with v2 of the sdk yet, but this does seem like a nice one to practice with.  I may play with this when i have some free time.  But for now, here are some thoughts.&lt;/P&gt;

&lt;P&gt;At a high-level, i believe you'll want to create an app, put the sdk in the app, create your script in the app and create the commands.conf file to tell splunk about your script.  &lt;/P&gt;

&lt;P&gt;There is this &lt;A href="https://github.com/splunk/splunk-sdk-python/tree/master/examples/searchcommands_app"&gt;searchcommands_app example&lt;/A&gt; in Splunk SDK repository.  It has most of what you need to get started i think.&lt;/P&gt;

&lt;P&gt;Then there is &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEU2#basicexample"&gt;this section&lt;/A&gt; somewhere on the splunk dev site that explains what to do with that example app - where to put it and what else to put in there (some of the sdk bits).&lt;/P&gt;

&lt;P&gt;For the code itself, i would probably base it off of &lt;A href="https://github.com/splunk/splunk-sdk-python/blob/master/examples/searchcommands_app/package/bin/countmatches.py"&gt;this example&lt;/A&gt; in that app.  It shows you how to make a streaming command, which basically what you're trying to do.  &lt;/P&gt;

&lt;P&gt;Not sure if any of that will help or just provide you more useless hours of reading.  But if i do get a chance to play with this or if anyone else here has done something similar, hopefully we can get you a working example to get started with.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Oct 2018 00:27:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439498#M125022</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2018-10-31T00:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Command Help</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439499#M125023</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Let's go step by step. (check the reference link, if you get stuck somewhere)&lt;BR /&gt;
Ref 1 - &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/7.0.5/Search/Customcommandlocation" target="_blank"&gt;http://docs.splunk.com/Documentation/SplunkCloud/7.0.5/Search/Customcommandlocation&lt;/A&gt;&lt;BR /&gt;
Ref 2 - &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.0/Search/Customsearchcommandshape" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.0/Search/Customsearchcommandshape&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;As you are doing this for learning, I wont provide all the details. Following details will get you going.&lt;BR /&gt;
If you need more help, you are welcome.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Download Splunk Python SDK from the link, and copy 'splunklib' folder - &lt;A href="http://dev.splunk.com/python" target="_blank"&gt;http://dev.splunk.com/python&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Create an app with 'bin' and other required folders and paste the 'splunklib' folder inside bin folder&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Create &lt;CODE&gt;commands.conf&lt;/CODE&gt; file inside default folder, with following configuration.&lt;/P&gt;

&lt;P&gt;[command_name]&lt;BR /&gt;
filename = python_file.py&lt;BR /&gt;
supports_rawargs = true&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Now create a  &lt;CODE&gt;python_file.py&lt;/CODE&gt;inside 'bin' directory created at step 2. As details provided in reference 2, use the pre-defined code to capture command argument, process the results and push the new results/modified data by command back to Splunk.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;If  &lt;CODE&gt;python_file.py&lt;/CODE&gt; is using any other python file, than you have to import it with full path.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;&lt;EM&gt;if this helps, don't forget to accept this answer.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;cheers &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:52:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Custom-Command-Help/m-p/439499#M125023</guid>
      <dc:creator>gaurav_maniar</dc:creator>
      <dc:date>2020-09-29T21:52:44Z</dc:date>
    </item>
  </channel>
</rss>

