<?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: Using REX where unique data is behind the required string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190211#M54766</link>
    <description>&lt;P&gt;As an aside, @richgalloway is correct, you don't need the preceding P, since it's basically ignored. You also don't need the additional parentheses around the part following the PID matching group.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Aug 2014 15:47:09 GMT</pubDate>
    <dc:creator>aweitzman</dc:creator>
    <dc:date>2014-08-21T15:47:09Z</dc:date>
    <item>
      <title>Using REX where unique data is behind the required string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190206#M54761</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;I am quite new to Splunk and REX.&lt;/P&gt;

&lt;P&gt;I am using the SNMP modular input app to poll one of my servers for multiple things.  One value  I poll for is the RAM used for each process.  This is doing a full walk on the MIB I have provided and returns a long event which includes all the running processes.  Below is an extract of the event (there are no lone breaks):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;SNMPv2-SMI::mib-2."25.4.2.1.2.1064" = "ext4-dio-unwrit" SNMPv2-SMI::mib-2."25.4.2.1.2.1065" = "kworker/9:2" SNMPv2-SMI::mib-2."25.4.2.1.2.1070" = "VpnMonitor" SNMPv2-SMI::mib-2."25.4.2.1.2.1081" = "kworker/10:2" SNMPv2-SMI::mib-2."25.4.2.1.2.1113" = "sshd" SNMPv2-SMI::mib-2."25.4.2.1.2.1115" = "rsyslogd"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Each process has a unique PID, but this will change with every reboot.  I need to use the above to extract the PID of a specific number of processes, then use that value to run another query to get its memory utilisation.  I haven't yet figured out how I will do that either but one step at a time...&lt;/P&gt;

&lt;P&gt;Using the above example, I am trying to extract the PID for rsyslogd.  The PID is the final 4 digits in the long number beforehand, however that number is always preceeded with the same set of numbers of 25.4.2.1.2.&lt;/P&gt;

&lt;P&gt;I have run a selection of REX options but because 25.4.2.1.2. is repeated so many times in the event, the return is greedy and either grabs the 1st or last depending on my expression.  I can't get the REX to take in to account that I need the 4 digits after 25.4.2.1.2. but only its followed by " = "rsyslogd"&lt;/P&gt;

&lt;P&gt;An example of my expression is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search | rex "25.4.2.1.2.(?P&amp;lt;PID&amp;gt;\d{4})(\"\s=\s\"rsyslogd)" | table PID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have tried many variations along the lines of the above but it will always ignore the following text.&lt;/P&gt;

&lt;P&gt;Can anyone offer any suggestions for how I can get it to find my unique value?&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 21 Aug 2014 14:51:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190206#M54761</guid>
      <dc:creator>PhilAndreotti</dc:creator>
      <dc:date>2014-08-21T14:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using REX where unique data is behind the required string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190207#M54762</link>
      <description>&lt;P&gt;Your rex expression worked fine for me on regexr.com using your sample data.  Have you tried escaping the dots or using &lt;CODE&gt;?&amp;lt;PID&amp;gt;&lt;/CODE&gt; instead of &lt;CODE&gt;?P&amp;lt;PID&amp;gt;&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:16:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190207#M54762</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-08-21T15:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using REX where unique data is behind the required string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190208#M54763</link>
      <description>&lt;P&gt;Your rex works perfectly for me. Are you certain that this string is in your raw data?&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="SNMPv2-SMI::mib-2.\"25.4.2.1.2.1064\" = \"ext4-dio-unwrit\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1065\" = \"kworker/9:2\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1070\" = \"VpnMonitor\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1081\" = \"kworker/10:2\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1113\" = \"sshd\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1115\" = \"rsyslogd\"" | rex "25.4.2.1.2.(?P&amp;lt;PID&amp;gt;\d{4})(\"\s=\s\"rsyslogd)" | table PID&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:19:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190208#M54763</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-08-21T15:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using REX where unique data is behind the required string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190209#M54764</link>
      <description>&lt;P&gt;Thank you both for the replies.&lt;/P&gt;

&lt;P&gt;richgalloway - I have escaped the dots and tried without the P - no difference.&lt;/P&gt;

&lt;P&gt;aweitzman - perhaps you are getting the correct result because the example I gave is a subset.  If you ran the same while searching for the process"sshd" - i.e. NOT the last process in the list I don't think it would work.  I have an extract of probably 100+ processes running on my Linux server.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:30:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190209#M54764</guid>
      <dc:creator>PhilAndreotti</dc:creator>
      <dc:date>2014-08-21T15:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using REX where unique data is behind the required string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190210#M54765</link>
      <description>&lt;P&gt;I tried that, it works fine, too.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| gentimes start=-1 | eval _raw="SNMPv2-SMI::mib-2.\"25.4.2.1.2.1064\" = \"ext4-dio-unwrit\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1065\" = \"kworker/9:2\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1070\" = \"VpnMonitor\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1081\" = \"kworker/10:2\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1113\" = \"sshd\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1115\" = \"rsyslogd\" SNMPv2-SMI::mib-2.\"25.4.2.1.2.1116\" = \"sshd\"" | rex "25.4.2.1.2.(?&amp;lt;PID&amp;gt;\d{4})(\"\s=\s\"rsyslogd)" | table PID&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Do you get 1116 when you cut/paste the above query? I correctly get 1115.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:37:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190210#M54765</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-08-21T15:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using REX where unique data is behind the required string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190211#M54766</link>
      <description>&lt;P&gt;As an aside, @richgalloway is correct, you don't need the preceding P, since it's basically ignored. You also don't need the additional parentheses around the part following the PID matching group.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Aug 2014 15:47:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190211#M54766</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-08-21T15:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using REX where unique data is behind the required string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190212#M54767</link>
      <description>&lt;P&gt;Slightly embarrassing but user error - it is working!  Thank you both for your answers.&lt;/P&gt;

&lt;P&gt;I was looking for a specific PID relating to a specific process.  While I was working on this, the server was rebooted (not by me) and as such, the PID I was looking for changed so I was looking for the wrong answer.&lt;/P&gt;

&lt;P&gt;I was definitely getting the wrong answer for several hours - it was probably only the last 20mins before I submitted the question on the forum that I was actually getting the right answer.  On a brighter note, I learned a lot through the process!&lt;/P&gt;

&lt;P&gt;Thanks again for your help - it did help as it made me double check everything.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 07:17:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-REX-where-unique-data-is-behind-the-required-string/m-p/190212#M54767</guid>
      <dc:creator>PhilAndreotti</dc:creator>
      <dc:date>2014-08-22T07:17:39Z</dc:date>
    </item>
  </channel>
</rss>

