This is for the host's services:
Command:
curl -d "cmd_typ=86&cmd_mod=2&host=centos03&com_data=TestingDowntime&trigger=0&start_time=03-13-2015 11:30:00&end_time=03-13-2015 11:40:00&fixed=1&childoptions=0&btnSubmit=Commit" "http://xitest/nagios/cgi-bin/cmd.cgi" -u "troylea:password"
The output you receive for the commands is a http page, but most importantly you are after this message:
Scheduling Downtime On The Nagios Host - Recurring
Let's say you wanted to schedule downtime from 15:00 to 16:00 every day for a host and it's services. These commands could be run from a cron job at 00:05 every day to achieve that
This is for the host object:
Command:
now_epoch=$(eval date +%s); start_epoch=$(date +'%F 15:00:00' | xargs -0 date +%s -d); end_epoch=$(date +'%F 16:00:00' | xargs -0 date +%s -d); printf "[$now_epoch] SCHEDULE_HOST_DOWNTIME;centos01;$start_epoch;$end_epoch;1;0;;nagiosadmin;Daily Downtime\n" > /usr/local/nagios/var/rw/nagios.cmd
This is for the host's services:
Command:
now_epoch=$(eval date +%s); start_epoch=$(date +'%F 15:00:00' | xargs -0 date +%s -d); end_epoch=$(date +'%F 16:00:00' | xargs -0 date +%s -d); printf "[$now_epoch] SCHEDULE_HOST_SVC_DOWNTIME;centos01;$start_epoch;$end_epoch;1;0;;nagiosadmin;Daily Downtime\n" > /usr/local/nagios/var/rw/nagios.cmd
You will not receive any output however if you tail the nagios.log
you'll see entries like this:
Output:
[1457318760] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;centos01;1457323200;1457326800;1;0;;nagiosadmin;Daily Downtime
[1457318879] EXTERNAL COMMAND: SCHEDULE_HOST_SVC_DOWNTIME;centos01;1457323200;1457326800;1;0;;nagiosadmin;Daily Downtime
Adding Comments Locally From Nagios Host
This is for the host object:
Command:
now_epoch=$(eval date +%s); printf "[$now_epoch] ADD_HOST_COMMENT;centos03;1;nagiosadmin;This host does funny stuff\n" > /usr/local/nagios/var/rw/nagios.cmd
This is for a service object:
Command:
now_epoch=$(eval date +%s); printf "[$now_epoch] ADD_SVC_COMMENT;centos03;Total Processes;1;nagiosadmin;Keep an eye on this service\n" > /usr/local/nagios/var/rw/nagios.cmd
Disable/Enable Notifications Globally On Nagios Host
Disable
Command:
now_epoch=$(eval date +%s); printf "[$now_epoch] DISABLE_NOTIFICATIONS\n" > /usr/local/nagios/var/rw/nagios.cmd
Enable
Command:
now_epoch=$(eval date +%s); printf "[$now_epoch] ENABLE_NOTIFICATIONS\n" > /usr/local/nagios/var/rw/nagios.cmd
Submit Passive Check Result On Nagios Host
For a host object:
Command:
now_epoch=$(eval date +%s); printf
"[$now_epoch] PROCESS_HOST_CHECK_RESULT;Important_Host;0;This is the host output\n" >
/usr/local/nagios/var/rw/nagios.cmd
For a service object:
Command:
now_epoch=$(eval date +%s); printf "[$now_epoch] PROCESS_SERVICE_CHECK_RESULT;Important_Host;Check Disk /;0;This is the service output\n" > /usr/local/nagios/var/rw/nagios.cmd
Force Immediate Check From A Remote Host
We can use curl to do this.
This is for the host object:
Command:
curl --data "cmd_typ=96" --data "cmd_mod=2" --data "host=localhost" --data "start_time=07-11-2016 14:04:40" --data "force_check=1"
"http://xitest/nagios/cgi-bin/cmd.cgi" -u "troylea:password"
This is for the host's services:
Command:
curl --data "cmd_typ=7" --data "cmd_mod=2" --data "host=localhost" --data "service=PING" --data "start_time=07-11-2016 12:25:18" --data "force_check=1"
"http://xitest/nagios/cgi-bin/cmd.cgi" -u "troylea:password"
The output you receive for the commands is a http page, but most importantly you are after this message:
Output:
<P><DIV
CLASS='infoMessage'>Your command request was successfully submitted
to Nagios for processing.<BR><BR>
Note: It may take a while before the command is actually processed.<BR><BR>