Nagios Is The Industry Standard In IT Infrastructure Monitoring. Nagios logs all messages and information to file /usr/local/nagios/var/
If you are searching for information stored in Nagios log file, you will probably prefer to see the information in human readable date and time format. In this post we will explain how to quickly and easily convert Unix Timestamp Nagios log file format to human friendly and readable format.
Converting Nagios log file Unix Timestamp is actually very simple. Perl Localtime converts a time as returned by the time function to a 9-element list with the time analyzed for the local time zone. Since we will use perl localtime one liner to convert all Unix Timestampsto human readable format you must have Perl installed on your system. Perl is a required package when installing Nagios, so Perl it is usually already present on your systems. To convert Nagios log timestamps, we need to “cat” Nagios log file and convert Unix Timestamps with Perl Localtime as seen below.
Convert Nagios Log Timestamp to Human Readable Format
[root@foo1 ~]# cat /usr/local/nagios/var/nagios.log | perl -pe 's/(d+)/localtime($1)/e'
Let’s see what the Nagios log file Timestamp format was BEFORE the Timestamp conversion:
[root@foo1 ~]# cat /usr/local/nagios/var/nagios.log [1377258479] Nagios 3.5.0 starting... (PID=5889) [1377258479] Local time is Fri Aug 23 13:47:59 CEST 2013 [1377258479] LOG VERSION: 2.0 [1377258479] Finished daemonizing... (New PID=5890)
This is the Nagios log file Timestamp format AFTER the Timestamp conversion:
[root@foo1 ~]# cat /usr/local/nagios/var/nagios.log | perl -pe 's/(d+)/localtime($1)/e' [Fri Aug 23 13:47:59 2013] Nagios 3.5.0 starting... (PID=5889) [Fri Aug 23 13:47:59 2013] Local time is Fri Aug 23 13:47:59 CEST 2013 [Fri Aug 23 13:47:59 2013] LOG VERSION: 2.0 [Fri Aug 23 13:47:59 2013] Finished daemonizing... (New PID=5890)
We have successfully converted Nagios log file Unix Timestamp to human readable, friendly date and time format. This way Nagios administrators will have a much easier job looking and corelating Nagios events from Nagios log files.
Wish you happy browsing through Nagios log files!
2 Comments
Leave a Reply