<?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: Timestamp hour without leading zero in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27336#M4588</link>
    <description>&lt;P&gt;Something like C:\Users\angeliga\Filer\379177\Report_2013-05-21_16-49-29\Server\file&lt;/P&gt;

&lt;P&gt;Where the timestamp is 2013-05-21_16-49-29 (YYYY-MM-DD_hh-mm-ss)&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 14:19:55 GMT</pubDate>
    <dc:creator>gelica</dc:creator>
    <dc:date>2020-09-28T14:19:55Z</dc:date>
    <item>
      <title>Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27327#M4579</link>
      <description>&lt;P&gt;I have a problem regarding the time stamp recognition in one of my log types. The one affected is a checkpoint export which I cannot change in format as it is delivered by a 3rd party company every night. &lt;BR /&gt;&lt;BR /&gt;
The time stamps - as you can see in the exmaple lines below - have a format like &lt;BR /&gt;30Nov2011;23:59:58&lt;BR /&gt;&lt;BR /&gt;
The extraction works well for hours with 2 digits. The lines with an hour of only 1 digit are indexed somewhere in 2010 - so the time stamp is not recognized correctly.&lt;BR /&gt;&lt;BR /&gt;
Has anyone an idea to fix this?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
I already checked the "strptime" function but in the manual it says &lt;EM&gt;"%H is the hour (24-hour clock) [0,23]; leading zeros are permitted but not required&lt;/EM&gt;."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;
Well - in my case they seem to be &lt;STRONG&gt;required&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;My props.conf:&lt;BR /&gt;&lt;BR /&gt;
[cp]&lt;BR /&gt;&lt;BR /&gt;
CHECK_FOR_HEADER = true&lt;BR /&gt;&lt;BR /&gt;
TIME_FORMAT=%d%b%Y;%H:%M:%S&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
1652;30Nov2011;23:59:58;192.168.249.2;log;drop;&lt;BR /&gt;
1654;30Nov2011;23:59:59;192.168.249.2;log;drop;&lt;BR /&gt;
1710;30Nov2011;23:59:58;192.168.249.22;log;drop;&lt;BR /&gt;
1990;1Dec2011;0:00:00;192.168.249.2;log;drop;&lt;BR /&gt;
1967;1Dec2011;0:00:01;192.168.249.12;log;drop;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2011 09:56:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27327#M4579</guid>
      <dc:creator>FRoth</dc:creator>
      <dc:date>2011-12-02T09:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27328#M4580</link>
      <description>&lt;P&gt;Yes, for some reasons I am encountering this problem as well and that is puzzling me. Timestamp with a single digit as an hour gets their Timestamp extracted out wrongly, e.g. 0:12:53. But if I changed them to a double digit, e.g.00:12:53 they are fine.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 09:21:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27328#M4580</guid>
      <dc:creator>twkan</dc:creator>
      <dc:date>2011-12-13T09:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27329#M4581</link>
      <description>&lt;P&gt;This is common with some uses of IBM Websphere I have seen timestamps that look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[12/14/11 1:00:00:115 PST]  hello 
[12/14/11 1:00:00:117 PST]  goodbye 
[12/14/11 1:00:00:114 PST]  whatever 
[12/14/11 1:08:00:117 PST]  super 
[12/14/11 0:07:00:113]  star 
[12/14/11 0:06:00:117 PST]  who  
[12/14/11 0:04:00:118 PST]  cares
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(notice above, some have timezone, and some do not)&lt;/P&gt;

&lt;P&gt;In this case, a custom "datetime.xml" will solve it.  ($SPLUNK_HOME/etc/datetime.xml has all the default config for timestamp extraction patterns).  Its not rocket science to make you're own, you just have to write a simple regex for it.&lt;/P&gt;

&lt;P&gt;You'll need to edit two files.  "props.conf" which you may already edit from time to time, and a file that contains a new datetime config, in this case we'll call it "ninjadatetime.xml".&lt;/P&gt;

&lt;P&gt;props.conf will need to reference the location of "ninjadatetime.xml" as the setting for the DATETIME_CONFIG entry.  It will now ignore splunk's defaults and take the new pattern we've created.&lt;/P&gt;

&lt;P&gt;ninjadatetime.xml --- has a definition for the "order in which splunk will assign parts of a date and a time", and the corresponding regex, matching and capturing each appropriate component of the date and the time.&lt;BR /&gt;
If your events have no timestamp, you also may want to set the timezone as well (as i have below). &lt;/P&gt;

&lt;H2&gt;FILE -&amp;gt; props.conf&lt;/H2&gt;

&lt;PRE&gt;&lt;CODE&gt;[mysourcetype]
DATETIME_CONFIG = /etc/apps/search/local/ninjadatetime.xml
TIME_FORMAT = %m/%d/%y %k:%M:%S:%3f
TZ = America/Chicago
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;H2&gt;FILE -&amp;gt; ninjadatetime.xml&lt;/H2&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;datetime&amp;gt;
   &amp;lt;!-- we're using Splunk's default timezone extraction regex below--&amp;gt;
&amp;lt;define name="_zone" extract="zone"&amp;gt;
         &amp;lt;text&amp;gt;&amp;lt;![CDATA[((?:(?:UT|UTC|GMT(?![+-])|CET|CEST|CETDST|MET|MEST|METDST|MEZ|MESZ|EET|EEST|EETDST|WET|WEST|WETDST|MSK|MSD|IST|JST|KST|HKT|AST|ADT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|CAST|CADT|EAST|EADT|WAST|WADT|Z)|(?:GMT)?[+-]\d\d?:?(?:\d\d)?)(?!\w?))?]]&amp;gt;&amp;lt;/text&amp;gt;
&amp;lt;/define&amp;gt;

  &amp;lt;!--this pattern captures all of the time/date info, and then uses the above patterns to gather timezone.--&amp;gt;
&amp;lt;define name="_wsdatewzone" extract="month, day, year,hour,minute,second,subsecond,zone"&amp;gt;
    &amp;lt;text&amp;gt;&amp;lt;![CDATA[(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+):(\d+)]]&amp;gt;&amp;lt;/text&amp;gt;
        &amp;lt;text&amp;gt;&amp;lt;![CDATA[\s+]]&amp;gt;&amp;lt;/text&amp;gt;
    &amp;lt;use name="_zone"/&amp;gt;
&amp;lt;/define&amp;gt;

  &amp;lt;!--this pattern captures all of the time/date info but no timezone as one is not present--&amp;gt;
&amp;lt;define name="_wsdatenozone" extract="month, day, year,hour,minute,second,subsecond"&amp;gt;
        &amp;lt;text&amp;gt;&amp;lt;![CDATA[(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+):(\d+)]]&amp;gt;&amp;lt;/text&amp;gt;
&amp;lt;/define&amp;gt;

&amp;lt;timePatterns&amp;gt;
      &amp;lt;use name="_wsdatewzone"/&amp;gt;
      &amp;lt;use name="_wsdatenozone"/&amp;gt;
&amp;lt;/timePatterns&amp;gt;

&amp;lt;datePatterns&amp;gt;
      &amp;lt;use name="_wsdatewzone"/&amp;gt;
      &amp;lt;use name="_wsdatenozone"/&amp;gt;

&amp;lt;/datePatterns&amp;gt;

&amp;lt;/datetime&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="https://img.skitch.com/20111216-c3ix71dh9p1tjp9chwfc21dgrn.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2011 19:46:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27329#M4581</guid>
      <dc:creator>Michael_Wilde</dc:creator>
      <dc:date>2011-12-16T19:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27330#M4582</link>
      <description>&lt;P&gt;This is very nice, thanks for the effort! I haven't had the time to get to the root cause of the issue, and suspected it could be the datetime.xml, and you beat me to it.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2011 23:28:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27330#M4582</guid>
      <dc:creator>twkan</dc:creator>
      <dc:date>2011-12-16T23:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27331#M4583</link>
      <description>&lt;P&gt;Tat-Wee.. I fixed it to accommodate events that do and do not have a timezone.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Dec 2011 04:34:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27331#M4583</guid>
      <dc:creator>Michael_Wilde</dc:creator>
      <dc:date>2011-12-17T04:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27332#M4584</link>
      <description>&lt;P&gt;Excellent answer!&lt;/P&gt;</description>
      <pubDate>Sun, 18 Dec 2011 15:34:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27332#M4584</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2011-12-18T15:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27333#M4585</link>
      <description>&lt;P&gt;I recently encountered the same issue with some WebSphere logs.&lt;/P&gt;

&lt;P&gt;An easy solution I came up with is to modify the default datetime.xml in $SPLUNK_HOME/etc/&lt;/P&gt;

&lt;P&gt;The only modification you need to make is to change the hour detection (ie, in the section labelled &lt;STRONG&gt;define name="_hour" extract="hour"&lt;/STRONG&gt;) from this:&lt;/P&gt;

&lt;P&gt;[([01]?&lt;STRONG&gt;[1-9]&lt;/STRONG&gt;|[012][0-3])(?!\d)]]&lt;/P&gt;

&lt;P&gt;to this:&lt;/P&gt;

&lt;P&gt;[([01]?&lt;STRONG&gt;[0-9]&lt;/STRONG&gt;|[012][0-3])(?!\d)]]&lt;/P&gt;

&lt;P&gt;Then it successfully picks up the 0:xx:xx:xxx event timestamps.  I have not found a situation where this has caused side effects so far.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jun 2012 06:23:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27333#M4585</guid>
      <dc:creator>milestulett</dc:creator>
      <dc:date>2012-06-28T06:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27334#M4586</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;
I'm trying to do something similar to this, but I want to extract the time and date from my source path. &lt;BR /&gt;
I've tried modifying datetime.xml, but I can't get it to work, I followed this example but changed the regex to match my format. &lt;BR /&gt;
This is what it looks like, but I can't get it to work. Does anyone have any suggestions?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;define name="_wsdatenozone" extract="year, month, day,hour,minute,second"&amp;gt;
        &amp;lt;text&amp;gt;&amp;lt;![CDATA[source::.*?(\d{4})-(\d{2})-(\d{2})_(\d{2})-(\d{2})-(\d{2})]]&amp;gt;&amp;lt;/text&amp;gt;
&amp;lt;/define&amp;gt;

&amp;lt;timePatterns&amp;gt;
      &amp;lt;use name="_wsdatenozone"/&amp;gt;
&amp;lt;/timePatterns&amp;gt;

&amp;lt;datePatterns&amp;gt;
      &amp;lt;use name="_wsdatenozone"/&amp;gt;
&amp;lt;/datePatterns&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Edit: My timestamps are of the form:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;C:\Users\angeliga\Filer\379177\Report_2013-05-21_16-49-29\Server\file
where the timestamp is 2013-05-21_16-49-29 (YYYY-MM-DD_hh-mm-ss)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jul 2013 11:59:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27334#M4586</guid>
      <dc:creator>gelica</dc:creator>
      <dc:date>2013-07-12T11:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27335#M4587</link>
      <description>&lt;P&gt;How do your timestamps look like?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2013 12:26:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27335#M4587</guid>
      <dc:creator>FRoth</dc:creator>
      <dc:date>2013-07-12T12:26:24Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27336#M4588</link>
      <description>&lt;P&gt;Something like C:\Users\angeliga\Filer\379177\Report_2013-05-21_16-49-29\Server\file&lt;/P&gt;

&lt;P&gt;Where the timestamp is 2013-05-21_16-49-29 (YYYY-MM-DD_hh-mm-ss)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:19:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27336#M4588</guid>
      <dc:creator>gelica</dc:creator>
      <dc:date>2020-09-28T14:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27337#M4589</link>
      <description>&lt;P&gt;I dont know for sure .. but have you tried putting the "\d" in brackets like "[\d]{4}" ?&lt;BR /&gt;
I would also escape the "-" symbols that way "\-".&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2013 13:48:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27337#M4589</guid>
      <dc:creator>FRoth</dc:creator>
      <dc:date>2013-07-12T13:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Timestamp hour without leading zero</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27338#M4590</link>
      <description>&lt;P&gt;I tried your suggestion, but it won't work &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; &lt;BR /&gt;
Thanks anyway&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2013 13:53:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Timestamp-hour-without-leading-zero/m-p/27338#M4590</guid>
      <dc:creator>gelica</dc:creator>
      <dc:date>2013-07-12T13:53:06Z</dc:date>
    </item>
  </channel>
</rss>

