Timestamp
Fred
f1216 at yahoo.com
Wed Sep 21 12:41:15 CEST 2005
I use the following little script which finds all the timestamps (well,
things that *look* like timestamps ;-) in any of the various log files and
converts them.
#/usr/bin/perl
use strict;
use 5.008000;
use Data::Dumper;
sub usage {
print <<'EOF';
nlog [--help] [file]
Pretty print the nagios logs
--help Print this message
--status|-s Use the status.log, default is nagios.log
EOF
exit 0;
}
sub version {
my ($r,$ver) = split / /,'$Revision: 1.5 $';
print <<"EOF";
nlog version $ver
EOF
exit;
}
my $status;
{
use Getopt::Long;
&GetOptions( "version", \&version,
"help", \&usage,
"status", \$status,
"s", \$status,
);
}
my $f;
if ($status)
{
push(@ARGV,"/opt/hptc/nagios/var/status.log") if ($#ARGV < 0);
}
else
{
push(@ARGV,"/opt/hptc/nagios/var/nagios.log") if ($#ARGV < 0);
}
foreach $f (@ARGV)
{
open(LOG,"<$f") or die "Cannot open $f";
while (<LOG>)
{
my ($ts,$rest) = split /\s/,$_,2;
if (/\=11[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/)
{
my ($att,$val) = split /=/;
my $lt = localtime $val;
s/=.*$/=$lt/;
}
if ($ts =~ /\[[0-9]+\]/)
{
$ts =~ s/\[//;
$ts =~ s/\]//;
my $lt = localtime $ts;
print "[$lt] $rest";
}
else
{
print;
}
}
close LOG;
}
exit(0);
You'll need to change the /opt/hptc/nagios/var/* file references to
point to your own default locations.
I call it "nl" for nagioslog but be careful as it conflicts with the
real nl ;-)
-FredC
--- Richard Gliebe <richard.gliebe at fhv.at> wrote:
> Hi,
>
> how can I translate the timestamps in nagios.log to a real date/time:
>
> [1127294282] Auto-save of retention data completed successfully.
> ^^^^^^^^^^^^
>
> thanks in advance.
>
> Richard
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server.
> Download it for free - -and be entered to win a 42" plasma tv or your very
> own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-users
> ::: Please include Nagios version, plugin version (-v) and OS when reporting
> any issue.
> ::: Messages without supporting info will risk being sent to /dev/null
>
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list