5
syslog2iso8601.pl - Octopussy program to convert 'syslog format' logs to 'iso8601' logs
9
syslog2iso8601.pl --device <device> --service <service>
22
use DateTime::Format::Strptime;
24
use AAT::Utils qw( ARRAY );
28
Readonly my $PROG_NAME => 'syslog2iso8601.pl';
29
Readonly my $PROG_VERSION => Octopussy::Version();
32
my ($opt_device, $opt_service, $opt_timezone) = (undef, undef, undef);
44
my $help_str = <<"EOF";
46
$PROG_NAME (version $PROG_VERSION)
48
Usage: $PROG_NAME --device <device> --service <service> --timezone <+/-HH:MM>
53
if (!defined $opt_device)
55
print ' ' . Octopussy::Device::String_List(undef) . "\n";
57
elsif (!defined $opt_service)
60
. Octopussy::Device::String_Services(ARRAY($opt_device)) . "\n";
71
my $status = GetOptions(
74
'device=s' => \$opt_device,
75
'service=s' => \$opt_service,
76
'timezone=s' => \$opt_timezone,
82
|| (!defined $opt_device)
83
|| (!defined $opt_service)
84
|| (!defined $opt_timezone));
87
Octopussy::Logs::Get_TimePeriod_Files($opt_device, $opt_service, '197001010000', '202001010000');
89
my $strp = new DateTime::Format::Strptime(pattern => '%Y %h %e %T');
91
foreach my $min (sort keys %{$files})
94
foreach my $f (@{$files->{$min}})
96
if ($f =~ /\/(\d{4})\/\d{2}\/\d{2}\/msg_/)
99
if (defined open my $FILE, '-|', "zcat \"$f\"")
103
if ($_ =~ /^(\w{3}) \s?(\d{1,2}) (\d\d:\d\d:\d\d) (.*)$/)
105
my $dt = $strp->parse_datetime("$year $1 $2 $3");
106
my $str = sprintf("%sT%s.000000%s %s", $dt->ymd('-'), $dt->hms(':'), $opt_timezone, $4);
111
if (defined open my $TMPFILE, '|-', "gzip >> ${f}.tmp")
113
foreach my $log (@logs)
114
{ print {$TMPFILE} "$log\n"; }
116
rename "${f}.tmp", $f if (scalar @logs);
126
Sebastien Thebert <octo.devel@gmail.com>
b'\\ No newline at end of file'