Command Path with date variable

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
IT_TECHGENE
Posts: 4
Joined: Mon May 07, 2012 10:46 am

Command Path with date variable

Post by IT_TECHGENE »

Hello to everybody

I want to check some logfiles on a remote Windows Server using check_nt.
To perform this check I use the following command:
./check_nt -H $HOSTNAME$ -p 12489 -v FILEAGE -l C:/stocksystem/Arcotronics/dirlog/01_PC-HOST10052012.log

The check works fine, but my problem is that the logfile 01_PC-HOST10052012.log will change everyday the date:
today: 01_PC-HOST10052012.log
tomorrow: 01_PC-HOST11052012.log

So in the command path I have to set a Variable like:
$USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v FILEAGE -l C:/stocksystem/Arcotronics/dirlog/01_PC-HOST$DATE$.log -w 900-c 1800

The variable $DATE$ I define in resource.cfg like:
$DATE$=date '+%d%m%y' = ex: 10052012

The problem is that it wont work, somebody knows how I can realize a check command with a variable that I can check every day the new logfile?

Thanks
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Command Path with date variable

Post by mguthrie »

You might have to wrap your date command in backticks. If that doesn't work, also try wrapping the full directory path in double quotes in addition to the backticks.
IT_TECHGENE
Posts: 4
Joined: Mon May 07, 2012 10:46 am

Re: Command Path with date variable

Post by IT_TECHGENE »

Yes now I made a script in libexec:

check_nt_fileage_wrapper.sh

content:
#!/bin/bash

DATE=`date +%d%m%Y`
FILENAME=$DATE.log
CMD="/usr/local/nagios/libexec/check_nt -H 192.168.0.44 -p 12489 -v FILEAGE -l "C:/stocksystem/01_HOST-PC""
$CMD$FILENAME

Then I made the command:
define command {
command_name check-Stocksystem-Arcotronics-HOST-PC
command_line $USER1$/check_nt_fileage_wrapper.sh -w $ARG1$ -c $ARG2$
}

And the service:

define service {
host_name srvlogpro2.fercam.msft
service_description Check Arcotronics HOST-PC
use generic-service
check_command check-Stocksystem-Arcotronics-HOST-PC!15!30!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
notification_interval 60
contacts nagiosadmin
contact_groups admins
register 1
}

Now it works :) , thanks
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: Command Path with date variable

Post by agriffin »

Glad you got things figured out!
Locked