{enable, disable}_notifications and file name expansion!
Ethan Galstad
nagios at nagios.org
Thu Jan 24 13:31:12 CET 2008
Thomas Guyot-Sionnest wrote:
> Hi,
>
> I just noticed I recently started to have problems using the
> enable/disable notification commands when run from cron. After some
> investigation it turns out the culprit is... file name expansion!
>
> In those scripts the command line is built as this:
>
> cmdline="[$datetime] COMMAND_NAME;$datetime"
>
> and then the following command is run
>
> `$echocmd $cmdline >> $CommandFile`
>
> this result in the following being run (given current timestamp):
>
> `/bin/echo [1199733486] COMMAND_NAME;1199733486 >> $CommandFile`
>
> If you happen to have any of the digits in $datetime as a file name in
> your current folder, it will be expanded by bash. In my case I had a
> file named "1" in /root, and since it's being run by the root crontab it
> turned out to this:
>
> `/bin/echo 1 COMMAND_NAME;1199733486 >> $CommandFile`
>
> which obviously won't work.
>
> There's a few ways to fix this problem:
>
> 1. Quoting the $cmdline in the echocmd arguments:
>
> --- enable_notifications 2008-01-07 10:48:17.000000000 -0800
> +++ enable_notifications 2008-01-07 11:42:01.000000000 -0800
> @@ -23,7 +23,7 @@
> cmdline="[$datetime] ENABLE_NOTIFICATIONS;$datetime"
>
> # append the command to the end of the command file
> -`$echocmd $cmdline >> $CommandFile`
> +`$echocmd "$cmdline" >> $CommandFile`
>
>
>
>
> 2. Backquoting the hooks in $cmdline:
>
> --- enable_notifications 2008-01-07 10:48:17.000000000 -0800
> +++ enable_notifications 2008-01-07 11:44:42.000000000 -0800
> @@ -20,7 +20,7 @@
> datetime=`date +%s`
>
> # create the command line to add to the command file
> -cmdline="[$datetime] ENABLE_NOTIFICATIONS;$datetime"
> +cmdline="\[$datetime\] ENABLE_NOTIFICATIONS;$datetime"
>
> # append the command to the end of the command file
> `$echocmd $cmdline >> $CommandFile`
>
> 3. Uning printf:
> --- enable_notifications 2008-01-07 10:48:17.000000000 -0800
> +++ enable_notifications 2008-01-07 11:49:35.000000000 -0800
> @@ -12,18 +12,15 @@
> # the check_external_commands option in the main
> # configuration file.
>
> -echocmd="/bin/echo"
> +printfcmd="/bin/printf"
>
> CommandFile="/usr/local/nagios/var/rw/nagios.cmd"
>
> # get the current date/time in seconds since UNIX epoch
> datetime=`date +%s`
>
> -# create the command line to add to the command file
> -cmdline="[$datetime] ENABLE_NOTIFICATIONS;$datetime"
> -
> # append the command to the end of the command file
> -`$echocmd $cmdline >> $CommandFile`
> +`$printfcmd "[%i] ENABLE_NOTIFICATIONS;%i\n" $datetime $datetime >>
> $CommandFile`
>
>
>
>
> This should be fixed on both disable_notifications and
> enable_notifications files in contrib/eventhandlers/
>
> Thanks
>
Thanks Thomas - fix will be in CVS shortly.
Ethan Galstad
Nagios Developer
___
Email: nagios at nagios.org
Web: www.nagios.org
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
More information about the Developers
mailing list