diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index f03b421203..ad41285a32 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,9 @@ +2014-08-14 Ramon Novoa + + * plugins/grep_log, + plugins/grep_log_module: Detect log rotation by inode number AND file + size. + 2014-08-14 Koichiro Kikuchi * FreeBSD/pandora_agent: Fixed path of the daemon command. diff --git a/pandora_agents/unix/plugins/grep_log b/pandora_agents/unix/plugins/grep_log index 9b02e2d4b9..d94b7d01ab 100755 --- a/pandora_agents/unix/plugins/grep_log +++ b/pandora_agents/unix/plugins/grep_log @@ -47,6 +47,9 @@ my $Idx_pos = 0; # Log file inode number my $Idx_ino = ''; +# Log file size +my $Idx_size = 0; + # Regular expression to be matched my $Reg_exp = ''; @@ -91,6 +94,7 @@ sub log_msg ($) { sub load_idx () { my $line; my $current_ino; + my $current_size; log_msg("Loading index file $Idx_file"); @@ -99,18 +103,20 @@ sub load_idx () { # Read position and date $line = ; - ($Idx_pos, $Idx_ino) = split(' ', $line); + ($Idx_pos, $Idx_ino, $Idx_size) = split(' ', $line); close(IDXFILE); # Reset the file index if the file has changed $current_ino = (stat($Log_file))[1]; - if ($current_ino != $Idx_ino) { + $current_size = -s "$Log_file"; + if ($current_ino != $Idx_ino || $current_size < $Idx_size) { log_msg("File changed, resetting index"); $Idx_pos = 0; $Idx_ino = $current_ino; } + $Idx_size = $current_size; return; } @@ -125,7 +131,7 @@ sub save_idx () { open(IDXFILE, "> $Idx_file") || error_msg("Error opening file $Idx_file: " . $!); - print (IDXFILE $Idx_pos . " " . $Idx_ino); + print (IDXFILE $Idx_pos . " " . $Idx_ino . " " . $Idx_size); close(IDXFILE); return; diff --git a/pandora_agents/unix/plugins/grep_log_module b/pandora_agents/unix/plugins/grep_log_module index 78a7b1d9cd..0769128cbd 100755 --- a/pandora_agents/unix/plugins/grep_log_module +++ b/pandora_agents/unix/plugins/grep_log_module @@ -47,6 +47,9 @@ my $Idx_pos = 0; # Log file inode number my $Idx_ino = ''; +# Log file size +my $Idx_size = 0; + # Regular expression to be matched my $Reg_exp = ''; @@ -91,6 +94,7 @@ sub log_msg ($) { sub load_idx () { my $line; my $current_ino; + my $current_size; log_msg("Loading index file $Idx_file"); @@ -99,18 +103,20 @@ sub load_idx () { # Read position and date $line = ; - ($Idx_pos, $Idx_ino) = split(' ', $line); + ($Idx_pos, $Idx_ino, $Idx_size) = split(' ', $line); close(IDXFILE); # Reset the file index if the file has changed $current_ino = (stat($Log_file))[1]; - if ($current_ino != $Idx_ino) { + $current_size = -s "$Log_file"; + if ($current_ino != $Idx_ino || $current_size < $Idx_size) { log_msg("File changed, resetting index"); $Idx_pos = 0; $Idx_ino = $current_ino; } + $Idx_size = $current_size; return; } @@ -125,7 +131,7 @@ sub save_idx () { open(IDXFILE, "> $Idx_file") || error_msg("Error opening file $Idx_file: " . $!); - print (IDXFILE $Idx_pos . " " . $Idx_ino); + print (IDXFILE $Idx_pos . " " . $Idx_ino . " " . $Idx_size); close(IDXFILE); return;