<?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: extracting fields &amp; values from SQL logs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116733#M183902</link>
    <description>&lt;P&gt;Here is an example of what I went with.  Not that I am proud of it. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| history events=true | head 1 | fields - * _* | eval sql="INSERT INTO `table1` (`field1`, `field2`, `field3`, `field4`) VALUES (0, 1, NULL, 'sometext')"
| rex field=sql "INSERT INTO\s+.(?&amp;lt;tablename&amp;gt;\w+).\s+(?&amp;lt;FIELDS&amp;gt;\(.*\))\s+VALUES\s+(?&amp;lt;VALUES&amp;gt;\(.*\))"
| rex mode=sed field=FIELDS "s/`//g"
| rex mode=sed field=VALUES "s/'//g"
| rex max_match=0 field=FIELDS "\(?(?&amp;lt;MVFIELD&amp;gt;[\s\S]+?)[,)]\s?"
| rex max_match=0 field=VALUES "\(?(?&amp;lt;MVVALUE&amp;gt;[\s\S]+?)[,)]\s?"
| eval _raw=mvzip(MVFIELD,MVVALUE,"=") | extract
| fields - _raw FIELDS VALUES MVFIELD MVVALUE
| table *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 11 Apr 2014 20:32:26 GMT</pubDate>
    <dc:creator>rizzo75</dc:creator>
    <dc:date>2014-04-11T20:32:26Z</dc:date>
    <item>
      <title>extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116724#M183893</link>
      <description>&lt;P&gt;I am trying to extract field names and values from SQL logs.&lt;BR /&gt;
IE - “… INSERT INTO &lt;CODE&gt;table&lt;/CODE&gt; (&lt;CODE&gt;COL1&lt;/CODE&gt;, &lt;CODE&gt;COL2&lt;/CODE&gt;) VALUES ('VAL1', 'VAL2’)”&lt;/P&gt;

&lt;P&gt;COL1=VAL1&lt;BR /&gt;
COL2=VAL2&lt;/P&gt;

&lt;P&gt;Any thoughts on how to do this?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Joe&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2014 15:31:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116724#M183893</guid>
      <dc:creator>rizzo75</dc:creator>
      <dc:date>2014-04-02T15:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116725#M183894</link>
      <description>&lt;P&gt;Have you attempted to use db connect? &lt;A href="https://apps.splunk.com/app/958/"&gt;https://apps.splunk.com/app/958/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2014 15:56:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116725#M183894</guid>
      <dc:creator>aelliott</dc:creator>
      <dc:date>2014-04-02T15:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116726#M183895</link>
      <description>&lt;P&gt;You &lt;EM&gt;might&lt;/EM&gt; get away with a transforms.conf extraction like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_stanza]
REGEX = (?i)insert\s*into\s*(?&amp;lt;table&amp;gt;\S+)\s*\((?&amp;lt;_KEY_1&amp;gt;\w+)(?:,\s*(?&amp;lt;_KEY_2&amp;gt;\w+))?(?:,\s*(?&amp;lt;_KEY_3&amp;gt;\w+))?(?:,\s*(?&amp;lt;_KEY_4&amp;gt;\w+))?\)\s*values\s*\('(?&amp;lt;_VAL_1&amp;gt;[^']+)'(?:,\s*'(?&amp;lt;_VAL_2&amp;gt;[^']+)')?(?:,\s*'(?&amp;lt;_VAL_4&amp;gt;[^']+)')?(?:,\s*'(?&amp;lt;_VAL_4&amp;gt;[^']+)')?\)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That's for up to four columns, but you probably see how it's expandable to any number. I didn't test this though, but I'm optimistic it might actually work. For a little background, see &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.0.2/Admin/transformsconf"&gt;http://docs.splunk.com/Documentation/Splunk/6.0.2/Admin/transformsconf&lt;/A&gt; (search for "_key_").&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2014 16:33:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116726#M183895</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-02T16:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116727#M183896</link>
      <description>&lt;P&gt;I wish I could.  I do not have access to the DB.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2014 16:34:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116727#M183896</guid>
      <dc:creator>rizzo75</dc:creator>
      <dc:date>2014-04-02T16:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116728#M183897</link>
      <description>&lt;P&gt;Thanks - that is actually what I am doing now.&lt;BR /&gt;
I was hoping to automatically extract the field name and values as this is tedious and static.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Apr 2014 16:35:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116728#M183897</guid>
      <dc:creator>rizzo75</dc:creator>
      <dc:date>2014-04-02T16:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116729#M183898</link>
      <description>&lt;P&gt;This should extract the column names automatically, due to the magic _KEY_x and _VAL_x names.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:18:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116729#M183898</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2020-09-28T16:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116730#M183899</link>
      <description>&lt;P&gt;Ah.  Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2014 18:26:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116730#M183899</guid>
      <dc:creator>rizzo75</dc:creator>
      <dc:date>2014-04-03T18:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116731#M183900</link>
      <description>&lt;P&gt;Does it work? I still didn't get around to actually test my expression &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Apr 2014 20:40:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116731#M183900</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-03T20:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116732#M183901</link>
      <description>&lt;P&gt;I actually did not try it, but it looks like it would work if the number of fields was static.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2014 20:31:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116732#M183901</guid>
      <dc:creator>rizzo75</dc:creator>
      <dc:date>2014-04-11T20:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116733#M183902</link>
      <description>&lt;P&gt;Here is an example of what I went with.  Not that I am proud of it. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| history events=true | head 1 | fields - * _* | eval sql="INSERT INTO `table1` (`field1`, `field2`, `field3`, `field4`) VALUES (0, 1, NULL, 'sometext')"
| rex field=sql "INSERT INTO\s+.(?&amp;lt;tablename&amp;gt;\w+).\s+(?&amp;lt;FIELDS&amp;gt;\(.*\))\s+VALUES\s+(?&amp;lt;VALUES&amp;gt;\(.*\))"
| rex mode=sed field=FIELDS "s/`//g"
| rex mode=sed field=VALUES "s/'//g"
| rex max_match=0 field=FIELDS "\(?(?&amp;lt;MVFIELD&amp;gt;[\s\S]+?)[,)]\s?"
| rex max_match=0 field=VALUES "\(?(?&amp;lt;MVVALUE&amp;gt;[\s\S]+?)[,)]\s?"
| eval _raw=mvzip(MVFIELD,MVVALUE,"=") | extract
| fields - _raw FIELDS VALUES MVFIELD MVVALUE
| table *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Apr 2014 20:32:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116733#M183902</guid>
      <dc:creator>rizzo75</dc:creator>
      <dc:date>2014-04-11T20:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116734#M183903</link>
      <description>&lt;P&gt;You could create one expression with the maximum expected number of fields, they're all marked as optional.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Apr 2014 04:48:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/116734#M183903</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-12T04:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields &amp; values from SQL logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/530029#M183904</link>
      <description>&lt;P&gt;Thank you thank you thank you!&lt;BR /&gt;&lt;BR /&gt;This was exactly what i was after, then i used mvexpand and mvindex with split to split the values to the field&lt;/P&gt;</description>
      <pubDate>Thu, 19 Nov 2020 06:44:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-values-from-SQL-logs/m-p/530029#M183904</guid>
      <dc:creator>geraldcontreras</dc:creator>
      <dc:date>2020-11-19T06:44:50Z</dc:date>
    </item>
  </channel>
</rss>

