External Command question

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

External Command question

Post 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!
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: External Command question

Post 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].
User avatar
BanditBBS
Posts: 2474
Joined: Tue May 31, 2011 12:57 pm
Location: Scio, OH
Contact:

Re: External Command question

Post 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!
2 of XI5.6.14 Prod/DR/DEV - Nagios LogServer 2 Nodes
See my projects on the Exchange at BanditBBS - Also check out my Nagios stuff on my personal page at Bandit's Home and at github
cmerchant
Posts: 546
Joined: Wed Sep 24, 2014 11:19 am

Re: External Command question

Post by cmerchant »

We'll go ahead and close the thread. Thanks.
Locked