Fire Immediate Check from Command Line

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Fire Immediate Check from Command Line

Post 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.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Fire Immediate Check from Command Line

Post by tmcdonald »

Former Nagios employee
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: Fire Immediate Check from Command Line

Post 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
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Fire Immediate Check from Command Line

Post 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:
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: Fire Immediate Check from Command Line

Post 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
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Fire Immediate Check from Command Line

Post by tmcdonald »

That looks right. Let us know how it works out for you.
Former Nagios employee
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: Fire Immediate Check from Command Line

Post 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
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Fire Immediate Check from Command Line

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
rajasegar
Posts: 1018
Joined: Sun Mar 30, 2014 10:49 pm

Re: Fire Immediate Check from Command Line

Post 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.
5 x Nagios 5.6.9 Enterprise Edition
RHEL 6 & 7
rrdcached & ramdisk optimisation
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Fire Immediate Check from Command Line

Post 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.
Former Nagios employee
Locked