<?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: Is it possible to force CSV header in export job with output_mode=csv and no matching events? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482499#M82681</link>
    <description>&lt;P&gt;Thank you for the answer!&lt;/P&gt;

&lt;P&gt;For me, your approach works, but isn't particularly scalable. I have ~ 50 queries that change frequently, and maintaining the column list in two points in the query is a bit fragile. The subsearch is also unbounded in time, so can be expensive on large indexes.&lt;/P&gt;

&lt;P&gt;My current solution is to detect if no data was returned, then submit the query to the parsing endpoint, and extracting the fields from the &lt;CODE&gt;reportsSearch&lt;/CODE&gt; key. It's also fairly fragile (it depends on the last command being a &lt;CODE&gt;table&lt;/CODE&gt;), but it avoids the penalty of resubmitting the search.&lt;/P&gt;

&lt;P&gt;Ideally Splunk would adjust things so that an &lt;CODE&gt;output_mode=csv&lt;/CODE&gt; would return the headers always, or at least expose an option for it.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Nov 2019 14:56:58 GMT</pubDate>
    <dc:creator>iroddis</dc:creator>
    <dc:date>2019-11-14T14:56:58Z</dc:date>
    <item>
      <title>Is it possible to force CSV header in export job with output_mode=csv and no matching events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482497#M82679</link>
      <description>&lt;P&gt;Using the cURL/API to submit an &lt;CODE&gt;output_mode=csv&lt;/CODE&gt; export job like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search .... | table fieldA fieldB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will give a CSV payload if there are any matching events, otherwise, it will return no data at all, not even a header.&lt;/P&gt;

&lt;P&gt;Is it possible to force the header, even if there are no matching events? I know Splunk knows what the header should be, since &lt;CODE&gt;output_mode=xml&lt;/CODE&gt; will return the expected fields in a &lt;CODE&gt;&amp;lt;fieldOrder&amp;gt;&lt;/CODE&gt; set.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Nov 2019 16:17:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482497#M82679</guid>
      <dc:creator>iroddis</dc:creator>
      <dc:date>2019-11-12T16:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to force CSV header in export job with output_mode=csv and no matching events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482498#M82680</link>
      <description>&lt;P&gt;Why not add a fake event at the end of each search, to never return an empty table ?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search ....  | append [ | stats count | eval fieldA="null", fieldB="null" | fields - count ]  | table fieldA fieldB
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Nov 2019 00:32:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482498#M82680</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2019-11-14T00:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to force CSV header in export job with output_mode=csv and no matching events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482499#M82681</link>
      <description>&lt;P&gt;Thank you for the answer!&lt;/P&gt;

&lt;P&gt;For me, your approach works, but isn't particularly scalable. I have ~ 50 queries that change frequently, and maintaining the column list in two points in the query is a bit fragile. The subsearch is also unbounded in time, so can be expensive on large indexes.&lt;/P&gt;

&lt;P&gt;My current solution is to detect if no data was returned, then submit the query to the parsing endpoint, and extracting the fields from the &lt;CODE&gt;reportsSearch&lt;/CODE&gt; key. It's also fairly fragile (it depends on the last command being a &lt;CODE&gt;table&lt;/CODE&gt;), but it avoids the penalty of resubmitting the search.&lt;/P&gt;

&lt;P&gt;Ideally Splunk would adjust things so that an &lt;CODE&gt;output_mode=csv&lt;/CODE&gt; would return the headers always, or at least expose an option for it.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 14:56:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482499#M82681</guid>
      <dc:creator>iroddis</dc:creator>
      <dc:date>2019-11-14T14:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to force CSV header in export job with output_mode=csv and no matching events?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482500#M82682</link>
      <description>&lt;P&gt;Understood, if you have a support contract, you can still open an enhancement request case on the product, to request outputlookup options.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 16:03:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Is-it-possible-to-force-CSV-header-in-export-job-with-output/m-p/482500#M82682</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2019-11-14T16:03:27Z</dc:date>
    </item>
  </channel>
</rss>

