{enable, disable}_notifications and file name expansion!

Thomas Guyot-Sionnest thomas at zango.com
Mon Jan 7 20:54:44 CET 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHgoOE6dZ+Kt5BchYRAivoAKD/QX4dEM5XQAPhctGzlEyaCdGf4wCgmOj1
ss+SuRzMEcl+D4klP8l9odg=
=CF5j
-----END PGP SIGNATURE-----

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace




More information about the Developers mailing list