<?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: Creating fields from trap in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91045#M23422</link>
    <description>&lt;P&gt;I guess you're giving me something extra to read about. Thank you for that. I'll try to make something out of it, and see how I could use it. Again, thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Apr 2011 20:26:51 GMT</pubDate>
    <dc:creator>jduraes</dc:creator>
    <dc:date>2011-04-28T20:26:51Z</dc:date>
    <item>
      <title>Creating fields from trap</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91041#M23418</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I may be going at this in the completely wrong way, but I'm looking at extracting information from traps sent by a system, and then using them to generate reports.&lt;/P&gt;

&lt;P&gt;So I have this trap:&lt;/P&gt;

&lt;P&gt;SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.1230.2.7.4.3   SNMPv2-SMI::enterprises.1230.2.7.4.10.4 = INTEGER: 6    SNMPv2-SMI::enterprises.1230.2.7.4.10.5 = STRING: "neptune"&lt;/P&gt;

&lt;P&gt;The system is picking up the fields ok, like "SNMPv2-SMI::enterprises.1230.2.7.4.10.5", but then its content is "STRING: \"neptune\"".&lt;/P&gt;

&lt;P&gt;I'm looking at removing the word "STRING: ", both quotes (""), and just keeping the rest (neptune), preferably somehow placing that into a field named "planet".&lt;/P&gt;

&lt;P&gt;My report will then look at displaying how many times each planet was observed, sort of thing.&lt;/P&gt;

&lt;P&gt;Is this possible? Does this reasoning make any sense? I was thinking about using rex for this, but I must be way off the mark because nothing seems to work for me... &lt;/P&gt;

&lt;P&gt;I was trying:    | rex field=_raw "STRING: \"(?&lt;PLANET&gt;.*)\""&lt;/PLANET&gt;&lt;/P&gt;

&lt;P&gt;Help, please?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2011 19:09:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91041#M23418</guid>
      <dc:creator>jduraes</dc:creator>
      <dc:date>2011-04-28T19:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating fields from trap</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91042#M23419</link>
      <description>&lt;P&gt;Something like this should work  ** (change to your sourcetype)&lt;/P&gt;

&lt;P&gt;sourcetype="?????" | head 100 | rex "(?im)STRING:\s\\"(?P&lt;PLANET&gt;.+?)\\"" | top 50 PLANET&lt;/PLANET&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2011 19:50:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91042#M23419</guid>
      <dc:creator>JSapienza</dc:creator>
      <dc:date>2011-04-28T19:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating fields from trap</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91043#M23420</link>
      <description>&lt;P&gt;Thank you. I guess I'm more of a beginner than I thought. The key was in specifying the sourcetype; I was just casting the | rex... on its own. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2011 19:56:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91043#M23420</guid>
      <dc:creator>jduraes</dc:creator>
      <dc:date>2011-04-28T19:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating fields from trap</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91044#M23421</link>
      <description>&lt;P&gt;Getting rid of the quotes makes it a little messy, at least if you want to allow for the possibility of spaces within the quoted string.&lt;/P&gt;

&lt;P&gt;Here's one way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#transforms.conf
[snmp-fields]
REGEX = \s(\S+)\s*=\s*\w+: (")?((?&amp;lt;=")[^"]+|(\S+))
FORMAT = $1::$3

#props.conf
[snmp]
KV_MODE = none
REPORT-snmp = snmp-fields
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;
The trick is to consume the opening quotation mark first so that it isn't part of the capture group (i.e., the extracted field).&lt;/P&gt;

&lt;P&gt;Then, within the capture group, use &lt;A href="http://www.regular-expressions.info/lookaround.html"&gt;negative lookbehind&lt;/A&gt; to determine whether you're matching inside a quoted section (match up to the end-quote), or just matching a block of non-whitespace.&lt;/P&gt;

&lt;P&gt;Another way would be to create two separate transforms -- one for quoted string values and one for integer and other non-string types.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2011 19:57:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91044#M23421</guid>
      <dc:creator>southeringtonp</dc:creator>
      <dc:date>2011-04-28T19:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Creating fields from trap</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91045#M23422</link>
      <description>&lt;P&gt;I guess you're giving me something extra to read about. Thank you for that. I'll try to make something out of it, and see how I could use it. Again, thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2011 20:26:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91045#M23422</guid>
      <dc:creator>jduraes</dc:creator>
      <dc:date>2011-04-28T20:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating fields from trap</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91046#M23423</link>
      <description>&lt;P&gt;If the trapserver is net-snmp, you can use -OQ option to remove the type (STRINGS in this case).&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2011 22:26:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-fields-from-trap/m-p/91046#M23423</guid>
      <dc:creator>rasingh</dc:creator>
      <dc:date>2011-08-23T22:26:20Z</dc:date>
    </item>
  </channel>
</rss>

