Change SFTP/SCP log rotators to use 4-digit year in filenames (fixes #745).

This commit is contained in:
Jon Siwek 2012-01-10 09:38:17 -06:00
parent 048516c605
commit f921a4d5db
2 changed files with 18 additions and 2 deletions

View file

@ -25,6 +25,10 @@ export {
## function queries this table upon log rotation and performs a secure ## function queries this table upon log rotation and performs a secure
## copy of the rotated-log to each destination in the set. ## copy of the rotated-log to each destination in the set.
global scp_destinations: table[Writer, string] of set[SCPDestination]; global scp_destinations: table[Writer, string] of set[SCPDestination];
## Default naming format for timestamps embedded into log filenames
## that use the SCP rotator.
const scp_rotation_date_format = "%Y-%m-%d-%H-%M-%S" &redef;
} }
function scp_postprocessor(info: Log::RotationInfo): bool function scp_postprocessor(info: Log::RotationInfo): bool
@ -34,7 +38,11 @@ function scp_postprocessor(info: Log::RotationInfo): bool
local command = ""; local command = "";
for ( d in scp_destinations[info$writer, info$path] ) for ( d in scp_destinations[info$writer, info$path] )
command += fmt("scp %s %s@%s:%s;", info$fname, d$user, d$host, d$path); {
local dst = fmt("%s/%s.%s.log", d$path, info$path,
strftime(Log::scp_rotation_date_format, info$open));
command += fmt("scp %s %s@%s:%s;", info$fname, d$user, d$host, dst);
}
command += fmt("/bin/rm %s", info$fname); command += fmt("/bin/rm %s", info$fname);
system(command); system(command);

View file

@ -47,6 +47,10 @@ export {
## transfer of the rotated-log to each destination in the set. This ## transfer of the rotated-log to each destination in the set. This
## table can be modified at run-time. ## table can be modified at run-time.
global sftp_destinations: table[Writer, string] of set[SFTPDestination]; global sftp_destinations: table[Writer, string] of set[SFTPDestination];
## Default naming format for timestamps embedded into log filenames
## that use the SFTP rotator.
const sftp_rotation_date_format = "%Y-%m-%d-%H-%M-%S" &redef;
} }
function sftp_postprocessor(info: Log::RotationInfo): bool function sftp_postprocessor(info: Log::RotationInfo): bool
@ -56,8 +60,12 @@ function sftp_postprocessor(info: Log::RotationInfo): bool
local command = ""; local command = "";
for ( d in sftp_destinations[info$writer, info$path] ) for ( d in sftp_destinations[info$writer, info$path] )
command += fmt("echo put %s %s | sftp -b - %s@%s;", info$fname, d$path, {
local dst = fmt("%s/%s.%s.log", d$path, info$path,
strftime(Log::sftp_rotation_date_format, info$open));
command += fmt("echo put %s %s | sftp -b - %s@%s;", info$fname, dst,
d$user, d$host); d$user, d$host);
}
command += fmt("/bin/rm %s", info$fname); command += fmt("/bin/rm %s", info$fname);
system(command); system(command);