<?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: How to write a Scripted input directly to lookup in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590772#M103483</link>
    <description>&lt;P&gt;You don't need the Add-on Builder to do that.&amp;nbsp; You already have a Python script so just replace the part the indexes the data with a few lines of code to write it to ../lookups/mylookup.csv (or whatever you want to call the file).&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2022 00:15:01 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2022-03-25T00:15:01Z</dc:date>
    <item>
      <title>How to write a Scripted input directly to lookup?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590744#M103474</link>
      <description>&lt;P&gt;I have a requirement where I need to make an API call and write the data to a lookup file that I can use locally. The API calls returns data in a CSV format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Previously, I used the Ad-on builder to create a python script that would make make the API request and index this data. However, I have a new requirement to skip the index entirely and write to a local lookup on the search head. The Ad-on builder wont help as it only shows examples of how to write the data to an index.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 13:47:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590744#M103474</guid>
      <dc:creator>amat</dc:creator>
      <dc:date>2022-03-25T13:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted input directly to lookup</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590755#M103476</link>
      <description>&lt;P&gt;The input itself (at least with the input functionality) cannot write to a lookup.&lt;/P&gt;&lt;P&gt;You need a script that manipulates lookup using REST API. It has nothing to do with indexing.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 20:21:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590755#M103476</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-03-24T20:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Scripted input directly to lookup</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590772#M103483</link>
      <description>&lt;P&gt;You don't need the Add-on Builder to do that.&amp;nbsp; You already have a Python script so just replace the part the indexes the data with a few lines of code to write it to ../lookups/mylookup.csv (or whatever you want to call the file).&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 00:15:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590772#M103483</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-03-25T00:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Scripted input directly to lookup</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590788#M103486</link>
      <description>&lt;P&gt;interesting. So should I use the Ad-On builder but at the very end of the script have it overwrite the lookup table?&amp;nbsp;&lt;/P&gt;&lt;P&gt;For background, the reason why I used the ad-on builder was because I was getting really confused with the authentication and safely pulling the API keys out of the passwords.conf. So the ad-on builder really helped with retrieval of secrets.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you suggesting overwriting the lookup using the REST endpoint? If so, how do i do that without authenticating ? I see a lot of the curl commands require you to pass admin credentials; however, i dont want to hardcode any creds in my script.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 02:55:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590788#M103486</guid>
      <dc:creator>amat</dc:creator>
      <dc:date>2022-03-25T02:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Scripted input directly to lookup</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590847#M103505</link>
      <description>&lt;P&gt;AoB helps with the hard parts.&amp;nbsp; Writing data to a disk file is not a hard part.&amp;nbsp; Because scripted inputs run on the Splunk server, they have access to the file system there.&amp;nbsp; Just use normal pythonic methods for opening and writing to a text file.&amp;nbsp; You don't need REST.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 12:17:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/590847#M103505</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-03-25T12:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a Scripted input directly to lookup?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/591026#M103534</link>
      <description>&lt;P&gt;I would suggest using a custom Python command with the help of Splunklib as input is not recommended on the search head. Here is some parts of the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;commands.conf&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[lookupgen]
filename = lookup_gen.py
chunked = true&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;lookup_gen.py&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import os
import sys
import csv

from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators

HEADERS = ['ip','mac','hostname']   # change this as per your need
LOOKUP_NAME = 'my_lookup.csv'


@Configuration()
class LookupGen(GeneratingCommand):
    def get_data_from_your_data_source(self):
        pass # write your logic to fetch the data here

    def update_lookup_file(self, lookup_file_path, data):
        with open(lookup_file_path, 'w') as f:
            csv_writer = csv.writer(f)
            csv_writer.writerow(HEADERS)
            csv_writer.writerows(data)

 
    def generate(self):
        data = self.get_data_from_your_data_source()
        lookup_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
                                            os.path.join('lookups', LOOKUP_NAME))
        self.update_lookup_file(lookup_path, data)

 
dispatch(LookupGen, 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;You will need to add this python file into your bin folder along with splunklib (Python SDK for Splunk) -&amp;nbsp;&lt;A href="https://pypi.org/project/splunklib/" target="_blank" rel="noopener"&gt;https://pypi.org/project/splunklib/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/splunk/splunk-sdk-python" target="_blank" rel="noopener"&gt;https://github.com/splunk/splunk-sdk-python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And you can schedule a search/report using this command at regular internal.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 06:33:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-write-a-Scripted-input-directly-to-lookup/m-p/591026#M103534</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2022-03-28T06:33:13Z</dc:date>
    </item>
  </channel>
</rss>

