Nagios log file time format

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Nagios log file time format

Post by bsivavani »

Hi,

We have observed that currently Nagios log file /usr/local/nagios/var/nagios.log is saving with EPOCH time format as shown below.

[1507118166] SERVICE ALERT: XXXX;WIN_Server_C_Drive_Usage;CRITICAL;HARD;5;C:\ - total: 50.00 Gb - used: 42.73 Gb (85%) - free 7.27 Gb (15%)
[1507118166] GLOBAL SERVICE EVENT HANDLER: XXXX;WIN_Server_C_Drive_Usage;CRITICAL;HARD;5;xi_service_event_handler
[1507118166] SERVICE EVENT HANDLER: XXXX;WIN_Server_C_Drive_Usage;CRITICAL;HARD;5;check_snow_service

Is it possible to change time to standard date and time format (Oct 4 13:28:10) ?

Kindly advice.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Nagios log file time format

Post by eloyd »

Short version is no. This file is not really intended for reading by humans, it is intended to be parsed by the Nagios XI GUI for log file examination, which will then convert epoch time into local timezone time based on the Nagios XI settings.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Nagios log file time format

Post by mcapra »

You could feed the log into Nagios Log Server if the end goal is something more human readable. Logstash even has a handy nagios filter for parsing those logs and installing Logstash plugins in Nagios Log Server is relatively simple.

Code: Select all

/usr/local/nagioslogserver/logstash/bin/plugin install logstash-filter-nagios
Granted it's adding a separate application+server to your environment. If you have an existing logging solution, the same basic concept should be applicable.
Former Nagios employee
https://www.mcapra.com/
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Nagios log file time format

Post by eloyd »

We actually recommend installing NLS as a free install next to Nagios XI, send the Nagios XI log files to NLS, and then use NLS as an additional verification or "service check" to ensure that Nagios XI is actually running and working well. This is right along with what @mcapra is suggestion, and is basically a "set and forget" type thing (especially if you're virtualized).
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Nagios log file time format

Post by dwhitfield »

Thanks @mcapra and @eloyd!

@bsivavani, did you have any additional questions?
bsivavani
Posts: 339
Joined: Tue Oct 06, 2015 9:17 am

Re: Nagios log file time format

Post by bsivavani »

eloyd wrote:Short version is no. This file is not really intended for reading by humans, it is intended to be parsed by the Nagios XI GUI for log file examination, which will then convert epoch time into local timezone time based on the Nagios XI settings.
@eloyd - Can you guide me the Nagios XI settings where I can covert.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Nagios log file time format

Post by eloyd »

I may not have been clear. There isn't a tool that will convert the format. I mean that when you view the event log from within Nagios, it will show you the times in your local timezone.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Nagios log file time format

Post by gormank »

Convert Unix time to human readable
tail /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'
perl -pe 's/(\d+)/localtime($1)/e' < /usr/local/nagios/var/nagios.log | less

google is your friend :)
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: Nagios log file time format

Post by dwhitfield »

gormank wrote:Convert Unix time to human readable
tail /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'
perl -pe 's/(\d+)/localtime($1)/e' < /usr/local/nagios/var/nagios.log | less
While this is true, I want to make it clear that the nagios will still be printing to the log in epoch.
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: Nagios log file time format

Post by eloyd »

As @dwhitfield said, this doesn't change the log file format.

We actually wrote a Perl library that parses the Nagios log file and allows for essentially field-based regex searching based on time, day, date, month, year, source, type, sequence number, and all sorts of other things. So if the original poster wants to just parse the log file, and perl script would be very capable of doing that.

If, however, which is what I thought they were asking, they'd like the log file to be in a human readable time/date format, then they are simply out of luck.
gormank wrote:Convert Unix time to human readable
tail /usr/local/nagios/var/nagios.log | perl -pe 's/(\d+)/localtime($1)/e'
perl -pe 's/(\d+)/localtime($1)/e' < /usr/local/nagios/var/nagios.log | less

google is your friend :)
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Locked