Page 1 of 1

How to change $DATE variable format

Posted: Tue May 12, 2015 10:13 am
by gsl_ops_practice
Hello,

After a fair bit of googling I can't find an obvious way to change the format of the $DATE$ variable.

Trying to monitor log files whose names end with YYYYMMDD, $DATE$ gives me MM-DD-YYYY.

Thank you.

Re: How to change $DATE variable format

Posted: Tue May 12, 2015 10:20 am
by tmcdonald
There are a few options to change it, but none appear to match what you need:

http://nagios.sourceforge.net/docs/3_0/ ... ate_format

We can put in a Core feature request for additional formats if you would like, but that would take some time to implement. The faster option, if possible depending on how you are using this, is to use a wrapper script to provide the date format.

Re: How to change $DATE variable format

Posted: Tue May 12, 2015 10:28 am
by gsl_ops_practice
Hi,

Can you please how I would go about setting up a wrapper script? Definitely faster than waiting for a feature to be added :)

Thanks,
Alex

Re: How to change $DATE variable format

Posted: Tue May 12, 2015 10:43 am
by tmcdonald
Sure thing. First I need to see how you are monitoring these logs. Can you post the check command and plugin you are using? The more info I have about the setup the better.

Re: How to change $DATE variable format

Posted: Tue May 12, 2015 10:46 am
by gsl_ops_practice
This is my command definition, we deployed a check_file_age script on all of our hosts that we need to monitor.

check_nrpe!check_file_age!-a '-w 3600 -c 5400 -f /home/application/apps/cli/log/cli-message-details.log.$DATE$'!!!!!!

Re: How to change $DATE variable format

Posted: Tue May 12, 2015 12:27 pm
by lmiltchev
You could create a bash script, i.e. "check_file_age_wrapper".

Code: Select all

#!/bin/bash

d=`date +%Y%m%d`
/usr/local/nagios/libexec/check_file_age -w $1 -c $2 -f $3.$d
and use it as such:

Code: Select all

/usr/local/nagios/libexec/check_file_age_wrapper 3600 5400 /home/application/apps/cli/log/cli-message-details.log

Re: How to change $DATE variable format

Posted: Tue May 12, 2015 1:14 pm
by gsl_ops_practice
I had to add a new check with a new name and then the wrapper script started to return valid results.

Thank for your help, please mark this thread closed.