[Nagiosplug-checkins] nagiosplug/plugins Makefile.am, 1.76, 1.77 check_cluster.c, 1.1, 1.2

Thomas Guyot dermoth at users.sourceforge.net
Sun Apr 15 10:51:01 CEST 2007


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs16:/tmp/cvs-serv31014/plugins

Modified Files:
	Makefile.am check_cluster.c 
Log Message:
Add thresholds support for check_cluster + lots of standardization.
Add forgotten items to NEWS.


Index: Makefile.am
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/Makefile.am,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- Makefile.am	13 Apr 2007 11:35:13 -0000	1.76
+++ Makefile.am	15 Apr 2007 08:50:58 -0000	1.77
@@ -48,6 +48,7 @@
 # the actual targets
 
 check_apt_LDADD = $(BASEOBJS) runcmd.o
+check_cluster_LDADD = $(BASEOBJS)
 check_dig_LDADD = $(NETLIBS) runcmd.o 
 check_disk_LDADD = $(BASEOBJS) popen.o
 check_dns_LDADD = $(NETLIBS) runcmd.o
@@ -90,7 +91,7 @@
 urlize_LDADD = $(BASEOBJS) popen.o
 
 check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS)
-check_cluster_DEPENDENCIES = check_cluster.c $(DEPLIBS)
+check_cluster_DEPENDENCIES = check_cluster.c $(BASEOBJS) $(DEPLIBS)
 check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS)
 check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS) 
 check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS)

Index: check_cluster.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_cluster.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- check_cluster.c	13 Apr 2007 11:35:13 -0000	1.1
+++ check_cluster.c	15 Apr 2007 08:50:58 -0000	1.2
@@ -3,10 +3,11 @@
  * CHECK_CLUSTER2.C - Host and Service Cluster Plugin for Nagios 2.x
  *
  * Copyright (c) 2000-2004 Ethan Galstad (nagios at nagios.org)
+ * Copyright (c) 2007 nagios-plugins team
  * License: GPL
- * Last Modified:   03-11-2004
+ * Last Modified: $Date$
  *
- * License:
+ * License Information:
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,31 +23,21 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- *****************************************************************************/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
+ * $Id$
+ * 
+******************************************************************************/
 
-#define OK		0
-#define ERROR		-1
+const char *progname = "check_cluster";
+const char *revision = "$Revision$";
+const char *copyright = "2000-2007";
+const char *email = "nagiosplug-devel at lists.sourceforge.net";
 
-#define TRUE		1
-#define FALSE		0
+#include "common.h"
+#include "utils.h"
 
 #define CHECK_SERVICES	1
 #define CHECK_HOSTS	2
 
-#define MAX_INPUT_BUFFER	1024
-
-#define STATE_OK	0
-#define STATE_WARNING	1
-#define STATE_CRITICAL	2
-#define STATE_UNKNOWN	3
-
 int total_services_ok=0;
 int total_services_warning=0;
 int total_services_unknown=0;
@@ -56,14 +47,15 @@
 int total_hosts_down=0;
 int total_hosts_unreachable=0;
 
-int warning_threshold=1;
-int critical_threshold=1;
+char *warn_threshold;
+char *crit_threshold;
 
 int check_type=CHECK_SERVICES;
 
 char *data_vals=NULL;
 char *label=NULL;
 
+int verbose=0;
 
 int process_arguments(int,char **);
 
@@ -75,33 +67,15 @@
 	int data_val;
 	int return_code=STATE_OK;
 	int error=FALSE;
+	thresholds *thresholds;
 
-	if(process_arguments(argc,argv)==ERROR){
-
-		printf("Invalid arguments supplied\n");
-		printf("\n");
-
-		printf("Host/Service Cluster Plugin for Nagios 2\n");
-		printf("Copyright (c) 2000-2004 Ethan Galstad (nagios at nagios.org)\n");
-		printf("Last Modified: 03-11-2004\n");
-		printf("License: GPL\n");
-		printf("\n");
-		printf("Usage: %s (-s | -h) [-l label] [-w threshold] [-c threshold] [-d val1,val2,...,valn]\n",argv[0]);
-		printf("\n");
-		printf("Options:\n");
-		printf("   -s, --service  = Check service cluster status\n");
-		printf("   -h, --host     = Check host cluster status\n");
-		printf("   -l, --label    = Optional prepended text output (i.e. \"Host cluster\")\n");
-		printf("   -w, --warning  = Specifies the number of hosts or services in cluster that must be in\n");
-		printf("                    a non-OK state in order to return a WARNING status level\n");
-		printf("   -c, --critical = Specifies the number of hosts or services in cluster that must be in\n");
-		printf("                    a non-OK state in order to return a CRITICAL status level\n");
-		printf("   -d, --data     = The status codes of the hosts or services in the cluster, separated\n");
-		printf("                    by commas\n");
-		printf("\n");
+	if(process_arguments(argc,argv)==ERROR)
+		usage(_("Could not parse arguments"));
 
-		return STATE_UNKNOWN;
-	        }
+	/* Initialize the thresholds */
+	set_thresholds(&thresholds, warn_threshold, crit_threshold);
+	if(verbose)
+		print_thresholds("check_cluster", thresholds);
 
 	/* check the data values */
 	for(ptr=strtok(data_vals,",");ptr!=NULL;ptr=strtok(NULL,",")){
@@ -146,22 +120,17 @@
 
 	/* return the status of the cluster */
 	if(check_type==CHECK_SERVICES){
-		if((total_services_warning+total_services_unknown+total_services_critical) >= critical_threshold)
-			return_code=STATE_CRITICAL;
-		else if((total_services_warning+total_services_unknown+total_services_critical) >= warning_threshold)
-			return_code=STATE_WARNING;
-		else
-			return_code=STATE_OK;
-		printf("%s %s: %d ok, %d warning, %d unknown, %d critical\n",(label==NULL)?"Service cluster":label,(return_code==STATE_OK)?"ok":"problem",total_services_ok,total_services_warning,total_services_unknown,total_services_critical);
+		return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds);
+		printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
+			state_text(return_code), (label==NULL)?"Service cluster":label,
+			total_services_ok,total_services_warning,
+			total_services_unknown,total_services_critical);
                 }
 	else{
-		if((total_hosts_down+total_hosts_unreachable) >= critical_threshold)
-			return_code=STATE_CRITICAL;
-		else if((total_hosts_down+total_hosts_unreachable) >= warning_threshold)
-			return_code=STATE_WARNING;
-		else
-			return_code=STATE_OK;
-		printf("%s %s: %d up, %d down, %d unreachable\n",(label==NULL)?"Host cluster":label,(return_code==STATE_OK)?"ok":"problem",total_hosts_up,total_hosts_down,total_hosts_unreachable);
+		return_code=get_status(total_hosts_down+total_hosts_unreachable, thresholds);
+		printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n",
+			state_text(return_code), (label==NULL)?"Host cluster":label,
+			total_hosts_up,total_hosts_down,total_hosts_unreachable);
                 }
 
 	return return_code;
@@ -179,6 +148,8 @@
 		{"label",    required_argument,0,'l'},
 		{"host",     no_argument,      0,'h'},
 		{"service",  no_argument,      0,'s'},
+		{"verbose",  no_argument,      0,'v'},
+		{"help",     no_argument,      0,'H'},
 		{0,0,0,0}
 		};
 
@@ -188,7 +159,7 @@
 
 	while(1){
 
-		c=getopt_long(argc,argv,"hsw:c:d:l:",longopts,&option);
+		c=getopt_long(argc,argv,"hHsvw:c:d:l:",longopts,&option);
 
 		if(c==-1 || c==EOF || c==1)
 			break;
@@ -204,11 +175,15 @@
 			break;
 
 		case 'w': /* warning threshold */
-			warning_threshold=atoi(optarg);
+			if (strspn (optarg, "0123456789:,") < strlen (optarg))
+				usage2 (_("Invalid warning threshold: %s\n"), optarg);
+			warn_threshold = strdup(optarg);
 			break;
 
 		case 'c': /* warning threshold */
-			critical_threshold=atoi(optarg);
+			if (strspn (optarg, "0123456789:,") < strlen (optarg))
+				usage2 (_("Invalid critical threshold: %s\n"), optarg);
+			crit_threshold = strdup(optarg);
 			break;
 
 		case 'd': /* data values */
@@ -219,6 +194,15 @@
 			label=(char *)strdup(optarg);
 			break;
 
+		case 'v': /* verbose */
+			verbose++;
+			break;
+
+		case 'H': /* help */
+			print_help();
+			exit(STATE_UNKNOWN);
+			break;
+
 		default:
 			return ERROR;
 			break;
@@ -229,4 +213,61 @@
 		return ERROR;
 
 	return OK;
-        }
+}
+
+void
+print_help(void)
+{
+	print_revision(progname, revision);
+	printf(COPYRIGHT, copyright, email);
+
+	printf("%s\n", _("Host/Service Cluster Plugin for Nagios 2"));
+
+	print_usage();
+
+
+	printf("%s\n", _("Options:"));
+	printf (" %s\n", "-s, --service");
+	printf ("    %s\n", _("Check service cluster status"));
+	printf (" %s\n", "-h, --host");
+	printf ("    %s\n", _("Check host cluster status"));
+	printf (" %s\n", "-l, --label=STRING");
+	printf ("    %s\n", _("Optional prepended text output (i.e. \"Host cluster\")"));
+	printf (" %s\n", "-w, --warning=THRESHOLD");
+	printf ("    %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
+	printf ("    %s\n", _("non-OK state in order to return a WARNING status level"));
+	printf (" %s\n", "-c, --critical=THRESHOLD");
+	printf ("    %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
+	printf ("    %s\n", _(" non-OK state in order to return a CRITICAL status level"));
+	printf (" %s\n", "-d, --data=LIST");
+	printf ("    %s\n", _("The status codes of the hosts or services in the cluster, separated by"));
+	printf ("    %s\n", _("commas"));
+
+	printf(_(UT_VERBOSE));
+
+	printf("\n");
+	printf("%s\n", _("Notes:"));
+	printf(" %s\n", _("See:"));
+	printf(" %s\n", _("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
+	printf(" %s\n", _("for THRESHOLD format and examples."));
+
+	printf(_(UT_SUPPORT));
+	printf("\n");
+}
+
+
+void
+print_usage(void)
+{
+
+	printf("\n");
+	printf(_("Usage:"));
+	printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname);
+	printf("[-w threshold] [-c threshold] [-v] [--help]\n");
+	printf("\n");
+
+}
+
+#if 0
+#endif
+





More information about the Commits mailing list