<?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: Why copytruncate logrotate does not play well with splunk monitoring in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196119#M39013</link>
    <description>&lt;P&gt;If you can tell your case number, I will make sure issue is resolved. However there is one possibility that splunk might see rolled file while it's still &amp;lt; 256 bytes, then in that case initcrc will not match. &lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2017 02:35:04 GMT</pubDate>
    <dc:creator>hrawat</dc:creator>
    <dc:date>2017-10-30T02:35:04Z</dc:date>
    <item>
      <title>Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196112#M39006</link>
      <description>&lt;P&gt;I am using logrotate to rotate my files, with the option &lt;STRONG&gt;copytruncate&lt;/STRONG&gt;.&lt;BR /&gt;
&lt;A href="http://linuxcommand.org/man_pages/logrotate8.html"&gt;http://linuxcommand.org/man_pages/logrotate8.html&lt;/A&gt;&lt;BR /&gt;
And It is causing splunk to reindex the file during the rotation.&lt;/P&gt;

&lt;P&gt;see my rotate script /etc/logrotate.d/test&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"/home/feed/test.log" { 
rotate 5 
size=50M 
sharedscripts 
copytruncate 
compress 
} 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What happens is :&lt;BR /&gt;
 - the rotation creates a new rotated file. (test.log.1)&lt;BR /&gt;
 - the rotation copy the content of the file to the new file (from line 1 to line X), then compress it.&lt;BR /&gt;
 - the rotation then &lt;STRONG&gt;truncates the original file by removing the first lines per chunks&lt;/STRONG&gt;, until reaching the line X.&lt;/P&gt;

&lt;P&gt;At the same time, splunk is monitoring the file, and &lt;STRONG&gt;check the first 256 chars for the crc&lt;/STRONG&gt;.&lt;BR /&gt;
 - during the truncate, because the first lines are changing, splunk redetect the file as new, and reindex it all.&lt;BR /&gt;
 - we find duplicates of the lines, the first lines with fewer duplicates, the last lines with more duplicates.&lt;/P&gt;

&lt;P&gt;How to identify the issue :&lt;BR /&gt;
 - look for duplicates and the time when they were generated. (not the event timestamp)&lt;BR /&gt;
 &lt;CODE&gt;source=path/to/my/logfile | convert ctime(_indextime) AS indextime| stats count values(indextime) AS indextime by _raw  | where count &amp;gt;1&lt;/CODE&gt;&lt;BR /&gt;
 - at the time of the rotation, look on the forwarder splunkd.log, check for multiple events like :&lt;BR /&gt;
&lt;CODE&gt;11-05-2014 10:48:33.924 +0000 INFO  WatchedFile - Will begin reading at offset=0 for file='/home/feed/test.log&lt;BR /&gt;
11-05-2014 10:48:34.234 +0000 INFO  WatchedFile - Will begin reading at offset=0 for file='/home/feed/test.log&lt;BR /&gt;
etc...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Nov 2014 10:54:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196112#M39006</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2014-11-05T10:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196113#M39007</link>
      <description>&lt;P&gt;The workarounds I found are : &lt;BR /&gt;
A - &lt;STRONG&gt;replace the copytruncate rotation by a move rotation&lt;/STRONG&gt; .&lt;BR /&gt;
It may not always be a solution, some applications are pretty limited and need to keep the handle of the log file always open.&lt;/P&gt;

&lt;P&gt;B- &lt;STRONG&gt;disable the monitoring just before the rotation&lt;/STRONG&gt;. &lt;/P&gt;

&lt;P&gt;The idea is to disable the monitoring before the rotation and re-enable it just after. &lt;BR /&gt;
using the logrotate options. Splunk will simply detect the new files, and resume. &lt;/P&gt;

&lt;P&gt;Here is my configuration : &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;&lt;P&gt;Inputs.conf in splunk &lt;STRONG&gt;in a specific app&lt;/STRONG&gt; "input_rotate"&lt;BR /&gt;
cat ./opt/splunk/etc/apps/input_rotate/local/inputs.conf &lt;/P&gt;

&lt;P&gt;[monitor://home/feed/&lt;EM&gt;.log&lt;/EM&gt;] &lt;BR /&gt;
disabled = false &lt;/P&gt;

&lt;H1&gt;add additional parameters&lt;/H1&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;logrotate script /etc/logrotate.d/test&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"/home/feed/test.log" { 
rotate 5 
size=50M
sharedscripts 
copytruncate 
compress 
prerotate 
/opt/splunk/bin/splunk disable app input_rotate -auth admin:changeme 
endscript 
postrotate 
/opt/splunk/bin/splunk enable app input_rotate -auth admin:changeme 
endscript 
} 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Remarks : &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt; you may want to adapt to your own monitor inputs. &lt;/LI&gt;
&lt;LI&gt;if you prefer to disable only one input, instead of the app.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;&lt;CODE&gt;/opt/splunk/bin/splunk edit monitor "/home/feed/*.log*" -disabled true -auth admin:changeme&lt;/CODE&gt;&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;the path to the splunk CLI has to be adapted to your forwarder path. &lt;/LI&gt;
&lt;LI&gt;it is important to monitoring the rotated/compressed version of the log file to avoid missing events.(my log.log* instead of just my log.log) 
Otherwise the last events before and during the copytruncate are lost. 
The splunk init crc will prevent the rotated versions to generate duplicates. 
you can compare the source to see from which file the events were monitored. &lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:06:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196113#M39007</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2020-09-28T18:06:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196114#M39008</link>
      <description>&lt;P&gt;An alternative method is to use a symlink so cancel the monitoring during the rotation.&lt;/P&gt;

&lt;P&gt;/home/feed/symlink_test.log -&amp;gt; /home/feed/test.log&lt;/P&gt;

&lt;P&gt;Have splunk monitors the symlink only&lt;BR /&gt;
[monitor://home/feed/symlink_test.log]&lt;BR /&gt;
followLinks=true&lt;/P&gt;

&lt;P&gt;then in the logrotate config &lt;BR /&gt;
when the rotation occurs : disable the symlink&lt;BR /&gt;
then after the rotation : recreate the symlink&lt;/P&gt;</description>
      <pubDate>Sat, 20 Aug 2016 22:10:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196114#M39008</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2016-08-20T22:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196115#M39009</link>
      <description>&lt;P&gt;I realize this is a little old, but for posterity...&lt;/P&gt;

&lt;P&gt;Depending on what your needs are, you can also move the rotated files to a location that is not defined in Splunk's inputs.conf for those files.  This capability is available in logrotate.  For example if you have a forwarder acting as a syslog server for network/system devices, and you have these logs dumped to /var/log/syslog.  You can create a directory for all archived/rotated files, and compress them giving them a different extension from the files you are currently inputting.  In our environment we have rsyslog dumping to a file distinguishable by the source ip of the sending device, and the sending protocol (for example the files look like:  logfile-x.x.x.x-imudp.log).  The inputs.conf file only ingests files ending in *.log from our production syslog server, ignoring the rotated files that end in .gz (compressed with logrotate).  You can also rotate to locations that are blacklisted within the inputs.conf, but we found the approach we took easier, and effective.  For example, you can define the following in logrotate (adjust for your retention and rotation requirements):&lt;/P&gt;

&lt;P&gt;/var/log/syslog/*.log&lt;BR /&gt;
{&lt;BR /&gt;
     daily&lt;BR /&gt;
     olddir /var/log/syslog/archive&lt;BR /&gt;
     size 1k&lt;BR /&gt;
     copytruncate&lt;BR /&gt;
     rotate 7&lt;BR /&gt;
     compress&lt;BR /&gt;
     sharedscripts&lt;BR /&gt;
     postrotate&lt;BR /&gt;
          /bin/kill -HUP &lt;CODE&gt;cat /var/run/syslogd.pid 2 &amp;gt; /dev/null&lt;/CODE&gt; 2&amp;gt; /dev/null || true&lt;BR /&gt;
     endscript&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;Splunk will ignore the rotated files because they don't meet the requirements defined within inputs.conf&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2017 15:12:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196115#M39009</guid>
      <dc:creator>trross33</dc:creator>
      <dc:date>2017-03-17T15:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196116#M39010</link>
      <description>&lt;P&gt;Hi trross33.&lt;/P&gt;

&lt;P&gt;This method works, but has a possible issue.&lt;BR /&gt;
If Splunk had the time to read 99 lines of the primary file, then the line 100 is added and the file rotate just after, you will end up with a rotated file in a location that is not monitored.&lt;BR /&gt;
And you will always have a chance to be missing the last lines of a log file, if your logs rotate quickly or if your forwarder is under speed constrains.&lt;BR /&gt;
This is why It's a good idea to monitor the original file and at least the first copy. Because splunk compares the crc and can pick up the last lines on a rotated copy of the file.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2017 16:09:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196116#M39010</guid>
      <dc:creator>yannK</dc:creator>
      <dc:date>2017-03-17T16:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196117#M39011</link>
      <description>&lt;P&gt;I checked logrotate code (&lt;A href="https://github.com/logrotate/logrotate/blob/master/logrotate.c"&gt;https://github.com/logrotate/logrotate/blob/master/logrotate.c&lt;/A&gt;) and it's using ftruncate(). So underlying linux do_truncate() in open.c is simply modifying inode entry for size. In logrotate case file size will be changed to 0.&lt;BR /&gt;
&lt;A href="https://elixir.free-electrons.com/linux/latest/source/fs/open.c"&gt;https://elixir.free-electrons.com/linux/latest/source/fs/open.c&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The only possible issue from man logrotate -&amp;gt; copytruncate&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   copytruncate
          Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one.  It can be used when some program cannot
          be  told  to  close its logfile and thus might continue writing (appending) to the previous log file forever.  Note that there is a very small time slice between copying the
          file and truncating it, so some logging data might be lost.  When this option is used, the create option will have no effect, as the old log file stays in place.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To avoid possible loss of few lines, monitor rotated file as well. Splunk will read missing line from backup file.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Oct 2017 22:32:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196117#M39011</guid>
      <dc:creator>hrawat</dc:creator>
      <dc:date>2017-10-29T22:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196118#M39012</link>
      <description>&lt;P&gt;Except you can't trust Splunk's logic in ignoring log files it's already seen. I've had to disabled the monitoring of rolled files in almost all situations because we end up with duplicate logs. Splunk's support has been, to be blunt, useless with tracking this down. Really, super frustrating.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 00:51:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196118#M39012</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2017-10-30T00:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196119#M39013</link>
      <description>&lt;P&gt;If you can tell your case number, I will make sure issue is resolved. However there is one possibility that splunk might see rolled file while it's still &amp;lt; 256 bytes, then in that case initcrc will not match. &lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 02:35:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196119#M39013</guid>
      <dc:creator>hrawat</dc:creator>
      <dc:date>2017-10-30T02:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196120#M39014</link>
      <description>&lt;P&gt;Case 000466442&lt;/P&gt;

&lt;P&gt;And also this question: &lt;A href="https://answers.splunk.com/answers/515448/why-does-splunk-re-index-this-rolled-file-how-to-t.html"&gt;https://answers.splunk.com/answers/515448/why-does-splunk-re-index-this-rolled-file-how-to-t.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:34:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196120#M39014</guid>
      <dc:creator>twinspop</dc:creator>
      <dc:date>2017-10-30T15:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196121#M39015</link>
      <description>&lt;P&gt;Appreciate your help on Case 000466442. The attached DEBUG logs were very helpful to understand the problem. Now I can re-pro the issue at will. Fixing it for next release.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Nov 2017 22:21:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196121#M39015</guid>
      <dc:creator>hrawat</dc:creator>
      <dc:date>2017-11-05T22:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196122#M39016</link>
      <description>&lt;P&gt;This issue is resolved by &lt;BR /&gt;
7.1 (SPL-149198)&lt;BR /&gt;
7.0.4 (SPL-153453) &lt;BR /&gt;
6.6.7(SPL-146190)&lt;/P&gt;</description>
      <pubDate>Sat, 12 May 2018 02:02:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196122#M39016</guid>
      <dc:creator>hrawat</dc:creator>
      <dc:date>2018-05-12T02:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196123#M39017</link>
      <description>&lt;P&gt;Issue is resolved by 7.1.0 ( SPL-143553).&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 23:12:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196123#M39017</guid>
      <dc:creator>hrawat</dc:creator>
      <dc:date>2018-10-11T23:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Why copytruncate logrotate does not play well with splunk monitoring</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196124#M39018</link>
      <description>&lt;P&gt;Issue is resolved by code fix for 7.1.0 release ( SPL-143553).&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 23:17:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Why-copytruncate-logrotate-does-not-play-well-with-splunk/m-p/196124#M39018</guid>
      <dc:creator>hrawat</dc:creator>
      <dc:date>2018-10-11T23:17:49Z</dc:date>
    </item>
  </channel>
</rss>

