<?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 from snmp traps in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234618#M188492</link>
    <description>&lt;P&gt;Hi Brian,&lt;BR /&gt;
from your sample event, it appears that the unwanted string is always &lt;CODE&gt;.'.....'&lt;/CODE&gt;, sometimes followed by .nnn so the simplest is probably removing that from the source events during indexing using SEDCMD for your source (or sourcetype) in props.conf, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::yourlogfile]
SEDCMD-removeUnwantedStuff = s/\.\'[.'1234567890]+//g
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not that this will alter the events before they get indexed, so it will only apply to new events coming in. &lt;BR /&gt;
If you don't want to do that, you can use the rex command at search time, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearch | rex mode=sed ddd "s/\.\'[.'1234567890]+//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this helps.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Aug 2016 18:17:15 GMT</pubDate>
    <dc:creator>s2_splunk</dc:creator>
    <dc:date>2016-08-22T18:17:15Z</dc:date>
    <item>
      <title>Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234616#M188490</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I'm trying to extract key/value data from SNMP trap data logged to my splunk server.  I have snmptrapd running in the background and logging to a file, which splunk is monitoring.  All that is working great.  The data that makes it into splunk looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2016-08-22 12:42:21 10.192.2.110 [UDP: [10.192.2.110]:32771-&amp;gt;[10.10.15.76]]:
sysUpTimeInstance = 80:20:41:00.00  snmpTrapOID.0 = ciscoLwappDot11ClientMIBNotifs.2    cldcClientMacAddress.'......' = d4:b:1a:92:fc:8b    cldcClientWlanProfileName.'......' = SSID   cldcClientEntry.'......'.139 = 10.64.97.246 cldcApMacAddress.'......' = 58:f3:9c:c8:55:20   cldcClientEntry.'......'.139 = 0    cldcClientEntry.'......'.139 = 396
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm trying to use the kv command like this: " ... | kv pairdelim="\t" kvdelim=" = " "which grabs some of the fields, but I think the problem is that there's extra snmp variable data that I need to get rid of.  With the example above I get a key of "cldcClientEntry_________139" and value of "10.64.97.246" but what I want to get is "cldcClientEntry" and value of "10.64.97.246" ... so I think I need some way to stop matching the key as soon as it hits a period, but I'm not quite sure where/how to do that.  Any suggestions?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Brian&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 17:51:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234616#M188490</guid>
      <dc:creator>swannie</dc:creator>
      <dc:date>2016-08-22T17:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234617#M188491</link>
      <description>&lt;P&gt;Try this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| rex mode=sed "s/(\.\'[\.]+\')?(\.\d+)? =/ =/g"
| kv pairdelim="\t" kvdelim=" = "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It worked fine for me based on your sample above (and using several spaces instead of tabs because of the copy and paste):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| fields - _time
| eval _raw = "2016-08-22 12:42:21 10.192.2.110 [UDP: [10.192.2.110]:32771-&amp;gt;[10.10.15.76]]:
 sysUpTimeInstance = 80:20:41:00.00    snmpTrapOID.0 = ciscoLwappDot11ClientMIBNotifs.2    cldcClientMacAddress.'......' = d4:b:1a:92:fc:8b    cldcClientWlanProfileName.'......' = SSID    cldcClientEntry.'......'.139 = 10.64.97.246    cldcApMacAddress.'......' = 58:f3:9c:c8:55:20    cldcClientEntry.'......'.139 = 0    cldcClientEntry.'......'.139 = 396"
| rex mode=sed "s/(\.\'[\.]+\')?(\.\d+)? =/ =/g"
| kv pairdelim="    " kvdelim=" = "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/1732i319CFC0E543D701F/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 18:16:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234617#M188491</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-08-22T18:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234618#M188492</link>
      <description>&lt;P&gt;Hi Brian,&lt;BR /&gt;
from your sample event, it appears that the unwanted string is always &lt;CODE&gt;.'.....'&lt;/CODE&gt;, sometimes followed by .nnn so the simplest is probably removing that from the source events during indexing using SEDCMD for your source (or sourcetype) in props.conf, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[source::yourlogfile]
SEDCMD-removeUnwantedStuff = s/\.\'[.'1234567890]+//g
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Not that this will alter the events before they get indexed, so it will only apply to new events coming in. &lt;BR /&gt;
If you don't want to do that, you can use the rex command at search time, like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearch | rex mode=sed ddd "s/\.\'[.'1234567890]+//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 18:17:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234618#M188492</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2016-08-22T18:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234619#M188493</link>
      <description>&lt;P&gt;Ahh... I didn't think about pre-processing those fields.  I'll have to try it on a few different log entries and see what I need to tweak.  Thanks for your assistance!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 19:15:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234619#M188493</guid>
      <dc:creator>swannie</dc:creator>
      <dc:date>2016-08-22T19:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234620#M188494</link>
      <description>&lt;P&gt;Thanks for the idea, but I might have gave a bad example.  The text following the OID is variable and different (it happened to be the same in this log entry because it was all non-printable characters).&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 19:17:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234620#M188494</guid>
      <dc:creator>swannie</dc:creator>
      <dc:date>2016-08-22T19:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234621#M188495</link>
      <description>&lt;P&gt;Okay, I'm having a problem wrapping my head around the SED command, and the interwebs aren't helping.  Here's another log example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2016-08-22 14:57:08 10.192.2.110 [UDP: [10.192.2.110]:32771-&amp;gt;[10.10.15.76]]:
sysUpTimeInstance = 80:22:55:48.00  snmpTrapOID = ciscoLwappDot11ClientMIBNotifs.2  cldcClientMacAddress.'.*..q.' = e8:2a:ea:c6:71:d6   cldcClientWlanProfileName.'.*..q.' = RAMBLERS   cldcClientEntry.'..*..q' = 10.64.30.36  cldcApMacAddress.'.*..q.' = f0:7f:6:3e:20:30    cldcClientEntry.'..*..q' = 0    cldcClientEntry.'..*..q' = 330
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically, I want to take everything from the first period up to (but not including) the equal sign and trash it.  I tried to modify the original SED script you gave me, but it's not working as expected.  Any thoughts?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 20:00:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234621#M188495</guid>
      <dc:creator>swannie</dc:creator>
      <dc:date>2016-08-22T20:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234622#M188496</link>
      <description>&lt;P&gt;I think I got it .. here's what I settled on:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex mode=sed "s/\.([^\s]+) =/ =/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Aug 2016 20:31:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234622#M188496</guid>
      <dc:creator>swannie</dc:creator>
      <dc:date>2016-08-22T20:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting fields from snmp traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234623#M188497</link>
      <description>&lt;P&gt;Fair enough. Looks like you figured it out how to adjust the RegEx in SED to match any character from the first dot to the next equals sign. &lt;BR /&gt;
You may want to consider removing that extraneous stuff before indexing the data, unless you need those characters for any other search. You could configure SEDCMD in your props.conf to achieve that.&lt;BR /&gt;
Either way works fine, schema on the fly at work! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 22:13:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extracting-fields-from-snmp-traps/m-p/234623#M188497</guid>
      <dc:creator>s2_splunk</dc:creator>
      <dc:date>2016-08-22T22:13:03Z</dc:date>
    </item>
  </channel>
</rss>

