Home > Uncategorized > Nagios: HOWTO convert timestamp values to a human-readable value / logfile

Nagios: HOWTO convert timestamp values to a human-readable value / logfile

Problem description:

Nagios reports all messages to /usr/local/nagios/var/log/nagios.log. Unfortunately timestamps are stored in a none-human-readable way. If you are analyzing the logfile via tail, less, more, vi, etc. you are not able to determine the actual time of an event.

Problem resolution:

You can convert the timestamp values to a humand-readable string using the following simple perl command:

cat /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'

Example:

[root@linux01 ~]# tail -7lf /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'
[Wed May 15 12:00:12 2011] Caught SIGHUP, restarting...
[Wed May 15 12:00:12 2011] Nagios 3.2.3 starting... (PID=1234)
[Wed May 15 12:00:12 2011] Local time is Wed May 15 12:00:12 CEST 2011
[Wed May 15 12:00:12 2011] LOG VERSION: 2.0
[Wed May 15 12:14:02 2011] SERVICE ALERT: linux02.mydomain.intern;Status bond0;OK;HARD;4;OK - Bonding Mode: IEEE802.3adDynamic. eth0 up eth1 up
[Wed May 15 12:14:02 2011] SERVICE NOTIFICATION: nagiosadmin;linux02.mydomain.intern;Status bond0;OK;notify-service-by-email;OK - Bonding Mode: IEEE802.3adDynamic. eth0 up eth1 up
[Wed May 15 13:00:12 2011] Auto-save of retention data completed successfully.
Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.

Connect with Facebook