Page 1 of 1
Fire Immediate Check from Command Line
Posted: Sun Sep 28, 2014 9:36 pm
by rajasegar
NagiosXI 2014R1.2
RHEL 6.5
If there a way to trigger immediate check for a service from the command line?
Please advice how to go about this.
Thanks.
Re: Fire Immediate Check from Command Line
Posted: Mon Sep 29, 2014 9:06 am
by tmcdonald
Re: Fire Immediate Check from Command Line
Posted: Mon Sep 29, 2014 6:13 pm
by rajasegar
SCHEDULE_FORCED_HOST_CHECK;<host_name>;<check_time>
Code: Select all
#!/bin/sh
# This is a sample shell script showing how you can submit the SCHEDULE_FORCED_HOST_CHECK command
# to Nagios. Adjust variables to fit your environment as necessary.
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'
/bin/printf "[%lu] SCHEDULE_FORCED_HOST_CHECK;host1;1110741500\n" $now > $commandfile
Why is 1110741500 hard coded in the script? Shouldn't this be the actual check time?
BTW, in RHEL 6.5 printf is in /usr/bin
Re: Fire Immediate Check from Command Line
Posted: Tue Sep 30, 2014 9:20 am
by slansing
Yeah, that was probably written a while ago. The example timestamp would need to be changed, as you can see at the top of that quoted code block:
Shell Script Usage Example:
Re: Fire Immediate Check from Command Line
Posted: Tue Sep 30, 2014 5:58 pm
by rajasegar
slansing wrote:Yeah, that was probably written a while ago. The example timestamp would need to be changed, as you can see at the top of that quoted code block:
Shell Script Usage Example:
Code: Select all
Old
/bin/printf "[%lu] SCHEDULE_FORCED_HOST_CHECK;host1;1110741500\n" $now > $commandfile
Will change to the following and test it out.
/usr/bin/printf "[%lu] SCHEDULE_FORCED_HOST_CHECK;host1;$now\n" $now > $commandfile
Re: Fire Immediate Check from Command Line
Posted: Wed Oct 01, 2014 9:15 am
by tmcdonald
That looks right. Let us know how it works out for you.
Re: Fire Immediate Check from Command Line
Posted: Wed Oct 01, 2014 6:10 pm
by rajasegar
tmcdonald wrote:That looks right. Let us know how it works out for you.
One more question. Is there a way to execute reports from the script using wget etc?
I need the state history report in CSV in the nagios server for some processing.
Reports->State History
Re: Fire Immediate Check from Command Line
Posted: Thu Oct 02, 2014 12:26 pm
by abrist
You can get the statehistory csv from the cli (but you will need an active session (or valid ticketid) to get it:
Code: Select all
curl "http://<ip>/nagiosxi/reports/statehistory.php?1&host=<hostname>&service=<optional service description>&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=hard&reporttimesubmitbutton=Update&manual_run=1&page=1&records=25&mode=csv&username=<nagios xi user>&ticket=<xi user ticket id>"
You will have to explore the different get parameters for yourself.
Re: Fire Immediate Check from Command Line
Posted: Thu Oct 02, 2014 6:08 pm
by rajasegar
abrist wrote:You can get the statehistory csv from the cli (but you will need an active session (or valid ticketid) to get it:
Code: Select all
curl "http://<ip>/nagiosxi/reports/statehistory.php?1&host=<hostname>&service=<optional service description>&search=&reportperiod=last24hours&startdate=&enddate=&hostgroup=&servicegroup=&statetype=hard&reporttimesubmitbutton=Update&manual_run=1&page=1&records=25&mode=csv&username=<nagios xi user>&ticket=<xi user ticket id>"
You will have to explore the different get parameters for yourself.
Thanks I will check this out.
Re: Fire Immediate Check from Command Line
Posted: Fri Oct 03, 2014 9:04 am
by tmcdonald
Let us know how it turns out. We'll keep the thread open for a little bit in case you do have questions.