[PATCH 1/1] Additional command link for SCHEDULE_HOST_SVC_DOWNTIME in extinfo.c

Hendrik Baecker andurin at process-zero.de
Wed Sep 16 17:01:36 CEST 2009


The following patch brings an additional link to the command box for the
extinfo.cgi (Host Detail View).
It allows the user to schedule a downtime for a host including every
service on that particular host.
Beside the new link in extinfo.c it adds the support for
SCHEDULE_HOST_SVC_DOWNTIME via cmd.cgi, including the command description.

perl testfile against a local cgi call is also available
---
 cgi/cmd.c            |   25 ++++++++++++++++++++++---
 cgi/extinfo.c        |    2 ++
 t/622extinfo-local.t |   25 +++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 3 deletions(-)
 create mode 100644 t/622extinfo-local.t

diff --git a/cgi/cmd.c b/cgi/cmd.c
index f81514b..9252672 100644
--- a/cgi/cmd.c
+++ b/cgi/cmd.c
@@ -792,6 +792,10 @@ void request_command_data(int cmd){
 		printf("schedule downtime for a particular %s",(cmd==CMD_SCHEDULE_HOST_DOWNTIME)?"host":"service");
 		break;
 
+	case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
+		printf("schedule downtime for all Services for a particular host");
+		break;
+
 	case CMD_PROCESS_HOST_CHECK_RESULT:
 	case CMD_PROCESS_SERVICE_CHECK_RESULT:
 		printf("submit a passive check result for a particular %s",(cmd==CMD_PROCESS_HOST_CHECK_RESULT)?"host":"service");
@@ -1153,6 +1157,7 @@ void request_command_data(int cmd){
 		break;
 		
 	case CMD_SCHEDULE_HOST_DOWNTIME:
+	case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
 	case CMD_SCHEDULE_SVC_DOWNTIME:
 
 		printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
@@ -1641,6 +1646,7 @@ void commit_command_data(int cmd){
 	case CMD_DISABLE_HOST_CHECK:
 	case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
 	case CMD_SCHEDULE_HOST_DOWNTIME:
+	case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
 	case CMD_DELAY_HOST_NOTIFICATION:
 	case CMD_ENABLE_HOST_FLAP_DETECTION:
 	case CMD_DISABLE_HOST_FLAP_DETECTION:
@@ -1652,7 +1658,7 @@ void commit_command_data(int cmd){
 	case CMD_STOP_OBSESSING_OVER_HOST:
 
 		/* make sure we have author name and comment data... */
-		if(cmd==CMD_SCHEDULE_HOST_DOWNTIME){
+		if(cmd==CMD_SCHEDULE_HOST_DOWNTIME||cmd==CMD_SCHEDULE_HOST_SVC_DOWNTIME){
 			if(!strcmp(comment_data,"")){
 				if(!error_string)
 					error_string=strdup("Comment was not entered");
@@ -1669,7 +1675,7 @@ void commit_command_data(int cmd){
 			authorized=TRUE;
 
 		/* clean up the comment data if scheduling downtime */
-		if(cmd==CMD_SCHEDULE_HOST_DOWNTIME){
+		if(cmd==CMD_SCHEDULE_HOST_DOWNTIME||cmd==CMD_SCHEDULE_HOST_SVC_DOWNTIME){
 			clean_comment_data(comment_author);
 			clean_comment_data(comment_data);
 		        }
@@ -1681,7 +1687,7 @@ void commit_command_data(int cmd){
 			}
 
 		/* make sure we have start/end times for downtime (if necessary) */
-		if(cmd==CMD_SCHEDULE_HOST_DOWNTIME && (start_time==(time_t)0 || end_time==(time_t)0 || start_time>end_time)){
+		if((cmd==CMD_SCHEDULE_HOST_DOWNTIME||cmd==CMD_SCHEDULE_HOST_SVC_DOWNTIME) && (start_time==(time_t)0 || end_time==(time_t)0 || start_time>end_time)){
 			if(!error_string)
 				error_string=strdup("Start or end time not valid");
 			}
@@ -2104,6 +2110,10 @@ int commit_command(int cmd){
 		result = cmd_submitf(cmd,"%s;%lu;%lu;%d;%lu;%lu;%s;%s",host_name,start_time,end_time,fixed,triggered_by,duration,comment_author,comment_data);
 		break;
 		
+        case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
+		result = cmd_submitf(cmd,"%s;%lu;%lu;%d;%lu;%lu;%s;%s",host_name,start_time,end_time,fixed,triggered_by,duration,comment_author,comment_data);
+                break;
+
 	case CMD_SCHEDULE_SVC_DOWNTIME:
 		result = cmd_submitf(cmd,"%s;%s;%lu;%lu;%d;%lu;%lu;%s;%s",host_name,service_desc,start_time,end_time,fixed,triggered_by,duration,comment_author,comment_data);
 		break;
@@ -2522,6 +2532,15 @@ void show_command_help(cmd){
 		printf("start and end times you specified) and lasts as long as the duration of time you enter.  The duration fields do not apply for fixed downtime.\n");
 		break;
 
+	case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
+		printf("This command is used to schedule downtime for a particular host and all of his services.  During the specified downtime, Nagios will not send notifications out about the host.\n");
+		printf("When the scheduled downtime expires, Nagios will send out notifications for this host as it normally would.  Scheduled downtimes are preserved\n");
+		printf("across program shutdowns and restarts.  Both the start and end times should be specified in the following format:  <b>mm/dd/yyyy hh:mm:ss</b>.\n");
+		printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify.  If you do not select the <i>fixed</i>\n");
+		printf("option, Nagios will treat this as \"flexible\" downtime.  Flexible downtime starts when the host goes down or becomes unreachable (sometime between the\n");
+		printf("start and end times you specified) and lasts as long as the duration of time you enter.  The duration fields do not apply for fixed downtime.\n");
+		break;
+
 	case CMD_SCHEDULE_SVC_DOWNTIME:
 		printf("This command is used to schedule downtime for a particular service.  During the specified downtime, Nagios will not send notifications out about the service.\n");
 		printf("When the scheduled downtime expires, Nagios will send out notifications for this service as it normally would.  Scheduled downtimes are preserved\n");
diff --git a/cgi/extinfo.c b/cgi/extinfo.c
index 4e7b989..39b982a 100644
--- a/cgi/extinfo.c
+++ b/cgi/extinfo.c
@@ -1264,6 +1264,8 @@ void show_host_info(void){
 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Delay Next Host Notification' TITLE='Delay Next Host Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Delay next host notification</a></td></tr>\n",url_images_path,DELAY_ICON,COMMAND_CGI,CMD_DELAY_HOST_NOTIFICATION,url_encode(host_name));
 
 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Host' TITLE='Schedule Downtime For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for this host</a></td></tr>\n",url_images_path,DOWNTIME_ICON,COMMAND_CGI,CMD_SCHEDULE_HOST_DOWNTIME,url_encode(host_name));
+		
+		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Host and all Services' TITLE='Schedule Downtime For This Host and all Services'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for this host and all Services</a></td></tr>\n",url_images_path,DOWNTIME_ICON,COMMAND_CGI,CMD_SCHEDULE_HOST_SVC_DOWNTIME,url_encode(host_name));
 
 		/*
 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Cancel Scheduled Downtime For This Host' TITLE='Cancel Scheduled Downtime For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Cancel scheduled downtime for this host</a></td></tr>\n",url_images_path,SCHEDULED_DOWNTIME_ICON,COMMAND_CGI,CMD_CANCEL_HOST_DOWNTIME,url_encode(host_name));
diff --git a/t/622extinfo-local.t b/t/622extinfo-local.t
new file mode 100644
index 0000000..dae8289
--- /dev/null
+++ b/t/622extinfo-local.t
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+# 
+# Local Checks for extinfo.cgi
+
+use warnings;
+use strict;
+use Test::More;
+use FindBin qw($Bin);
+
+chdir $Bin or die "Cannot chdir";
+
+my $topdir = "$Bin/..";
+my $cgi_dir = "$topdir/cgi";
+my $extinfo_cgi = "$cgi_dir/extinfo.cgi";
+
+my $output;
+
+plan tests => 2;
+
+$output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REQUEST_METHOD=GET $extinfo_cgi`;
+like( $output, "/Process Information/", "extinfo.cgi without params show the process information" );
+
+$output = `NAGIOS_CGI_CONFIG=etc/cgi.cfg REQUEST_METHOD=GET QUERY_STRING='&type=1&host=host1' $extinfo_cgi`;
+like( $output, "/Schedule downtime for this host and all Services/", "extinfo.cgi allows us to set downtime for a host and all of his services" );
+
-- 
1.6.3.GIT


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf




More information about the Developers mailing list