Nagios log file with normal date/time format
Introduction –
Nagios log file print the time in epoch time format. To convert that nagios log with normal time/date format you can use the following perl script.
Please download the script from here- http://www.indiangnu.org/wp-content/uploads/2010/nagios-log-pl.txt
* How to use it –
root@me:~# cat /etc/nagios/var/nagios.log | grep -i NOTIFICATION | /root/nagmon/nagios-log.pl
* Pasting the code here…
root@me:~# /root/nagmon/nagios-log.pl
#!/usr/bin/perl
# Author - IndianGNU.org
# Read nagios.log file and show log with
# converted date field in human-readable format
#
$numArgs = $#ARGV + 1;
if ( $ARGV[0] eq "-h")
{
print " * Usage: cat like '/usr/local/nagios/var/nagios.log' | $0 \n"; exit 1;
}
sub epochtime
{
my $epoch_time = shift;
($sec,$min,$hour,$day,$month,$year) = localtime($epoch_time);
# correct the date and month for humans
$year = 1900 + $year;
$month++;
return sprintf("%02d/%02d/%02d %02d:%02d:%02d", $year, $month, $day, $hour, $min, $sec);
}
while (<>)
{
my $epoch = substr $_, 1, 10;
my $remainder = substr $_, 13;
my $human_date = &epochtime($epoch);
printf("[%s] %s", $human_date, $remainder);
}
exit;
Thanks you,
Arun
Similar Posts:
- Nagios daily and weekly Reporting and log parsing
- أعلى 5 – فتح شبكة المصدر ومراقبة الأداء + نظام تنبيه
- Epoch or Unix timestamp and Date format
- 상위 5 – 오픈 소스 네트워크 및 성능 모니터링 + 경보 시스템
- Топ 5 – Open Network Источник и мониторинга производительности системы оповещения
- 前5名 – 开源网络和性能监控+报警系统
- トップ5 – オープンソースのネットワークおよびパフォーマンスの監視+警告システム