<?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: Generating .csv-Lookups from XML-File in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106869#M6035</link>
    <description>&lt;P&gt;I happened to work this out for someone else yesterday. What you really want is "lookup file contains the results of the last non-empty job run, right? So basically, you include in the lookup the time of the run (or of the data set or whatever). In mine below, I just take it as the job run time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval jobtime=now() | inputlookup append=true mylookup | sort 0 - jobtime | streamstats max(jobtime) as latestjobtime | head (jobtime==latestjobtime) null=t | fields - latestjobtime | outputlookup mylookup
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now the trick is that the part of the search before &lt;CODE&gt;eval&lt;/CODE&gt; (the &lt;CODE&gt;...&lt;/CODE&gt;) needs to either return the last valid set, or else no results at all. So if you have a daily upload, and you run your base search from -1d@d to @d each day, that should work fine.&lt;/P&gt;</description>
    <pubDate>Sat, 19 Oct 2013 17:40:34 GMT</pubDate>
    <dc:creator>gkanapathy</dc:creator>
    <dc:date>2013-10-19T17:40:34Z</dc:date>
    <item>
      <title>Generating .csv-Lookups from XML-File</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106868#M6034</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'd like to use Splunk itself to to generate a .csv-lookupfile to enrich one of my data sources. The data for this lookup comes from an XML-file that is undergoing several changes per week.&lt;/P&gt;

&lt;P&gt;Now I want to automate this as good as possible and thought about the following solution:&lt;/P&gt;

&lt;P&gt;a) Configure Splunk to monitor a folder in which I'd copy the new XML-file once it has undergone one or more changes. The sourcetype for that file is configured to see every line of that XML-file as a new event.&lt;/P&gt;

&lt;P&gt;b) Use a schedules saved search (I already finished the searchstring) to filter down and process the events from the XML-file and generate a new lookupfile (overwrite the old one) with the | outputlookup-command.&lt;/P&gt;

&lt;P&gt;My problem is that I somehow have to differentiate in the scheduled search to only use the newest data from the XML-file. Let's say I'd run a scheduled search every day for the last 24 hours and there was no new XML-file uploaded - outputlook would overwrite the .csv-file with an empty one. And in case I'd upload two new XML files per day, I'd end up with an .csv-file having double entries.&lt;/P&gt;

&lt;P&gt;Someone has an idea how to solve this problem?&lt;/P&gt;

&lt;P&gt;Regards,&lt;/P&gt;

&lt;P&gt;Leo&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2013 14:16:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106868#M6034</guid>
      <dc:creator>lrudolph</dc:creator>
      <dc:date>2013-10-19T14:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Generating .csv-Lookups from XML-File</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106869#M6035</link>
      <description>&lt;P&gt;I happened to work this out for someone else yesterday. What you really want is "lookup file contains the results of the last non-empty job run, right? So basically, you include in the lookup the time of the run (or of the data set or whatever). In mine below, I just take it as the job run time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval jobtime=now() | inputlookup append=true mylookup | sort 0 - jobtime | streamstats max(jobtime) as latestjobtime | head (jobtime==latestjobtime) null=t | fields - latestjobtime | outputlookup mylookup
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now the trick is that the part of the search before &lt;CODE&gt;eval&lt;/CODE&gt; (the &lt;CODE&gt;...&lt;/CODE&gt;) needs to either return the last valid set, or else no results at all. So if you have a daily upload, and you run your base search from -1d@d to @d each day, that should work fine.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Oct 2013 17:40:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106869#M6035</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-10-19T17:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Generating .csv-Lookups from XML-File</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106870#M6036</link>
      <description>&lt;P&gt;Hm, sounds logical but doesn't work quite yet. I modified my searchstring so it now looks like this:&lt;/P&gt;

&lt;P&gt;sourcetype=xml_input "Service" | eval hostname=substr(name, 1, len(name)-25) | rex field=hostname "^(?&lt;CITY&gt;[^-]+)" | eval jobtime=now() |  sort - jobtime | streamstats max(jobtime) as latestjobtime | head (jobtime==latestjobtime) | fields - latestjobtime | table id hostname city | rename id AS AreaId | outputlookup id_lookup.csv&lt;/CITY&gt;&lt;/P&gt;

&lt;P&gt;If I run it over a time period in which I have not uploaded new data, the lookupfile "id_lookup.csv" gets overwritten with an empy file. I'd like to avoid this.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:01:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106870#M6036</guid>
      <dc:creator>lrudolph</dc:creator>
      <dc:date>2020-09-28T15:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Generating .csv-Lookups from XML-File</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106871#M6037</link>
      <description>&lt;P&gt;Looks to me like you left out the part about inputlookup. Also, would recommend you do your table, rename, and other field manipulations before adding eval jobtime, etc.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2013 09:59:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106871#M6037</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2013-10-21T09:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Generating .csv-Lookups from XML-File</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106872#M6038</link>
      <description>&lt;P&gt;Ah! Thanks for this comment. I think I know solved it:&lt;/P&gt;

&lt;P&gt;sourcetype=xml_input "Service" | eval hostname=substr(name, 1, len(name)-25) | rex field=hostname "^(?&lt;CITY&gt;[^-]+)" | table id hostname city | rename id AS AreaId | eval jobtime=now() | inputlookup append=true id_lookup.csv | sort - jobtime | streamstats max(jobtime) as latestjobtime | head (jobtime==latestjobtime) | fields - latestjobtime | outputlookup id_lookup.csv&lt;/CITY&gt;&lt;/P&gt;

&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 15:01:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Generating-csv-Lookups-from-XML-File/m-p/106872#M6038</guid>
      <dc:creator>lrudolph</dc:creator>
      <dc:date>2020-09-28T15:01:37Z</dc:date>
    </item>
  </channel>
</rss>

