2014-08-14 Ramon Novoa <rnovoa@artica.es>
* plugins/grep_log, plugins/grep_log_module: Detect log rotation by inode number AND file size. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10427 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
8473797f42
commit
eac45c37b5
|
@ -1,3 +1,9 @@
|
||||||
|
2014-08-14 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* plugins/grep_log,
|
||||||
|
plugins/grep_log_module: Detect log rotation by inode number AND file
|
||||||
|
size.
|
||||||
|
|
||||||
2014-08-14 Koichiro Kikuchi <koichiro@rworks.jp>
|
2014-08-14 Koichiro Kikuchi <koichiro@rworks.jp>
|
||||||
|
|
||||||
* FreeBSD/pandora_agent: Fixed path of the daemon command.
|
* FreeBSD/pandora_agent: Fixed path of the daemon command.
|
||||||
|
|
|
@ -47,6 +47,9 @@ my $Idx_pos = 0;
|
||||||
# Log file inode number
|
# Log file inode number
|
||||||
my $Idx_ino = '';
|
my $Idx_ino = '';
|
||||||
|
|
||||||
|
# Log file size
|
||||||
|
my $Idx_size = 0;
|
||||||
|
|
||||||
# Regular expression to be matched
|
# Regular expression to be matched
|
||||||
my $Reg_exp = '';
|
my $Reg_exp = '';
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ sub log_msg ($) {
|
||||||
sub load_idx () {
|
sub load_idx () {
|
||||||
my $line;
|
my $line;
|
||||||
my $current_ino;
|
my $current_ino;
|
||||||
|
my $current_size;
|
||||||
|
|
||||||
log_msg("Loading index file $Idx_file");
|
log_msg("Loading index file $Idx_file");
|
||||||
|
|
||||||
|
@ -99,18 +103,20 @@ sub load_idx () {
|
||||||
|
|
||||||
# Read position and date
|
# Read position and date
|
||||||
$line = <IDXFILE>;
|
$line = <IDXFILE>;
|
||||||
($Idx_pos, $Idx_ino) = split(' ', $line);
|
($Idx_pos, $Idx_ino, $Idx_size) = split(' ', $line);
|
||||||
|
|
||||||
close(IDXFILE);
|
close(IDXFILE);
|
||||||
|
|
||||||
# Reset the file index if the file has changed
|
# Reset the file index if the file has changed
|
||||||
$current_ino = (stat($Log_file))[1];
|
$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");
|
log_msg("File changed, resetting index");
|
||||||
|
|
||||||
$Idx_pos = 0;
|
$Idx_pos = 0;
|
||||||
$Idx_ino = $current_ino;
|
$Idx_ino = $current_ino;
|
||||||
}
|
}
|
||||||
|
$Idx_size = $current_size;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +131,7 @@ sub save_idx () {
|
||||||
|
|
||||||
open(IDXFILE, "> $Idx_file") || error_msg("Error opening file $Idx_file: "
|
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);
|
close(IDXFILE);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -47,6 +47,9 @@ my $Idx_pos = 0;
|
||||||
# Log file inode number
|
# Log file inode number
|
||||||
my $Idx_ino = '';
|
my $Idx_ino = '';
|
||||||
|
|
||||||
|
# Log file size
|
||||||
|
my $Idx_size = 0;
|
||||||
|
|
||||||
# Regular expression to be matched
|
# Regular expression to be matched
|
||||||
my $Reg_exp = '';
|
my $Reg_exp = '';
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ sub log_msg ($) {
|
||||||
sub load_idx () {
|
sub load_idx () {
|
||||||
my $line;
|
my $line;
|
||||||
my $current_ino;
|
my $current_ino;
|
||||||
|
my $current_size;
|
||||||
|
|
||||||
log_msg("Loading index file $Idx_file");
|
log_msg("Loading index file $Idx_file");
|
||||||
|
|
||||||
|
@ -99,18 +103,20 @@ sub load_idx () {
|
||||||
|
|
||||||
# Read position and date
|
# Read position and date
|
||||||
$line = <IDXFILE>;
|
$line = <IDXFILE>;
|
||||||
($Idx_pos, $Idx_ino) = split(' ', $line);
|
($Idx_pos, $Idx_ino, $Idx_size) = split(' ', $line);
|
||||||
|
|
||||||
close(IDXFILE);
|
close(IDXFILE);
|
||||||
|
|
||||||
# Reset the file index if the file has changed
|
# Reset the file index if the file has changed
|
||||||
$current_ino = (stat($Log_file))[1];
|
$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");
|
log_msg("File changed, resetting index");
|
||||||
|
|
||||||
$Idx_pos = 0;
|
$Idx_pos = 0;
|
||||||
$Idx_ino = $current_ino;
|
$Idx_ino = $current_ino;
|
||||||
}
|
}
|
||||||
|
$Idx_size = $current_size;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +131,7 @@ sub save_idx () {
|
||||||
|
|
||||||
open(IDXFILE, "> $Idx_file") || error_msg("Error opening file $Idx_file: "
|
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);
|
close(IDXFILE);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue