<?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: Parse apache access log  in transforms.conf in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55814#M10912</link>
    <description>&lt;P&gt;Thank you! I probably didn't ask my question properly. Let me try to rephrase my question. When I installed splunk, I can see 2 sourcetypes for common apache log files -- acceess_common and access_combined_cookie. &lt;BR /&gt;
Since my apache log format is coutomized, I have to create the regular expression myself. &lt;BR /&gt;
This part is time consuming and it will be great if I can reuse old transforms.conf.&lt;BR /&gt;
My sample eventdata&lt;/P&gt;

&lt;P&gt;[21/May/2012:11:50:16 -0400] 10.39.208.3 "my-user-id" "libwww-perl/5.77" GET HTTP/1.1 "&lt;A href="http://www.amazon.com" target="_blank"&gt;http://www.amazon.com&lt;/A&gt;" "?search-alias%3Daps&amp;amp;field-keywords=ipad+3&amp;amp;sprefix=ipad%2Caps%2C210" 200 495 0&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 11:50:56 GMT</pubDate>
    <dc:creator>shangshin</dc:creator>
    <dc:date>2020-09-28T11:50:56Z</dc:date>
    <item>
      <title>Parse apache access log  in transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55812#M10910</link>
      <description>&lt;P&gt;I noticed there are 2 default sourcetype for apache log. However, we are using a different format in out apache web server. (see Logformat below). I assume I need to use regular expression in transforms.conf. Is that correct? If yes, where can I see the default sample so I can create the right kv fields in transforms.conf. Thanks!&lt;/P&gt;

&lt;P&gt;%t %h \"%{Proxy-Remote-User}i\" \"%{User-Agent}i\" %m %H \"%U\" \"%q\" %&amp;gt;s %b %T&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2012 18:15:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55812#M10910</guid>
      <dc:creator>shangshin</dc:creator>
      <dc:date>2012-05-18T18:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Parse apache access log  in transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55813#M10911</link>
      <description>&lt;P&gt;I am not sure what you mean by "the default sample."  So here is an example of the configuration files that define a customized sourcetype. You can do this for any sort of input that is in a format that Splunk does not already recognize. I tried to do it for your actual custom log, but I am sure I didn't get it exactly right.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;First, you should create the &lt;STRONG&gt;props.conf&lt;/STRONG&gt; and &lt;STRONG&gt;transforms.conf&lt;/STRONG&gt; files, before setting up your input on the production server. It is best to do this on a test server (you can install Splunk on your PC and use that as a test server), where you can make sure it is working the way you want. Upload a sample of your apache data, too.&lt;/LI&gt;
&lt;LI&gt;I called the new sourcetype &lt;STRONG&gt;apache_custom&lt;/STRONG&gt; in my example. In props.conf, I tell Splunk to do two things: (1) override the host before indexing the data and (2) set up the fields, based on your description above, for use when searching and reporting on the data.&lt;/LI&gt;
&lt;LI&gt;transforms.conf contains the specification for how to do the override and field extraction&lt;/LI&gt;
&lt;LI&gt;Once you are happy with the props.conf and transforms.conf, set up the inputs.conf to actually bring your data into Splunk&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;I show the host override below, but you may not need it. If you don't, delete it and things will be more efficient. But - if your Apache log will contain information from a variety of web hosts, you must have the override to make sure that Splunk assigns the proper host name to each event in the data.&lt;/P&gt;

&lt;P&gt;The apache_custom_fields stanza in transforms.conf is where the field extraction is actually set up. The fields are defined by a regular expression. I hope I got it right, but I might not have, depending on your actual data. I suggest that you take the regular expression below and put it in a regular expression testing tool. (Note the the regular expression is line-wrapped below - there is not actually a newline in the regular expression.) Add a sample of your log file and see if the results make sense. You can try &lt;A href="http://gskinner.com/RegExr/"&gt;http://gskinner.com/RegExr/&lt;/A&gt; but there are others.&lt;/P&gt;

&lt;P&gt;Look in the manuals at the following locations for more details:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Data/Whysourcetypesmatter"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Data/Whysourcetypesmatter&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Data/Createsourcetypes#Edit_props.conf"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Data/Createsourcetypes#Edit_props.conf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Addfieldsatsearchtime"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Addfieldsatsearchtime&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;inputs.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[monitor://pathtoyourlogfiles]
sourcetype=apache_custom
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;props.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[apache_custom]
TRANSFORMS-h1=hostoverride
REPORT-r1=apache_custom_fields
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;transforms.conf&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[apache_custom_fields]
REGEX=] \w+ (\S+) "(.*?)" (OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT) (HTTP.\S+) (\S+) (\S+) (\d{3}) (\d+) (\d+)
FORMAT=clientip::$1 useragent::$2 method::$3 protocol::$4 url::$5 uri_query::$6 status::$7 bytes::$8 timetaken::$9 

[hostoverride]
DEST_KEY = MetaData:Host
REGEX = ] (\w+)
FORMAT = host::$1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 May 2012 07:53:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55813#M10911</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-19T07:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Parse apache access log  in transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55814#M10912</link>
      <description>&lt;P&gt;Thank you! I probably didn't ask my question properly. Let me try to rephrase my question. When I installed splunk, I can see 2 sourcetypes for common apache log files -- acceess_common and access_combined_cookie. &lt;BR /&gt;
Since my apache log format is coutomized, I have to create the regular expression myself. &lt;BR /&gt;
This part is time consuming and it will be great if I can reuse old transforms.conf.&lt;BR /&gt;
My sample eventdata&lt;/P&gt;

&lt;P&gt;[21/May/2012:11:50:16 -0400] 10.39.208.3 "my-user-id" "libwww-perl/5.77" GET HTTP/1.1 "&lt;A href="http://www.amazon.com" target="_blank"&gt;http://www.amazon.com&lt;/A&gt;" "?search-alias%3Daps&amp;amp;field-keywords=ipad+3&amp;amp;sprefix=ipad%2Caps%2C210" 200 495 0&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:50:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55814#M10912</guid>
      <dc:creator>shangshin</dc:creator>
      <dc:date>2020-09-28T11:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Parse apache access log  in transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55815#M10913</link>
      <description>&lt;P&gt;You can find the default settings for access_combined and other sourcetypes in $SPLUNK_HOME/etc/system/default&lt;BR /&gt;
You should look specifically at props.conf and transforms.conf&lt;BR /&gt;
You will find the regular expressions in transforms.conf&lt;/P&gt;

&lt;P&gt;However, you should not make your changes in the default directory.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:51:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55815#M10913</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2020-09-28T11:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Parse apache access log  in transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55816#M10914</link>
      <description>&lt;P&gt;Cool. Thanks!&lt;BR /&gt;
One last question -- Where can I find the definition of the reg strings. e.g. nspaces, sbstring, etc  &lt;/P&gt;

&lt;P&gt;REGEX = ^[[nspaces:clientip]]\s++[[nspaces:ident]]\s++[[nspaces:user]]\s++[[sbstring:req_time]]\s++[[access-request]]\s++[[nspaces:status]&lt;BR /&gt;
]\s++&lt;A href="https://community.splunk.com/?:s++%22(?%3Creferer%3E%5B%5Bbc_domain:referer_%5D%5D?+%5B%5E%22%5D*+)%22(?:s++%5B%5Bqstring:useragent%5D%5D(?:s++%5B%5Bqstring:cookie%5D%5D)?+)?+" target="_blank"&gt;[nspaces:bytes]&lt;/A&gt;?[[al&lt;BR /&gt;
l:other]]&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:51:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55816#M10914</guid>
      <dc:creator>shangshin</dc:creator>
      <dc:date>2020-09-28T11:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Parse apache access log  in transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55817#M10915</link>
      <description>&lt;P&gt;I think if you look earlier in transforms.conf, you will see these expressions. They aren't documented that I can find, and they aren't any official flavor of regex that I know. But, they are sort of "character classes" that Splunk uses as a shorthand for the sourcetypes that are predefined within Splunk.&lt;/P&gt;

&lt;P&gt;Funny you should ask, I just got an answer to this very question a few days ago. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;But that's why I wrote out the regexes in my original example - I couldn't really tell you how to use this syntax correctly.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2012 16:19:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Parse-apache-access-log-in-transforms-conf/m-p/55817#M10915</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-05-23T16:19:22Z</dc:date>
    </item>
  </channel>
</rss>

