Page 1 of 1

External Command question

Posted: Fri Mar 20, 2015 1:21 pm
by BanditBBS
So, I created a new downtime scheduling component based on XI's recurring downtime component. Everything works great, we're using it, except one thing, the creation date always says 12-31-1969.

In the examples online it is written like this:

Code: Select all

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/bin/printf "[%lu] SCHEDULE_HOST_SVC_DOWNTIME;host1;1110741500;1110748700;0;0;7200;Some One;Some Downtime Comment\n" $now > $commandfile
Two questions about that...what on earth is the [%lu] doing? and it's printing all that to the command file as well as the $now variable, right? I'm only writing the stuff in the quotes, including the [%LU]. That includes a \n newline, so I'm having trouble understanding where the $now variable comes into play there.

In php I'm building a variable $cfg_str and then this code is used:

Code: Select all

    $fh = fopen('/usr/local/nagios/var/rw/nagios.cmd', "a") or die(gettext("Error: Could not open downtime config file for writing."));
    fwrite($fh, $cfg_str);
    fclose($fh);
I need to add the $now(or whatever I name it) to the commandfile on the next line? Oh god...someone help me figure out what i have to do, not how to(I can do that).

Thanks!

Re: External Command question

Posted: Fri Mar 20, 2015 1:49 pm
by ssax
The %lu (long unsigned) is a placeholder for the $now data, printf basically takes the value of $now (seconds since unix epoch) and inserts it between the brackets [1426876754].

Re: External Command question

Posted: Fri Mar 20, 2015 1:57 pm
by BanditBBS
ssax wrote:The %lu (long unsigned) is a placeholder for the $now data, printf basically takes the value of $now (seconds since unix epoch) and inserts it between the brackets [1426876754].
Thanks ssax, that helped me fix it :)

Code: Select all

Host Name	Entry Time	Author	Comment	Start Time	End Time	Type	Duration	Downtime ID	Trigger ID	Actions
host003	03-20-2015 14:03:22	jclark	Test	03-21-2015 01:00:00	03-21-2015 02:00:00	Fixed	0d 1h 0m 0s	645	N/A
Now I'm working great!

Re: External Command question

Posted: Fri Mar 20, 2015 2:12 pm
by cmerchant
We'll go ahead and close the thread. Thanks.