summaryrefslogtreecommitdiffstats
path: root/web/attachments/330612-rangesupport.patch
blob: b32527a970af97906fe987b5b68a6b68aa4bd023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index d038efe..e2b8722 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -65,8 +65,10 @@ int server_port=PORT;
 char *value_list=NULL;
 char *req_password=NULL;
 unsigned long lvalue_list[MAX_VALUE_LIST];
-unsigned long warning_value=0L;
-unsigned long critical_value=0L;
+range *warning_value=NULL;
+range *critical_value=NULL;
+const char *warning_value_string="";
+const char *critical_value_string="";
 int check_warning_value=FALSE;
 int check_critical_value=FALSE;
 enum checkvars vars_to_check = CHECK_NONE;
@@ -81,6 +83,16 @@ int strtoularray(unsigned long *array, char *string, const char *delim);
 void print_help(void);
 void print_usage(void);
 
+bool allnumeric(const char* number)
+{
+	int i;
+	for(i=0; number[i]; i++)
+	{
+		if(number[i]<'0'||number[i]>'9'){return false;}
+	}
+	return true;
+}
+
 int main(int argc, char **argv){
 
 /* should be 	int result = STATE_UNKNOWN; */
@@ -224,8 +236,8 @@ int main(int argc, char **argv){
 
 			if (total_disk_space>0 && free_disk_space>=0) {
 				percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
-				warning_used_space = ((float)warning_value / 100) * total_disk_space;
-				critical_used_space = ((float)critical_value / 100) * total_disk_space;
+				warning_used_space = ((float)(warning_value?warning_value->end:0) / 100) * total_disk_space;
+				critical_used_space = ((float)(critical_value?critical_value->end:0) / 100) * total_disk_space;
 
 				asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
 				  value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824,
@@ -234,12 +246,33 @@ int main(int argc, char **argv){
 				  (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
 				  critical_used_space / 1073741824, total_disk_space / 1073741824);
 
-				if(check_critical_value==TRUE && percent_used_space >= critical_value)
-					return_code=STATE_CRITICAL;
-				else if (check_warning_value==TRUE && percent_used_space >= warning_value)
-					return_code=STATE_WARNING;
-				else
-					return_code=STATE_OK;
+				if(allnumeric(critical_value_string)&&allnumeric(warning_value_string))
+				{
+					if (critical_value > warning_value)
+					{                       /* Normal thresholds */
+						if (check_critical_value == TRUE && percent_used_space >= critical_value->end)
+							return_code = STATE_CRITICAL;
+						else if (check_warning_value == TRUE && percent_used_space >= warning_value->end)
+							return_code = STATE_WARNING;
+						else
+							return_code = STATE_OK;
+					}
+					else
+					{                       /* inverse thresholds */
+						return_code = STATE_OK;
+						if (check_critical_value == TRUE && percent_used_space <= critical_value->end)
+							return_code = STATE_CRITICAL;
+						else if (check_warning_value == TRUE && percent_used_space <= warning_value->end)
+							return_code = STATE_WARNING;
+					}
+				}else{
+					if(check_critical_value==TRUE && check_range(percent_used_space, critical_value))
+						return_code=STATE_CRITICAL;
+					else if (check_warning_value==TRUE && check_range(percent_used_space, warning_value))
+						return_code=STATE_WARNING;
+					else
+						return_code=STATE_OK;
+				}
 
 				output_message = strdup (temp_string);
 				perfdata = temp_string_perf;
@@ -273,8 +306,8 @@ int main(int argc, char **argv){
 		mem_commitLimit=atof(strtok(recv_buffer,"&"));
 		mem_commitByte=atof(strtok(NULL,"&"));
 		percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
-		warning_used_space = ((float)warning_value / 100) * mem_commitLimit;
-		critical_used_space = ((float)critical_value / 100) * mem_commitLimit;
+		warning_used_space = ((float)(warning_value?warning_value->end:0) / 100) * mem_commitLimit;
+		critical_used_space = ((float)(warning_value?critical_value->end:0) / 100) * mem_commitLimit;
 
 		/* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
 		which equals RAM + Pagefiles. */
@@ -284,12 +317,32 @@ int main(int argc, char **argv){
 		asprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567,
 		  warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);
 
-		return_code=STATE_OK;
-		if(check_critical_value==TRUE && percent_used_space >= critical_value)
-			return_code=STATE_CRITICAL;
-		else if (check_warning_value==TRUE && percent_used_space >= warning_value)
-			return_code=STATE_WARNING;
-
+		if(allnumeric(critical_value_string)&&allnumeric(warning_value_string))
+		{
+			if (critical_value > warning_value)
+			{                       /* Normal thresholds */
+				if (check_critical_value == TRUE && percent_used_space >= critical_value->end)
+					return_code = STATE_CRITICAL;
+				else if (check_warning_value == TRUE && percent_used_space >= warning_value->end)
+					return_code = STATE_WARNING;
+				else
+					return_code = STATE_OK;
+			}
+			else
+			{                       /* inverse thresholds */
+				return_code = STATE_OK;
+				if (check_critical_value == TRUE && percent_used_space <= critical_value->end)
+					return_code = STATE_CRITICAL;
+				else if (check_warning_value == TRUE && percent_used_space <= warning_value->end)
+					return_code = STATE_WARNING;
+			}
+		}else{
+			return_code=STATE_OK;
+			if(check_critical_value==TRUE && check_range(percent_used_space, critical_value))
+				return_code=STATE_CRITICAL;
+			else if (check_warning_value==TRUE && check_range(percent_used_space, warning_value))
+				return_code=STATE_WARNING;	
+		}
 		break;
 
 	case CHECK_COUNTER:
@@ -373,29 +426,41 @@ int main(int argc, char **argv){
 					}
 					asprintf (&output_message, "%s |", output_message);
 					asprintf (&output_message,"%s %s", output_message,
-						fperfdata (description, counter_value,
-							counter_unit, 1, warning_value, 1, critical_value,
+						fperfdatarange (description, counter_value, 
+							counter_unit, warning_value_string, critical_value_string,
 							(!(isPercent) && (minval != NULL)), fminval,
 							(!(isPercent) && (minval != NULL)), fmaxval));
 			}
 		}
 
-		if (critical_value > warning_value)
-		{			/* Normal thresholds */
-			if (check_critical_value == TRUE && counter_value >= critical_value)
-				return_code = STATE_CRITICAL;
-			else if (check_warning_value == TRUE && counter_value >= warning_value)
-				return_code = STATE_WARNING;
+		if(allnumeric(critical_value_string)&&allnumeric(warning_value_string))
+		{
+			if (critical_value > warning_value)
+			{                       /* Normal thresholds */
+				if (check_critical_value == TRUE && counter_value >= critical_value->end)
+					return_code = STATE_CRITICAL;
+				else if (check_warning_value == TRUE && counter_value >= warning_value->end)
+					return_code = STATE_WARNING;
+				else
+					return_code = STATE_OK;
+			}
 			else
+			{                       /* inverse thresholds */
 				return_code = STATE_OK;
-		}
-		else
-		{			/* inverse thresholds */
-			return_code = STATE_OK;
-			if (check_critical_value == TRUE && counter_value <= critical_value)
+				if (check_critical_value == TRUE && counter_value <= critical_value->end)
+					return_code = STATE_CRITICAL;
+				else if (check_warning_value == TRUE && counter_value <= warning_value->end)
+					return_code = STATE_WARNING;
+			}
+		}else{
+			if(check_critical_value == TRUE && check_range(counter_value, critical_value))
+			{
 				return_code = STATE_CRITICAL;
-			else if (check_warning_value == TRUE && counter_value <= warning_value)
+			}else if(check_warning_value == TRUE && check_range(counter_value, warning_value)) {
 				return_code = STATE_WARNING;
+			}else{
+				return_code = STATE_OK;
+			}
 		}
 	break;
 
@@ -411,21 +476,34 @@ int main(int argc, char **argv){
 			description = strtok(NULL,"&");
 			output_message = strdup (description);
 
-			if (critical_value > warning_value) {        /* Normal thresholds */
-				if(check_critical_value==TRUE && age_in_minutes >= critical_value)
-					return_code=STATE_CRITICAL;
-				else if (check_warning_value==TRUE && age_in_minutes >= warning_value)
-					return_code=STATE_WARNING;
-				else
-					return_code=STATE_OK;
-			}
-			else {                                       /* inverse thresholds */
-				if(check_critical_value==TRUE && age_in_minutes <= critical_value)
-					return_code=STATE_CRITICAL;
-				else if (check_warning_value==TRUE && age_in_minutes <= warning_value)
-					return_code=STATE_WARNING;
+			if(allnumeric(critical_value_string)&&allnumeric(warning_value_string))
+			{
+				if (critical_value > warning_value)
+				{                       /* Normal thresholds */
+					if (check_critical_value == TRUE && age_in_minutes >= critical_value->end)
+						return_code = STATE_CRITICAL;
+					else if (check_warning_value == TRUE && age_in_minutes >= warning_value->end)
+						return_code = STATE_WARNING;
+					else
+						return_code = STATE_OK;
+				}
 				else
-					return_code=STATE_OK;
+				{                       /* inverse thresholds */
+					return_code = STATE_OK;
+					if (check_critical_value == TRUE && age_in_minutes <= critical_value->end)
+						return_code = STATE_CRITICAL;
+					else if (check_warning_value == TRUE && age_in_minutes <= warning_value->end)
+						return_code = STATE_WARNING;
+				}
+			}else{
+				if(check_critical_value == TRUE && check_range(age_in_minutes, critical_value))
+				{
+					return_code = STATE_CRITICAL;
+				}else if(check_warning_value == TRUE && check_range(age_in_minutes, warning_value)) {
+					return_code = STATE_WARNING;
+				}else{
+					return_code = STATE_OK;
+				}
 			}
 		}
 		break;
@@ -563,11 +641,13 @@ int process_arguments(int argc, char **argv){
 				value_list = optarg;
 				break;
 			case 'w': /* warning threshold */
-				warning_value=strtoul(optarg,NULL,10);
+				warning_value=parse_range_string(optarg);
+				warning_value_string=optarg;
 				check_warning_value=TRUE;
 				break;
 			case 'c': /* critical threshold */
-				critical_value=strtoul(optarg,NULL,10);
+				critical_value=parse_range_string(optarg);
+				critical_value_string=optarg;
 				check_critical_value=TRUE;
 				break;
 			case 'd': /* Display select for services */
diff --git a/plugins/utils.c b/plugins/utils.c
index 4537390..f4f6433 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -600,3 +600,44 @@ char *fperfdata (const char *label,
 
 	return data;
 }
+
+char *fperfdatarange (const char *label,
+ double val,
+ const char *uom,
+ const char *warn,
+ const char *crit,
+ int minp,
+ double minv,
+ int maxp,
+ double maxv)
+{
+	char *data = NULL;
+
+	if (strpbrk (label, "'= "))
+		asprintf (&data, "'%s'=", label);
+	else
+		asprintf (&data, "%s=", label);
+
+	asprintf (&data, "%s%f", data, val);
+	asprintf (&data, "%s%s;", data, uom);
+
+	if (warn)
+		asprintf (&data, "%s%s", data, warn);
+
+	asprintf (&data, "%s;", data);
+
+	if (crit)
+		asprintf (&data, "%s%s", data, crit);
+
+	asprintf (&data, "%s;", data);
+
+	if (minp)
+		asprintf (&data, "%s%f", data, minv);
+
+	if (maxp) {
+		asprintf (&data, "%s;", data);
+		asprintf (&data, "%s%f", data, maxv);
+	}
+
+	return data;
+}
diff --git a/plugins/utils.h b/plugins/utils.h
index d6e9c8f..bd8fe1d 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -121,6 +121,16 @@ char *fperfdata (const char *,
  int,
  double);
 
+char *fperfdatarange (const char *,
+ double,
+ const char *,
+ const char *,
+ const char *,
+ int,
+ double,
+ int,
+ double);
+
 /* The idea here is that, although not every plugin will use all of these, 
    most will or should.  Therefore, for consistency, these very common 
    options should have only these meanings throughout the overall suite */