<?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: How to Extract Mac Address Field from Cisco Mac Address Notification Traps in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33696#M7178</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Your regex looks a bit complex, and also there are 2 &lt;CODE&gt;\s+&lt;/CODE&gt; as the first parts of the field you wish to extract. Also, there is the possibility that A-F may occur in other places than where you specified. Finally, your regex is not anchoring to any particular point in the event, so you could get strange results.&lt;/P&gt;

&lt;P&gt;You could try it as a &lt;CODE&gt;rex&lt;/CODE&gt; extraction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search | rex "Hex-STRING:[\sa-fA-F0-9]{7}(?&amp;lt;my_MAC&amp;gt;[\sa-fA-F0-9]{17})"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or in props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype] 
EXTRACT-cisco_MAC = Hex-STRING:[\sa-fA-F0-9]{7}(?&amp;lt;my_MAC&amp;gt;[\sa-fA-F0-9]{17})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
    <pubDate>Tue, 24 Apr 2012 08:42:31 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2012-04-24T08:42:31Z</dc:date>
    <item>
      <title>How to Extract Mac Address Field from Cisco Mac Address Notification Traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33695#M7177</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am trying to extract the mac address from the following snmp trap.  The mac address is embedded in the Hex-STRING.  I want to skip over the first two octets after 'Hex-STRING' and use the following 6 octets.  The first two: 02 00, can be diffrent depending on which switch is sending the snmp trap.&lt;/P&gt;

&lt;P&gt;In this case, the MAC address that I would like to capture is:&lt;BR /&gt;
91 08 00 11 19 D3.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2012-04-23 13:08:11 test-switch [192.18.foo.foo] (via UDP: [192.18.foo.foo]:55287) TRAP, SNMP v1, community blah    SNMPv2-SMI::enterprises.9.9.215.2 Enterprise Specific Trap (1) Uptime: 384 days, 23:02:38.16    SNMPv2-SMI::enterprises.9.9.215.1.1.8.1.2.0 = Hex-STRING: 02 00 91 08 00 11 19 D3 35 00 12 00
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The following REX Does NOT give me what I want:&lt;BR /&gt;
(?i).*? (?P&lt;FIELD&gt;\s+\s+\d+\s+[a-f0-9]+\s+[a-f0-9]+\s+\d+\s+[a-f0-9]+)\s+\d+\s+\d+&lt;/FIELD&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2012 20:32:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33695#M7177</guid>
      <dc:creator>lim23</dc:creator>
      <dc:date>2012-04-23T20:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to Extract Mac Address Field from Cisco Mac Address Notification Traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33696#M7178</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Your regex looks a bit complex, and also there are 2 &lt;CODE&gt;\s+&lt;/CODE&gt; as the first parts of the field you wish to extract. Also, there is the possibility that A-F may occur in other places than where you specified. Finally, your regex is not anchoring to any particular point in the event, so you could get strange results.&lt;/P&gt;

&lt;P&gt;You could try it as a &lt;CODE&gt;rex&lt;/CODE&gt; extraction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search | rex "Hex-STRING:[\sa-fA-F0-9]{7}(?&amp;lt;my_MAC&amp;gt;[\sa-fA-F0-9]{17})"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or in props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype] 
EXTRACT-cisco_MAC = Hex-STRING:[\sa-fA-F0-9]{7}(?&amp;lt;my_MAC&amp;gt;[\sa-fA-F0-9]{17})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2012 08:42:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33696#M7178</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-04-24T08:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to Extract Mac Address Field from Cisco Mac Address Notification Traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33697#M7179</link>
      <description>&lt;P&gt;Thanks for your response Kristian.  I used your regex to build a little table to parse out the Cisco mac notification snmp-trap.&lt;/P&gt;

&lt;P&gt;The 12 byte hex string has the following information in it.&lt;/P&gt;

&lt;P&gt;first byte = operation (01 for added and 02 for removed mac address from its arp tables)&lt;BR /&gt;
second+third byte = VLan (In HEX)&lt;BR /&gt;
fourth-ninth byte = MAC Address&lt;BR /&gt;
tenth-eleventh byte = Switch Interface (In HEX)&lt;BR /&gt;
twelfth byte = operation (never seen this byte used)&lt;/P&gt;

&lt;P&gt;Here is what I did with your help.&lt;/P&gt;

&lt;P&gt;my_search | rex "Hex-STRING:(?&lt;ACTION1&gt;[\sa-fA-F0-9]{3})(?&lt;VLAN_HEX&gt;[\sa-fA-F0-9]{6})(?&lt;MAC_ADDRESS&gt;[\sa-fA-F0-9]{18})(?&lt;PORT_HEX&gt;[\sa-fA-F0-9]{6})" | rex "(?i)(?P&lt;SWITCH&gt;[^ ]+)\s+(?:\[[^\n\[]*){2}" | eval ACTION2=replace(ACTION1,"01","Added") | eval ACTION=replace(ACTION2,"02","Removed") | eval VLAN1=replace(VLAN_HEX,"\s","") | eval PORT1=replace(PORT_HEX,"\s","") | eval PORT=tonumber(PORT1, 16) | eval VLAN=tonumber(VLAN1, 16) | table _time, MAC_ADDRESS, ACTION, VLAN, PORT, SWITCH&lt;/SWITCH&gt;&lt;/PORT_HEX&gt;&lt;/MAC_ADDRESS&gt;&lt;/VLAN_HEX&gt;&lt;/ACTION1&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:43:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33697#M7179</guid>
      <dc:creator>lim23</dc:creator>
      <dc:date>2020-09-28T11:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Extract Mac Address Field from Cisco Mac Address Notification Traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33698#M7180</link>
      <description>&lt;P&gt;Good that it worked for you. Perhaps you could tidy it up a little more by not including the whitespace in the fields you extract, i.e. do;&lt;BR /&gt;
&lt;CODE&gt;Hex-String:\s(?&lt;ACTION&gt;\d\d)\s+(?&lt;VLAN_HEX&gt;[a-fA-F0-9]{5})\s etc etc&lt;/VLAN_HEX&gt;&lt;/ACTION&gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Anyway, please mark the question as answered a/o upvote if your problem was solved. Thanks.&lt;/P&gt;

&lt;P&gt;/kristian&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2012 07:08:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33698#M7180</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-04-25T07:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to Extract Mac Address Field from Cisco Mac Address Notification Traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33699#M7181</link>
      <description>&lt;P&gt;Thanks,  I have included my search and rex, in case anyone out there is looking to use Splunk for real time end user tracking.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2012 20:30:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33699#M7181</guid>
      <dc:creator>lim23</dc:creator>
      <dc:date>2012-04-25T20:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to Extract Mac Address Field from Cisco Mac Address Notification Traps</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33700#M7182</link>
      <description>&lt;P&gt;Please mark as answered and/or upvote if your problem was solved, thanks.&lt;/P&gt;

&lt;P&gt;/kristian&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2012 07:02:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-Extract-Mac-Address-Field-from-Cisco-Mac-Address/m-p/33700#M7182</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-04-26T07:02:36Z</dc:date>
    </item>
  </channel>
</rss>

