|
[ Return To FAQ Index | Search The FAQs ]
|
|
| Title: | How can I convert the timestamp values in the log file to a friendlier format? |
| FAQ ID: | F0070 |
| Submitted By: | Andreas Wassatsch, Martin Ryan and Steve Alston |
| Last Updated: | 10/12/2003 |
|
| Description: |
User would like to view the raw log files with human-readable timestamps.
|
|
| Solution: |
The following Perl script will print out the contents of a Nagios log file with a human-readable time format:
#!/usr/bin/perl
# nagios-log-print
# taken from the faqs section FAQID: F0070 on the www.nagios.org website
#
if (!@ARGV[0]) {
print "Usage: {jumi [knowledge-based/faq/viewfaq.php]} <logfile name>\n";
print "\n";
print "prints the specified Nagios-logfile with timestamps\n";
print "converted to human readable time\n";
exit 1;
}
open(LOG,@ARGV[0]) || die "no Nagios log file named >>>>>>@ARGV[0]<<<<<<";
while (<LOG>) {
($part1, $part2) = split(/\s+/, $_, 2);
$part1 =~ s/\[//;
$part1 =~ s/\]//;
print "[", scalar localtime($part1), "]\;$part2\n";
};
close(LOG);
Alternatively, if you want to display the log from the command line use;
perl -pe 's/(\d+)/localtime(jumi)/e' nagios.log
|
|
| Related FAQs: |
| F0068 | What timestamp format is used in data and log files? |
|
| Keywords: | log timestamp format |
|