<?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: Lookup Table and Regex in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Lookup-Table-and-Regex/m-p/459623#M129712</link>
    <description>&lt;P&gt;As stated by @DalJeanis, if the assumptions are correct, then your search would look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your_basic_search
| rex field = _raw ".+finance\S+\;GET\s(?&amp;lt;URL&amp;gt;\/\w+\/\w+\/\w+\/)"
| rex field = URL "\/\w+\/\w+\/(?&amp;lt;TransactionName&amp;gt;\w+)
| rex field = _raw ".+\;(?&amp;lt;avg_Responsetime&amp;gt;\d+)\;\"\-\""
|  eval TransactionName=upper(TransactionName)
| stats count by TransactionName as Hits
| table URL TransactionName avg_Responsetime Hits
| outputlookup foo.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: If your search heads are clustered, then use &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Outputlookup"&gt;outputlookup&lt;/A&gt; command, otherwise use &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Outputcsv"&gt;outputcsv&lt;/A&gt; command.&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jul 2018 15:06:48 GMT</pubDate>
    <dc:creator>sudosplunk</dc:creator>
    <dc:date>2018-07-25T15:06:48Z</dc:date>
    <item>
      <title>Lookup Table and Regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Lookup-Table-and-Regex/m-p/459621#M129710</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;
I need some help with lookup table combined with regular expressions.&lt;/P&gt;

&lt;P&gt;I have the an apache log file which looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;*25/Jul/2018:10:17:30.999;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/balanceviewer/ HTTP/1.0;200;111;12421;15yjLFielsdx424u6S7Y136sHTvfpFWP;-;+dF15erUTMPMyqlLYEUugh7j7eJjtKtub5pRai/Z3ckGx0AkbJnDI3PPwHrwzRdk+bVwDNNU0ducGu0IZ8cKVA==;host/195 CFNetwork/651.5.4 Darwin/11.7.1;1493;"-";
25/Jul/2018:10:17:30.999;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/balanceviewer/ HTTP/1.0;200;111;12421;18y3LF87lsdx4643AS7Y13ZsHT4bpFWP;-;+dF15erUTMPMyqlLYEUugh7j7eJjtKtub5pRai/Z3ckGx0AkbJnDI3PPwHrwzRdk+bVwDNNU0ducGu0IZ8cKVA==;host/195 CFNetwork/651.5.4 Darwin/11.7.1;1493;"-";
25/Jul/2018:10:17:30.999;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/balanceviewer/ HTTP/1.0;200;111;12421;17yh6F9tlsd34A43AS7Y19ZseevbpFWP;-;+dF15erUTMPMyqlLYEUugh7j7eJjtKtub5pRai/Z3ckGx0AkbJnDI3PPwHrwzRdk+bVwDNNU0ducGu0IZ8cKVA==;host/195 CFNetwork/651.5.4 Darwin/11.7.1;1493;"-";
25/Jul/2018:10:17:30.997;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/getyoursettings/N1vAO8zgb38oYh6MogfhwQ HTTP/1.0;200;111;1111;155eUDXOjDT/G2QzEf2WvZulbirv4Fw2;https://host.temp.nl/finance/us/pay/transactions.html?account=A1vAO8zgbR8oghPMogfhwQ;n0hJVF5icTKeT+zO/5Xhs+Ul/QHwyqsrngxzEC6hPmU1RNpc5zF/51fSh07kfpHzp96YMt0bZiwZj76ze+N9GA==;Mozilla/5.0 (Linux; Android 7.0; HUAWEI NXT-L29 Build/HUAWEINXT-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Crosswalk/19.49.514.5 Mobile Safari/537.36;2362;"-";
25/Jul/2018:10:17:30.997;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/getyoursettings/Q2vAO8zg5R8oY4PMogfhwQ HTTP/1.0;200;111;1111;155gUDX4jDT/G2rzEf2WvZulbirv4Fwt;https://host.temp.nl/finance/us/pay/transactions.html?account=s1vAO8zgbs8oYhPMogfhwQ;n0hJVF5icTKeT+zO/5Xhs+Ul/QHwyqsrngxzEC6hPmU1RNpc5zF/51fSh07kfpHzp96YMt0bZiwZj76ze+N9GA==;Mozilla/5.0 (Linux; Android 7.0; HUAWEI NXT-L29 Build/HUAWEINXT-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Crosswalk/19.49.514.5 Mobile Safari/537.36;2362;"-";
25/Jul/2018:10:17:30.997;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/getyoursettings/A3vAO8zg5R8o4hPMogfhwQ HTTP/1.0;200;111;1111;155gUDXOfDT/G2QzEf2WvZulbirv4Ftv;https://host.temp.nl/finance/us/pay/transactions.html?account=f1vAO8zdbR8oYhPMogfhwQ;n0hJVF5icTKeT+zO/5Xhs+Ul/QHwyqsrngxzEC6hPmU1RNpc5zF/51fSh07kfpHzp96YMt0bZiwZj76ze+N9GA==;Mozilla/5.0 (Linux; Android 7.0; HUAWEI NXT-L29 Build/HUAWEINXT-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Crosswalk/19.49.514.5 Mobile Safari/537.36;2362;"-";*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to use the lookup and regex command to get an output based on the URL hit:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;URL,TransactionName, avg_Responsetime,Hits
 /api/balances/balanceviewer/,BALANCEVIEWER,1493,3
/api/balances/getyoursettings,GETYOURSETTINGS,2362,3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does anyone know how I can make this kind of a table/report with splunk?&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;

&lt;P&gt;Amit&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 08:30:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Lookup-Table-and-Regex/m-p/459621#M129710</guid>
      <dc:creator>aksampat81</dc:creator>
      <dc:date>2018-07-25T08:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup Table and Regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Lookup-Table-and-Regex/m-p/459622#M129711</link>
      <description>&lt;P&gt;We've made some assumptions here that you will need to review with your real data.  See the second second for your code and a discussion.  &lt;/P&gt;

&lt;P&gt;The first section is just a test data generator:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval myRaw="25/Jul/2018:10:17:30.999;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/balanceviewer/ HTTP/1.0;200;111;12421;15yjLFielsdx424u6S7Y136sHTvfpFWP;-;+dF15erUTMPMyqlLYEUugh7j7eJjtKtub5pRai/Z3ckGx0AkbJnDI3PPwHrwzRdk+bVwDNNU0ducGu0IZ8cKVA==;host/195 CFNetwork/651.5.4 Darwin/11.7.1;1493;\"-\";!!!!25/Jul/2018:10:17:30.999;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/balanceviewer/ HTTP/1.0;200;111;12421;18y3LF87lsdx4643AS7Y13ZsHT4bpFWP;-;+dF15erUTMPMyqlLYEUugh7j7eJjtKtub5pRai/Z3ckGx0AkbJnDI3PPwHrwzRdk+bVwDNNU0ducGu0IZ8cKVA==;host/195 CFNetwork/651.5.4 Darwin/11.7.1;1493;\"-\";!!!!25/Jul/2018:10:17:30.999;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/balanceviewer/ HTTP/1.0;200;111;12421;17yh6F9tlsd34A43AS7Y19ZseevbpFWP;-;+dF15erUTMPMyqlLYEUugh7j7eJjtKtub5pRai/Z3ckGx0AkbJnDI3PPwHrwzRdk+bVwDNNU0ducGu0IZ8cKVA==;host/195 CFNetwork/651.5.4 Darwin/11.7.1;1493;\"-\";!!!!25/Jul/2018:10:17:30.997;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/getyoursettings/N1vAO8zgb38oYh6MogfhwQ HTTP/1.0;200;111;1111;155eUDXOjDT/G2QzEf2WvZulbirv4Fw2;https://host.temp.nl/finance/us/pay/transactions.html?account=A1vAO8zgbR8oghPMogfhwQ;n0hJVF5icTKeT+zO/5Xhs+Ul/QHwyqsrngxzEC6hPmU1RNpc5zF/51fSh07kfpHzp96YMt0bZiwZj76ze+N9GA==;Mozilla/5.0 (Linux; Android 7.0; HUAWEI NXT-L29 Build/HUAWEINXT-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Crosswalk/19.49.514.5 Mobile Safari/537.36;2362;\"-\";!!!!25/Jul/2018:10:17:30.997;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/getyoursettings/Q2vAO8zg5R8oY4PMogfhwQ HTTP/1.0;200;111;1111;155gUDX4jDT/G2rzEf2WvZulbirv4Fwt;https://host.temp.nl/finance/us/pay/transactions.html?account=s1vAO8zgbs8oYhPMogfhwQ;n0hJVF5icTKeT+zO/5Xhs+Ul/QHwyqsrngxzEC6hPmU1RNpc5zF/51fSh07kfpHzp96YMt0bZiwZj76ze+N9GA==;Mozilla/5.0 (Linux; Android 7.0; HUAWEI NXT-L29 Build/HUAWEINXT-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Crosswalk/19.49.514.5 Mobile Safari/537.36;2362;\"-\";!!!!25/Jul/2018:10:17:30.997;2.2.2.255;temp-prod.nl;https://finance.host.nl;GET /api/balances/getyoursettings/A3vAO8zg5R8o4hPMogfhwQ HTTP/1.0;200;111;1111;155gUDXOfDT/G2QzEf2WvZulbirv4Ftv;https://host.temp.nl/finance/us/pay/transactions.html?account=f1vAO8zdbR8oYhPMogfhwQ;n0hJVF5icTKeT+zO/5Xhs+Ul/QHwyqsrngxzEC6hPmU1RNpc5zF/51fSh07kfpHzp96YMt0bZiwZj76ze+N9GA==;Mozilla/5.0 (Linux; Android 7.0; HUAWEI NXT-L29 Build/HUAWEINXT-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Crosswalk/19.49.514.5 Mobile Safari/537.36;2362;\"-\";"
| makemv delim="!!!!" myRaw
| mvexpand myRaw
| rename myRaw as _raw
| rename COMMENT as "The above just enters your data"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, here's the actual code and assumptions made:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rename COMMENT as "Here we assume the URL must start with /api and is all lower case plus slashes."
| rex "(?&amp;lt;URL&amp;gt;/api[a-z0-9//]*)" 

| rename COMMENT as "Here we assume the transaction name is whatever is between the last two slashes, and must be converted to upper case."
| rex field=URL "[//](?&amp;lt;TransactionName&amp;gt;[a-z0-9]*)[//]$"
| eval TransactionName=upper(TransactionName)

| rename COMMENT as "Here we assume the response time is a numeric entry between the two semicolons that are third and second from the end of each record."
| rex ";(?&amp;lt;Resp&amp;gt;\d+);[^;]*;$"

| rename COMMENT as "Now we calculate the count and average for each combination."
| stats avg(Resp) as AvgResp count as Hits by URL TransactionName
| eval AvgResp=round(AvgResp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;If you need help chatting about regular expressions, please get connected up to our Slack channel.  There is a #regex subchannel where you can get quick iterations on minor changes to assumptions like the above. &lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 14:41:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Lookup-Table-and-Regex/m-p/459622#M129711</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-07-25T14:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Lookup Table and Regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Lookup-Table-and-Regex/m-p/459623#M129712</link>
      <description>&lt;P&gt;As stated by @DalJeanis, if the assumptions are correct, then your search would look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Your_basic_search
| rex field = _raw ".+finance\S+\;GET\s(?&amp;lt;URL&amp;gt;\/\w+\/\w+\/\w+\/)"
| rex field = URL "\/\w+\/\w+\/(?&amp;lt;TransactionName&amp;gt;\w+)
| rex field = _raw ".+\;(?&amp;lt;avg_Responsetime&amp;gt;\d+)\;\"\-\""
|  eval TransactionName=upper(TransactionName)
| stats count by TransactionName as Hits
| table URL TransactionName avg_Responsetime Hits
| outputlookup foo.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: If your search heads are clustered, then use &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Outputlookup"&gt;outputlookup&lt;/A&gt; command, otherwise use &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.2/SearchReference/Outputcsv"&gt;outputcsv&lt;/A&gt; command.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 15:06:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Lookup-Table-and-Regex/m-p/459623#M129712</guid>
      <dc:creator>sudosplunk</dc:creator>
      <dc:date>2018-07-25T15:06:48Z</dc:date>
    </item>
  </channel>
</rss>

