<?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: Create custom command search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599235#M208612</link>
    <description>&lt;P&gt;You can watch&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/162676"&gt;@techiesid&lt;/a&gt;&amp;nbsp;YouTube channel to create your custom command&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=tTfEv5fLZEs" target="_blank"&gt;https://www.youtube.com/watch?v=tTfEv5fLZEs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;###If it helps. Kindly consider an upvote/accepting as an answer###&lt;/P&gt;</description>
    <pubDate>Wed, 25 May 2022 08:45:47 GMT</pubDate>
    <dc:creator>shivanshu1593</dc:creator>
    <dc:date>2022-05-25T08:45:47Z</dc:date>
    <item>
      <title>How to create custom command search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599218#M208604</link>
      <description>&lt;P&gt;Hi guys, I'm using splunk 8.0&lt;/P&gt;
&lt;P&gt;I want to create a command that can send some infos to another via web or api. I read the Dev page but hard to understand. Do you know some easy script?&lt;/P&gt;
&lt;P&gt;Like I have an table after search&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;a&lt;/TD&gt;
&lt;TD width="25%"&gt;b&lt;/TD&gt;
&lt;TD width="25%"&gt;c&lt;/TD&gt;
&lt;TD width="25%"&gt;Action&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;312&lt;/TD&gt;
&lt;TD width="25%"&gt;213&lt;/TD&gt;
&lt;TD width="25%"&gt;13&lt;/TD&gt;
&lt;TD width="25%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%"&gt;13&lt;/TD&gt;
&lt;TD width="25%"&gt;123&lt;/TD&gt;
&lt;TD width="25%"&gt;46&lt;/TD&gt;
&lt;TD width="25%"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;When Action=1, the script will send info {a:1,b:213,c:13} to another platform, exp: send message to telegram.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;basesearch&amp;gt;
| where action=1
| sendinfo a,b,c&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 06:06:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599218#M208604</guid>
      <dc:creator>lnn2204</dc:creator>
      <dc:date>2022-05-26T06:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom command search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599235#M208612</link>
      <description>&lt;P&gt;You can watch&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/162676"&gt;@techiesid&lt;/a&gt;&amp;nbsp;YouTube channel to create your custom command&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.youtube.com/watch?v=tTfEv5fLZEs" target="_blank"&gt;https://www.youtube.com/watch?v=tTfEv5fLZEs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;###If it helps. Kindly consider an upvote/accepting as an answer###&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 08:45:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599235#M208612</guid>
      <dc:creator>shivanshu1593</dc:creator>
      <dc:date>2022-05-25T08:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom command search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599244#M208613</link>
      <description>&lt;P&gt;One more question, I just want to out the value of fields, then send it. So which command should i create? (Streaming, Generating,&amp;nbsp;&lt;SPAN&gt;Transforming or something else). Because I'm using Streaming and it return error:&amp;nbsp;TypeError at "/opt/splunk/etc/apps/testCommand/bin/splunklib/searchcommands/internals.py", line 573 : 'NoneType' object is not iterable&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is my command:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from __future__ import absolute_import, division, print_function, unicode_literals
import os,sys
import time

from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators
import requests

@Configuration()
class GenerateTextCommand(StreamingCommand):
    def stream(self,records):
        for record in records:
                fields = self.fieldnames
                i = record[fields[0]]
                botURL = "https://api.telegram.org/botTOKEN/sendMessage?chat_id=CHAT_ID&amp;amp;text="+str(i)
                r = requests.get(botURL)

dispatch(GenerateTextCommand, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 25 May 2022 09:58:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599244#M208613</guid>
      <dc:creator>lnn2204</dc:creator>
      <dc:date>2022-05-25T09:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom command search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599340#M208646</link>
      <description>&lt;P&gt;I'm hoping that you have done part of setting up commands.conf and metadata for your custom command. The error that you are seeing down to the fact that the field records is None type, meaning it contains no values and you cannot iterate over None type. Looks like you are not able to pass the data from your SPL to your custom command. Also, you are doing the get request, when you want to send (post) the data instead. Try the following (off the top of my head. May have some bugs that you can fix):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from __future__ import absolute_import, division, print_function, unicode_literals
import os,sys
import time

from splunklib.searchcommands import dispatch, StreamingCommand, Configuration, Option, validators
import requests

@Configuration()
class GenerateTextCommand(StreamingCommand):

    fieldname = Option(
        doc='''
        **Syntax:** **fieldname=***&amp;lt;fieldname&amp;gt;*
        **Description:** Name of the field that will hold the session_key''',
        require=True, validate=validators.Fieldname())

    def stream(self,records):
        for record in records:
                fields = self.fieldnames
                i = record[fields[0]]
                botURL = "https://api.telegram.org/botTOKEN/sendMessage?chat_id=CHAT_ID&amp;amp;text="+str(i)
                r = requests.post(botURL)
                record[self.fieldname] = r
                yield record

dispatch(GenerateTextCommand, sys.argv, sys.stdin, sys.stdout, __name__)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please make sure that you run your custom command in the search&lt;/P&gt;&lt;P&gt;&amp;nbsp;(This will return the value of&amp;nbsp;r. You may wish to format it once it works):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| yourcustomcommand fieldname=events_sent&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;###If it helps, please consider an upvote/accepting as an answer###&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 19:09:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599340#M208646</guid>
      <dc:creator>shivanshu1593</dc:creator>
      <dc:date>2022-05-25T19:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create custom command search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599361#M208651</link>
      <description>&lt;P&gt;Thank you, because it's&amp;nbsp; streaming command, so i need to but things back to the result. And I found the way &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 02:40:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-create-custom-command-search/m-p/599361#M208651</guid>
      <dc:creator>lnn2204</dc:creator>
      <dc:date>2022-05-26T02:40:56Z</dc:date>
    </item>
  </channel>
</rss>

