summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2004-03-12 03:40:57 (GMT)
committerEthan Galstad <egalstad@users.sourceforge.net>2004-03-12 03:40:57 (GMT)
commit3bb09aa98c5a2ae3477f2c51370390deea2959d7 (patch)
treef44e0503e3284ec7df3b2e7513a3f6155cb45a7a
parent82cacea05586b63d3445473464bb45a9da22b89f (diff)
downloadmonitoring-plugins-3bb09aa98c5a2ae3477f2c51370390deea2959d7.tar.gz
New cluster plugin for Nagios 2.x
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@847 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r--contrib/check_cluster2.c232
1 files changed, 232 insertions, 0 deletions
diff --git a/contrib/check_cluster2.c b/contrib/check_cluster2.c
new file mode 100644
index 0000000..e60948d
--- /dev/null
+++ b/contrib/check_cluster2.c
@@ -0,0 +1,232 @@
1/*****************************************************************************
2 *
3 * CHECK_CLUSTER2.C - Host and Service Cluster Plugin for Nagios 2.x
4 *
5 * Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)
6 * License: GPL
7 * Last Modified: 03-11-2004
8 *
9 * License:
10 *
11 * 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 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 *****************************************************************************/
26
27
28#include <stdio.h>
29#include <stdlib.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
40#define CHECK_SERVICES 1
41#define CHECK_HOSTS 2
42
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;
51int total_services_warning=0;
52int total_services_unknown=0;
53int total_services_critical=0;
54
55int total_hosts_up=0;
56int total_hosts_down=0;
57int total_hosts_unreachable=0;
58
59int warning_threshold=1;
60int critical_threshold=1;
61
62int check_type=CHECK_SERVICES;
63
64char *data_vals=NULL;
65char *label=NULL;
66
67
68int process_arguments(int,char **);
69
70
71
72int main(int argc, char **argv){
73 char input_buffer[MAX_INPUT_BUFFER];
74 char *ptr;
75 int data_val;
76 int return_code=STATE_OK;
77 int error=FALSE;
78
79 if(process_arguments(argc,argv)==ERROR){
80
81 printf("Invalid arguments supplied\n");
82 printf("\n");
83
84 printf("Host/Service Cluster Plugin for Nagios 2\n");
85 printf("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n");
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
106 /* check the data values */
107 for(ptr=strtok(data_vals,",");ptr!=NULL;ptr=strtok(NULL,",")){
108
109 data_val=atoi(ptr);
110
111 if(check_type==CHECK_SERVICES){
112 switch(data_val){
113 case 0:
114 total_services_ok++;
115 break;
116 case 1:
117 total_services_warning++;
118 break;
119 case 2:
120 total_services_critical++;
121 break;
122 case 3:
123 total_services_unknown++;
124 break;
125 default:
126 break;
127 }
128 }
129 else{
130 switch(data_val){
131 case 0:
132 total_hosts_up++;
133 break;
134 case 1:
135 total_hosts_down++;
136 break;
137 case 2:
138 total_hosts_unreachable++;
139 break;
140 default:
141 break;
142 }
143 }
144 }
145
146
147 /* return the status of the cluster */
148 if(check_type==CHECK_SERVICES){
149 if((total_services_warning+total_services_unknown+total_services_critical) >= critical_threshold)
150 return_code=STATE_CRITICAL;
151 else if((total_services_warning+total_services_unknown+total_services_critical) >= warning_threshold)
152 return_code=STATE_WARNING;
153 else
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 }
157 else{
158 if((total_hosts_down+total_hosts_unreachable) >= critical_threshold)
159 return_code=STATE_CRITICAL;
160 else if((total_hosts_down+total_hosts_unreachable) >= warning_threshold)
161 return_code=STATE_WARNING;
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 }
166
167 return return_code;
168 }
169
170
171
172int process_arguments(int argc, char **argv){
173 int c;
174 int option=0;
175 static struct option longopts[]={
176 {"data", required_argument,0,'d'},
177 {"warning", required_argument,0,'w'},
178 {"critical", required_argument,0,'c'},
179 {"label", required_argument,0,'l'},
180 {"host", no_argument, 0,'h'},
181 {"service", no_argument, 0,'s'},
182 {0,0,0,0}
183 };
184
185 /* no options were supplied */
186 if(argc<2)
187 return ERROR;
188
189 while(1){
190
191 c=getopt_long(argc,argv,"hsw:c:d:l:",longopts,&option);
192
193 if(c==-1 || c==EOF || c==1)
194 break;
195
196 switch(c){
197
198 case 'h': /* host cluster */
199 check_type=CHECK_HOSTS;
200 break;
201
202 case 's': /* service cluster */
203 check_type=CHECK_SERVICES;
204 break;
205
206 case 'w': /* warning threshold */
207 warning_threshold=atoi(optarg);
208 break;
209
210 case 'c': /* warning threshold */
211 critical_threshold=atoi(optarg);
212 break;
213
214 case 'd': /* data values */
215 data_vals=(char *)strdup(optarg);
216 break;
217
218 case 'l': /* text label */
219 label=(char *)strdup(optarg);
220 break;
221
222 default:
223 return ERROR;
224 break;
225 }
226 }
227
228 if(data_vals==NULL)
229 return ERROR;
230
231 return OK;
232 }