How to change $DATE variable format

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
gsl_ops_practice
Posts: 151
Joined: Thu Apr 09, 2015 9:14 pm

How to change $DATE variable format

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: How to change $DATE variable format

Post 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.
Former Nagios employee
gsl_ops_practice
Posts: 151
Joined: Thu Apr 09, 2015 9:14 pm

Re: How to change $DATE variable format

Post 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
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: How to change $DATE variable format

Post 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.
Former Nagios employee
gsl_ops_practice
Posts: 151
Joined: Thu Apr 09, 2015 9:14 pm

Re: How to change $DATE variable format

Post 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$'!!!!!!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: How to change $DATE variable format

Post 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
Be sure to check out our Knowledgebase for helpful articles and solutions!
gsl_ops_practice
Posts: 151
Joined: Thu Apr 09, 2015 9:14 pm

Re: How to change $DATE variable format

Post 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.
Locked