summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-04-15 08:50:59 (GMT)
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-04-15 08:50:59 (GMT)
commite83aff2ef78406eeaddf0e9dfe4e540bcec1fae8 (patch)
tree6116a431ac3a4750d47d5e2fd590dad37418d337
parent6a564052eab2921b7027a259c5578319dbebde7c (diff)
downloadmonitoring-plugins-e83aff2ef78406eeaddf0e9dfe4e540bcec1fae8.tar.gz
Add thresholds support for check_cluster + lots of standardization.
Add forgotten items to NEWS. git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1688 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--NEWS5
-rw-r--r--plugins/Makefile.am3
-rw-r--r--plugins/check_cluster.c175
3 files changed, 115 insertions, 68 deletions
diff --git a/NEWS b/NEWS
index ed94cd3..6fb2468 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,10 @@
1This file documents the major additions and syntax changes between releases. 1This file documents the major additions and syntax changes between releases.
2 2
31.4.9 ??
4 Inclusion of contrib/check_cluster2 as check_cluster with some improvements
5 Fix the -S option in check_by_ssh
6 check_snmp now support Counter64
7
31.4.8 11th April 2007 81.4.8 11th April 2007
4 Respects --without-world-permissions for setuid plugins 9 Respects --without-world-permissions for setuid plugins
5 check_disk extra options for regex matching of filesystems and grouping of filesystems 10 check_disk extra options for regex matching of filesystems and grouping of filesystems
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 3909dc5..5e3cb0f 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -48,6 +48,7 @@ test:
48# the actual targets 48# the actual targets
49 49
50check_apt_LDADD = $(BASEOBJS) runcmd.o 50check_apt_LDADD = $(BASEOBJS) runcmd.o
51check_cluster_LDADD = $(BASEOBJS)
51check_dig_LDADD = $(NETLIBS) runcmd.o 52check_dig_LDADD = $(NETLIBS) runcmd.o
52check_disk_LDADD = $(BASEOBJS) popen.o 53check_disk_LDADD = $(BASEOBJS) popen.o
53check_dns_LDADD = $(NETLIBS) runcmd.o 54check_dns_LDADD = $(NETLIBS) runcmd.o
@@ -90,7 +91,7 @@ negate_LDADD = $(BASEOBJS) popen.o
90urlize_LDADD = $(BASEOBJS) popen.o 91urlize_LDADD = $(BASEOBJS) popen.o
91 92
92check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS) 93check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS)
93check_cluster_DEPENDENCIES = check_cluster.c $(DEPLIBS) 94check_cluster_DEPENDENCIES = check_cluster.c $(BASEOBJS) $(DEPLIBS)
94check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS) 95check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS)
95check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS) 96check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS)
96check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS) 97check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS)
diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c
index e60948d..98003f1 100644
--- a/plugins/check_cluster.c
+++ b/plugins/check_cluster.c
@@ -3,10 +3,11 @@
3 * CHECK_CLUSTER2.C - Host and Service Cluster Plugin for Nagios 2.x 3 * CHECK_CLUSTER2.C - Host and Service Cluster Plugin for Nagios 2.x
4 * 4 *
5 * Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org) 5 * Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)
6 * Copyright (c) 2007 nagios-plugins team
6 * License: GPL 7 * License: GPL
7 * Last Modified: 03-11-2004 8 * Last Modified: $Date$
8 * 9 *
9 * License: 10 * License Information:
10 * 11 *
11 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
@@ -22,31 +23,21 @@
22 * along with this program; if not, write to the Free Software 23 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * 25 *
25 *****************************************************************************/ 26 * $Id$
27 *
28******************************************************************************/
26 29
30const char *progname = "check_cluster";
31const char *revision = "$Revision$";
32const char *copyright = "2000-2007";
33const char *email = "nagiosplug-devel@lists.sourceforge.net";
27 34
28#include <stdio.h> 35#include "common.h"
29#include <stdlib.h> 36#include "utils.h"
30#include <string.h>
31#include <unistd.h>
32#include <getopt.h>
33
34#define OK 0
35#define ERROR -1
36
37#define TRUE 1
38#define FALSE 0
39 37
40#define CHECK_SERVICES 1 38#define CHECK_SERVICES 1
41#define CHECK_HOSTS 2 39#define CHECK_HOSTS 2
42 40
43#define MAX_INPUT_BUFFER 1024
44
45#define STATE_OK 0
46#define STATE_WARNING 1
47#define STATE_CRITICAL 2
48#define STATE_UNKNOWN 3
49
50int total_services_ok=0; 41int total_services_ok=0;
51int total_services_warning=0; 42int total_services_warning=0;
52int total_services_unknown=0; 43int total_services_unknown=0;
@@ -56,14 +47,15 @@ int total_hosts_up=0;
56int total_hosts_down=0; 47int total_hosts_down=0;
57int total_hosts_unreachable=0; 48int total_hosts_unreachable=0;
58 49
59int warning_threshold=1; 50char *warn_threshold;
60int critical_threshold=1; 51char *crit_threshold;
61 52
62int check_type=CHECK_SERVICES; 53int check_type=CHECK_SERVICES;
63 54
64char *data_vals=NULL; 55char *data_vals=NULL;
65char *label=NULL; 56char *label=NULL;
66 57
58int verbose=0;
67 59
68int process_arguments(int,char **); 60int process_arguments(int,char **);
69 61
@@ -75,33 +67,15 @@ int main(int argc, char **argv){
75 int data_val; 67 int data_val;
76 int return_code=STATE_OK; 68 int return_code=STATE_OK;
77 int error=FALSE; 69 int error=FALSE;
70 thresholds *thresholds;
78 71
79 if(process_arguments(argc,argv)==ERROR){ 72 if(process_arguments(argc,argv)==ERROR)
80 73 usage(_("Could not parse arguments"));
81 printf("Invalid arguments supplied\n"); 74
82 printf("\n"); 75 /* Initialize the thresholds */
83 76 set_thresholds(&thresholds, warn_threshold, crit_threshold);
84 printf("Host/Service Cluster Plugin for Nagios 2\n"); 77 if(verbose)
85 printf("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n"); 78 print_thresholds("check_cluster", thresholds);
86 printf("Last Modified: 03-11-2004\n");
87 printf("License: GPL\n");
88 printf("\n");
89 printf("Usage: %s (-s | -h) [-l label] [-w threshold] [-c threshold] [-d val1,val2,...,valn]\n",argv[0]);
90 printf("\n");
91 printf("Options:\n");
92 printf(" -s, --service = Check service cluster status\n");
93 printf(" -h, --host = Check host cluster status\n");
94 printf(" -l, --label = Optional prepended text output (i.e. \"Host cluster\")\n");
95 printf(" -w, --warning = Specifies the number of hosts or services in cluster that must be in\n");
96 printf(" a non-OK state in order to return a WARNING status level\n");
97 printf(" -c, --critical = Specifies the number of hosts or services in cluster that must be in\n");
98 printf(" a non-OK state in order to return a CRITICAL status level\n");
99 printf(" -d, --data = The status codes of the hosts or services in the cluster, separated\n");
100 printf(" by commas\n");
101 printf("\n");
102
103 return STATE_UNKNOWN;
104 }
105 79
106 /* check the data values */ 80 /* check the data values */
107 for(ptr=strtok(data_vals,",");ptr!=NULL;ptr=strtok(NULL,",")){ 81 for(ptr=strtok(data_vals,",");ptr!=NULL;ptr=strtok(NULL,",")){
@@ -146,22 +120,17 @@ int main(int argc, char **argv){
146 120
147 /* return the status of the cluster */ 121 /* return the status of the cluster */
148 if(check_type==CHECK_SERVICES){ 122 if(check_type==CHECK_SERVICES){
149 if((total_services_warning+total_services_unknown+total_services_critical) >= critical_threshold) 123 return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds);
150 return_code=STATE_CRITICAL; 124 printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
151 else if((total_services_warning+total_services_unknown+total_services_critical) >= warning_threshold) 125 state_text(return_code), (label==NULL)?"Service cluster":label,
152 return_code=STATE_WARNING; 126 total_services_ok,total_services_warning,
153 else 127 total_services_unknown,total_services_critical);
154 return_code=STATE_OK;
155 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);
156 } 128 }
157 else{ 129 else{
158 if((total_hosts_down+total_hosts_unreachable) >= critical_threshold) 130 return_code=get_status(total_hosts_down+total_hosts_unreachable, thresholds);
159 return_code=STATE_CRITICAL; 131 printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n",
160 else if((total_hosts_down+total_hosts_unreachable) >= warning_threshold) 132 state_text(return_code), (label==NULL)?"Host cluster":label,
161 return_code=STATE_WARNING; 133 total_hosts_up,total_hosts_down,total_hosts_unreachable);
162 else
163 return_code=STATE_OK;
164 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);
165 } 134 }
166 135
167 return return_code; 136 return return_code;
@@ -179,6 +148,8 @@ int process_arguments(int argc, char **argv){
179 {"label", required_argument,0,'l'}, 148 {"label", required_argument,0,'l'},
180 {"host", no_argument, 0,'h'}, 149 {"host", no_argument, 0,'h'},
181 {"service", no_argument, 0,'s'}, 150 {"service", no_argument, 0,'s'},
151 {"verbose", no_argument, 0,'v'},
152 {"help", no_argument, 0,'H'},
182 {0,0,0,0} 153 {0,0,0,0}
183 }; 154 };
184 155
@@ -188,7 +159,7 @@ int process_arguments(int argc, char **argv){
188 159
189 while(1){ 160 while(1){
190 161
191 c=getopt_long(argc,argv,"hsw:c:d:l:",longopts,&option); 162 c=getopt_long(argc,argv,"hHsvw:c:d:l:",longopts,&option);
192 163
193 if(c==-1 || c==EOF || c==1) 164 if(c==-1 || c==EOF || c==1)
194 break; 165 break;
@@ -204,11 +175,15 @@ int process_arguments(int argc, char **argv){
204 break; 175 break;
205 176
206 case 'w': /* warning threshold */ 177 case 'w': /* warning threshold */
207 warning_threshold=atoi(optarg); 178 if (strspn (optarg, "0123456789:,") < strlen (optarg))
179 usage2 (_("Invalid warning threshold: %s\n"), optarg);
180 warn_threshold = strdup(optarg);
208 break; 181 break;
209 182
210 case 'c': /* warning threshold */ 183 case 'c': /* warning threshold */
211 critical_threshold=atoi(optarg); 184 if (strspn (optarg, "0123456789:,") < strlen (optarg))
185 usage2 (_("Invalid critical threshold: %s\n"), optarg);
186 crit_threshold = strdup(optarg);
212 break; 187 break;
213 188
214 case 'd': /* data values */ 189 case 'd': /* data values */
@@ -219,6 +194,15 @@ int process_arguments(int argc, char **argv){
219 label=(char *)strdup(optarg); 194 label=(char *)strdup(optarg);
220 break; 195 break;
221 196
197 case 'v': /* verbose */
198 verbose++;
199 break;
200
201 case 'H': /* help */
202 print_help();
203 exit(STATE_UNKNOWN);
204 break;
205
222 default: 206 default:
223 return ERROR; 207 return ERROR;
224 break; 208 break;
@@ -229,4 +213,61 @@ int process_arguments(int argc, char **argv){
229 return ERROR; 213 return ERROR;
230 214
231 return OK; 215 return OK;
232 } 216}
217
218void
219print_help(void)
220{
221 print_revision(progname, revision);
222 printf(COPYRIGHT, copyright, email);
223
224 printf("%s\n", _("Host/Service Cluster Plugin for Nagios 2"));
225
226 print_usage();
227
228
229 printf("%s\n", _("Options:"));
230 printf (" %s\n", "-s, --service");
231 printf (" %s\n", _("Check service cluster status"));
232 printf (" %s\n", "-h, --host");
233 printf (" %s\n", _("Check host cluster status"));
234 printf (" %s\n", "-l, --label=STRING");
235 printf (" %s\n", _("Optional prepended text output (i.e. \"Host cluster\")"));
236 printf (" %s\n", "-w, --warning=THRESHOLD");
237 printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
238 printf (" %s\n", _("non-OK state in order to return a WARNING status level"));
239 printf (" %s\n", "-c, --critical=THRESHOLD");
240 printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
241 printf (" %s\n", _(" non-OK state in order to return a CRITICAL status level"));
242 printf (" %s\n", "-d, --data=LIST");
243 printf (" %s\n", _("The status codes of the hosts or services in the cluster, separated by"));
244 printf (" %s\n", _("commas"));
245
246 printf(_(UT_VERBOSE));
247
248 printf("\n");
249 printf("%s\n", _("Notes:"));
250 printf(" %s\n", _("See:"));
251 printf(" %s\n", _("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
252 printf(" %s\n", _("for THRESHOLD format and examples."));
253
254 printf(_(UT_SUPPORT));
255 printf("\n");
256}
257
258
259void
260print_usage(void)
261{
262
263 printf("\n");
264 printf(_("Usage:"));
265 printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname);
266 printf("[-w threshold] [-c threshold] [-v] [--help]\n");
267 printf("\n");
268
269}
270
271#if 0
272#endif
273