<?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: Using DB CONNECT to query data but the value of &amp;quot;where condition&amp;quot; is variable in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312659#M93616</link>
    <description>&lt;P&gt;The only way you could do this, is to create a custom script, where you can handle your SQL. But you have to manage the SQL handling by yourself.&lt;BR /&gt;
Normally i'm using a rising column for DB Input or i'm reading the whole table.&lt;/P&gt;

&lt;P&gt;The Documentation is here:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Writeasearchcommand"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Writeasearchcommand&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Example:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Customsearchcommandshape"&gt;https://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Customsearchcommandshape&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Here a stub i'm using, stored in &lt;CODE&gt;etc/apps/&amp;lt;app&amp;gt;/bin&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/python

__doc__ = '''

    Ein Konverter fuer die base36 Konversion im Splunk Stream

'''

import sys, splunk.Intersplunk

#splunk_home = os.getenv('SPLUNK_HOME')
#if not splunk_home:
#    raise ConfigError('Environment variable SPLUNK_HOME must be set. Run: source ~/bin/setSplunkEnv')

# Start script
#***************************************************************
if __name__ == '__main__':

    #Get the arguments from search
    #(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)

    #if len(sys.argv) != 2:
    #        splunk.Intersplunk.parseError("Usage | ctmbase36 __EXECUTE__ &amp;lt;field&amp;gt;")

    #thefield=sys.argv[1]

    reader=splunk.Intersplunk.readResults(None,None,True)

    for row in reader:
        #print "Inputvalue"
        value=int(row['ORDERNO'])
        #print value
        # Here your SQL Function
        convert = base36encode(value)
        #print convert

        # Set a value    
        row['orderid'] = convert

    splunk.Intersplunk.outputResults(reader)

#
# EOF
#
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To call this script then within the SQL you need a &lt;CODE&gt;commands.conf&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#
# Commands.conf for the base36 convert
#

[ctmbase36]
type = python
filename = ctm_base36.py
local = true
stderr_dest = message
supports_getinfo = false

#
# EOF
#
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;in the SPL the call would be like this then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval ORDERNO=00a2doz
| ctmbase36 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Apr 2018 10:19:33 GMT</pubDate>
    <dc:creator>Elsurion</dc:creator>
    <dc:date>2018-04-04T10:19:33Z</dc:date>
    <item>
      <title>Using DB CONNECT to query data but the value of "where condition" is variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312656#M93613</link>
      <description>&lt;P&gt;We want to query data from DB Using DB CONNECT but the value of "where condition" is variable.&lt;/P&gt;

&lt;P&gt;For example,the value of PID is variable as the sql below, we wanna pass the value of input box on the dashboard to sql below&lt;BR /&gt;
which used by DB CONNECT&lt;/P&gt;

&lt;P&gt;SELECT A,B,C FROM TABLE1 WHERE PID='1001002003'&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 07:31:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312656#M93613</guid>
      <dc:creator>kavana</dc:creator>
      <dc:date>2018-04-04T07:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using DB CONNECT to query data but the value of "where condition" is variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312657#M93614</link>
      <description>&lt;P&gt;You can use the SPL for the DBX for that Usecase:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbxquery query="select jobno, orderno, applgroup, nodegrp, failcount, order_time from cmr_ajf_jobs where endrun &amp;gt; '20180404000000'" connection="testsystem" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you feeding the SPL via Dashboard then you can use the &lt;CODE&gt;$value$&lt;/CODE&gt; substitution in the search.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 08:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312657#M93614</guid>
      <dc:creator>Elsurion</dc:creator>
      <dc:date>2018-04-04T08:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using DB CONNECT to query data but the value of "where condition" is variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312658#M93615</link>
      <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;

&lt;P&gt;We've used SPL for the DBX before, but it was too slow so that we are looking for a new way.&lt;/P&gt;

&lt;P&gt;So, it is no way for DB CONNECT to pass variable value to SQL, isn't it?&lt;/P&gt;

&lt;P&gt;So, we have to use the SPL for the DBX for that usecase, right?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Apr 2018 09:58:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312658#M93615</guid>
      <dc:creator>kavana</dc:creator>
      <dc:date>2018-04-04T09:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using DB CONNECT to query data but the value of "where condition" is variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312659#M93616</link>
      <description>&lt;P&gt;The only way you could do this, is to create a custom script, where you can handle your SQL. But you have to manage the SQL handling by yourself.&lt;BR /&gt;
Normally i'm using a rising column for DB Input or i'm reading the whole table.&lt;/P&gt;

&lt;P&gt;The Documentation is here:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Writeasearchcommand"&gt;http://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Writeasearchcommand&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Example:&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Customsearchcommandshape"&gt;https://docs.splunk.com/Documentation/Splunk/7.0.3/Search/Customsearchcommandshape&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Here a stub i'm using, stored in &lt;CODE&gt;etc/apps/&amp;lt;app&amp;gt;/bin&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/python

__doc__ = '''

    Ein Konverter fuer die base36 Konversion im Splunk Stream

'''

import sys, splunk.Intersplunk

#splunk_home = os.getenv('SPLUNK_HOME')
#if not splunk_home:
#    raise ConfigError('Environment variable SPLUNK_HOME must be set. Run: source ~/bin/setSplunkEnv')

# Start script
#***************************************************************
if __name__ == '__main__':

    #Get the arguments from search
    #(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)

    #if len(sys.argv) != 2:
    #        splunk.Intersplunk.parseError("Usage | ctmbase36 __EXECUTE__ &amp;lt;field&amp;gt;")

    #thefield=sys.argv[1]

    reader=splunk.Intersplunk.readResults(None,None,True)

    for row in reader:
        #print "Inputvalue"
        value=int(row['ORDERNO'])
        #print value
        # Here your SQL Function
        convert = base36encode(value)
        #print convert

        # Set a value    
        row['orderid'] = convert

    splunk.Intersplunk.outputResults(reader)

#
# EOF
#
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To call this script then within the SQL you need a &lt;CODE&gt;commands.conf&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#
# Commands.conf for the base36 convert
#

[ctmbase36]
type = python
filename = ctm_base36.py
local = true
stderr_dest = message
supports_getinfo = false

#
# EOF
#
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;in the SPL the call would be like this then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval ORDERNO=00a2doz
| ctmbase36 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Apr 2018 10:19:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-DB-CONNECT-to-query-data-but-the-value-of-quot-where/m-p/312659#M93616</guid>
      <dc:creator>Elsurion</dc:creator>
      <dc:date>2018-04-04T10:19:33Z</dc:date>
    </item>
  </channel>
</rss>

