diff options
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r-- | plugins/check_nt.c | 369 |
1 files changed, 162 insertions, 207 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 22e7757d..b1314d4b 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
@@ -33,19 +33,23 @@ | |||
33 | #include "netutils.h" | 33 | #include "netutils.h" |
34 | #include "utils.h" | 34 | #include "utils.h" |
35 | 35 | ||
36 | #define CHECK_NONE 0 | 36 | enum checkvars { |
37 | #define CHECK_CLIENTVERSION 1 | 37 | CHECK_NONE, |
38 | #define CHECK_CPULOAD 2 | 38 | CHECK_CLIENTVERSION, |
39 | #define CHECK_UPTIME 3 | 39 | CHECK_CPULOAD, |
40 | #define CHECK_USEDDISKSPACE 4 | 40 | CHECK_UPTIME, |
41 | #define CHECK_SERVICESTATE 5 | 41 | CHECK_USEDDISKSPACE, |
42 | #define CHECK_PROCSTATE 6 | 42 | CHECK_SERVICESTATE, |
43 | #define CHECK_MEMUSE 7 | 43 | CHECK_PROCSTATE, |
44 | #define CHECK_COUNTER 8 | 44 | CHECK_MEMUSE, |
45 | #define CHECK_FILEAGE 9 | 45 | CHECK_COUNTER, |
46 | #define MAX_VALUE_LIST 30 | 46 | CHECK_FILEAGE |
47 | 47 | }; | |
48 | #define PORT 1248 | 48 | |
49 | enum { | ||
50 | MAX_VALUE_LIST = 30, | ||
51 | PORT = 1248 | ||
52 | }; | ||
49 | 53 | ||
50 | char *server_address=NULL; | 54 | char *server_address=NULL; |
51 | char *volume_name=NULL; | 55 | char *volume_name=NULL; |
@@ -58,11 +62,14 @@ unsigned long critical_value=0L; | |||
58 | int check_value_list=FALSE; | 62 | int check_value_list=FALSE; |
59 | int check_warning_value=FALSE; | 63 | int check_warning_value=FALSE; |
60 | int check_critical_value=FALSE; | 64 | int check_critical_value=FALSE; |
61 | int vars_to_check=CHECK_NONE; | 65 | enum checkvars vars_to_check = CHECK_NONE; |
62 | int show_all=FALSE; | 66 | int show_all=FALSE; |
63 | 67 | ||
64 | const char *progname = "check_nt"; | 68 | const char *progname = "check_nt"; |
65 | 69 | ||
70 | char recv_buffer[MAX_INPUT_BUFFER]; | ||
71 | |||
72 | void fetch_data (const char* address, int port, const char* sendb); | ||
66 | int process_arguments(int, char **); | 73 | int process_arguments(int, char **); |
67 | void preparelist(char *string); | 74 | void preparelist(char *string); |
68 | int strtoularray(unsigned long *array, char *string, const char *delim); | 75 | int strtoularray(unsigned long *array, char *string, const char *delim); |
@@ -70,10 +77,8 @@ void print_help(void); | |||
70 | void print_usage(void); | 77 | void print_usage(void); |
71 | 78 | ||
72 | int main(int argc, char **argv){ | 79 | int main(int argc, char **argv){ |
73 | int result; | ||
74 | int return_code = STATE_UNKNOWN; | 80 | int return_code = STATE_UNKNOWN; |
75 | char *send_buffer=NULL; | 81 | char *send_buffer=NULL; |
76 | char recv_buffer[MAX_INPUT_BUFFER]; | ||
77 | char *output_message=NULL; | 82 | char *output_message=NULL; |
78 | char *temp_string=NULL; | 83 | char *temp_string=NULL; |
79 | char *description=NULL; | 84 | char *description=NULL; |
@@ -92,8 +97,6 @@ int main(int argc, char **argv){ | |||
92 | int uphours=0; | 97 | int uphours=0; |
93 | int upminutes=0; | 98 | int upminutes=0; |
94 | 99 | ||
95 | asprintf(&req_password, _("None")); | ||
96 | |||
97 | if(process_arguments(argc,argv)==ERROR) | 100 | if(process_arguments(argc,argv)==ERROR) |
98 | usage(_("Could not parse arguments\n")); | 101 | usage(_("Could not parse arguments\n")); |
99 | 102 | ||
@@ -103,170 +106,124 @@ int main(int argc, char **argv){ | |||
103 | /* set socket timeout */ | 106 | /* set socket timeout */ |
104 | alarm(socket_timeout); | 107 | alarm(socket_timeout); |
105 | 108 | ||
106 | if (vars_to_check==CHECK_CLIENTVERSION) { | 109 | switch (vars_to_check) { |
107 | 110 | ||
108 | asprintf(&send_buffer,strcat(req_password,"&1")); | 111 | case CHECK_CLIENTVERSION: |
109 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | ||
110 | if(result!=STATE_OK) | ||
111 | return result; | ||
112 | asprintf(&output_message,recv_buffer); | ||
113 | return_code=STATE_OK; | ||
114 | 112 | ||
115 | } | 113 | asprintf(&send_buffer, "%s&1", req_password); |
116 | 114 | fetch_data (server_address, server_port, send_buffer); | |
117 | else if(vars_to_check==CHECK_CPULOAD){ | 115 | output_message = strdup (recv_buffer); |
118 | 116 | return_code=STATE_OK; | |
119 | if (check_value_list==TRUE) { | 117 | break; |
120 | if (strtoularray(lvalue_list,value_list,",")==TRUE) { | ||
121 | /* -l parameters is present with only integers */ | ||
122 | return_code=STATE_OK; | ||
123 | asprintf(&temp_string,_("CPU Load")); | ||
124 | while (lvalue_list[0+offset]> (unsigned long)0 && | ||
125 | lvalue_list[0+offset]<=(unsigned long)17280 && | ||
126 | lvalue_list[1+offset]> (unsigned long)0 && | ||
127 | lvalue_list[1+offset]<=(unsigned long)100 && | ||
128 | lvalue_list[2+offset]> (unsigned long)0 && | ||
129 | lvalue_list[2+offset]<=(unsigned long)100) { | ||
130 | /* loop until one of the parameters is wrong or not present */ | ||
131 | |||
132 | /* Send request and retrieve data */ | ||
133 | asprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]); | ||
134 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | ||
135 | if(result!=STATE_OK) | ||
136 | return result; | ||
137 | |||
138 | if (!strncmp(recv_buffer,"ERROR",5)) { | ||
139 | printf("NSClient - %s\n",recv_buffer); | ||
140 | exit(STATE_UNKNOWN); | ||
141 | } | ||
142 | |||
143 | utilization=strtoul(recv_buffer,NULL,10); | ||
144 | |||
145 | /* Check if any of the request is in a warning or critical state */ | ||
146 | if(utilization >= lvalue_list[2+offset]) | ||
147 | return_code=STATE_CRITICAL; | ||
148 | else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING) | ||
149 | return_code=STATE_WARNING; | ||
150 | |||
151 | asprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]); | ||
152 | asprintf(&temp_string,"%s%s",temp_string,output_message); | ||
153 | offset+=3; /* move across the array */ | ||
154 | } | ||
155 | if (strlen(temp_string)>10) { | ||
156 | /* we had at least on loop */ | ||
157 | asprintf(&output_message,"%s",temp_string); | ||
158 | } | ||
159 | else | ||
160 | asprintf(&output_message,"%s",_("not enough values for -l parameters")); | ||
161 | |||
162 | } else | ||
163 | asprintf(&output_message,_("wrong -l parameter.")); | ||
164 | 118 | ||
165 | } else | 119 | case CHECK_CPULOAD: |
166 | asprintf(&output_message,_("missing -l parameters")); | ||
167 | } | ||
168 | 120 | ||
169 | else if(vars_to_check==CHECK_UPTIME){ | 121 | if (value_list==NULL) |
122 | output_message = strdup (_("missing -l parameters")); | ||
123 | else if (strtoularray(lvalue_list,value_list,",")==FALSE) | ||
124 | output_message = strdup (_("wrong -l parameter.")); | ||
125 | else { | ||
126 | /* -l parameters is present with only integers */ | ||
127 | return_code=STATE_OK; | ||
128 | temp_string = strdup (_("CPU Load")); | ||
129 | /* loop until one of the parameters is wrong or not present */ | ||
130 | while (lvalue_list[0+offset]> (unsigned long)0 && | ||
131 | lvalue_list[0+offset]<=(unsigned long)17280 && | ||
132 | lvalue_list[1+offset]> (unsigned long)0 && | ||
133 | lvalue_list[1+offset]<=(unsigned long)100 && | ||
134 | lvalue_list[2+offset]> (unsigned long)0 && | ||
135 | lvalue_list[2+offset]<=(unsigned long)100) { | ||
136 | |||
137 | /* Send request and retrieve data */ | ||
138 | asprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]); | ||
139 | fetch_data (server_address, server_port, send_buffer); | ||
140 | |||
141 | utilization=strtoul(recv_buffer,NULL,10); | ||
142 | |||
143 | /* Check if any of the request is in a warning or critical state */ | ||
144 | if(utilization >= lvalue_list[2+offset]) | ||
145 | return_code=STATE_CRITICAL; | ||
146 | else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING) | ||
147 | return_code=STATE_WARNING; | ||
170 | 148 | ||
171 | asprintf(&send_buffer,strcat(req_password,"&3")); | 149 | asprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]); |
172 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 150 | asprintf(&temp_string,"%s%s",temp_string,output_message); |
173 | if(result!=STATE_OK) | 151 | offset+=3; /* move across the array */ |
174 | return result; | 152 | } |
153 | if (strlen(temp_string)>10) /* we had at least one loop */ | ||
154 | output_message = strdup (temp_string); | ||
155 | else | ||
156 | output_message = strdup (_("not enough values for -l parameters")); | ||
157 | } | ||
158 | break; | ||
175 | 159 | ||
176 | if (!strncmp(recv_buffer,"ERROR",5)) { | 160 | case CHECK_UPTIME: |
177 | printf("NSClient - %s\n",recv_buffer); | ||
178 | exit(STATE_UNKNOWN); | ||
179 | } | ||
180 | 161 | ||
162 | asprintf(&send_buffer, "%s&3", req_password); | ||
163 | fetch_data (server_address, server_port, send_buffer); | ||
181 | uptime=strtoul(recv_buffer,NULL,10); | 164 | uptime=strtoul(recv_buffer,NULL,10); |
182 | updays = uptime / 86400; | 165 | updays = uptime / 86400; |
183 | uphours = (uptime % 86400) / 3600; | 166 | uphours = (uptime % 86400) / 3600; |
184 | upminutes = ((uptime % 86400) % 3600) / 60; | 167 | upminutes = ((uptime % 86400) % 3600) / 60; |
185 | asprintf(&output_message,_("System Uptime : %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes); | 168 | asprintf(&output_message,_("System Uptime : %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes); |
186 | return_code=STATE_OK; | 169 | return_code=STATE_OK; |
187 | } | 170 | break; |
188 | 171 | ||
189 | else if(vars_to_check==CHECK_USEDDISKSPACE){ | 172 | case CHECK_USEDDISKSPACE: |
190 | 173 | ||
191 | return_code=STATE_UNKNOWN; | 174 | if (value_list==NULL) |
192 | if (check_value_list==TRUE) { | 175 | output_message = strdup (_("missing -l parameters")); |
193 | if (strlen(value_list)==1) { | 176 | else if (strlen(value_list)==1) |
194 | asprintf(&send_buffer,"%s&4&%s", req_password, value_list); | 177 | output_message = strdup (_("wrong -l argument")); |
195 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 178 | else { |
196 | if(result!=STATE_OK) | 179 | asprintf(&send_buffer,"%s&4&%s", req_password, value_list); |
197 | return result; | 180 | fetch_data (server_address, server_port, send_buffer); |
198 | 181 | free_disk_space=atof(strtok(recv_buffer,"&")); | |
199 | if (!strncmp(recv_buffer,"ERROR",5)) { | 182 | total_disk_space=atof(strtok(NULL,"&")); |
200 | printf("NSClient - %s\n",recv_buffer); | 183 | percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; |
201 | exit(STATE_UNKNOWN); | 184 | |
202 | } | 185 | if (free_disk_space>=0) { |
203 | 186 | asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), | |
204 | free_disk_space=atof(strtok(recv_buffer,"&")); | 187 | value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, percent_used_space, |
205 | total_disk_space=atof(strtok(NULL,"&")); | 188 | free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100); |
206 | percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; | 189 | |
207 | 190 | ||
208 | if (free_disk_space>=0) { | 191 | if(check_critical_value==TRUE && percent_used_space >= critical_value) |
209 | asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), | 192 | return_code=STATE_CRITICAL; |
210 | value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, percent_used_space, | 193 | else if (check_warning_value==TRUE && percent_used_space >= warning_value) |
211 | free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100); | 194 | return_code=STATE_WARNING; |
212 | 195 | else | |
213 | 196 | return_code=STATE_OK; | |
214 | if(check_critical_value==TRUE && percent_used_space >= critical_value) | 197 | |
215 | return_code=STATE_CRITICAL; | 198 | output_message = strdup (temp_string); |
216 | else if (check_warning_value==TRUE && percent_used_space >= warning_value) | ||
217 | return_code=STATE_WARNING; | ||
218 | else | ||
219 | return_code=STATE_OK; | ||
220 | |||
221 | asprintf(&output_message,"%s",temp_string); | ||
222 | |||
223 | } | ||
224 | else { | ||
225 | asprintf(&output_message,_("Free disk space : Invalid drive ")); | ||
226 | return_code=STATE_UNKNOWN; | ||
227 | } | ||
228 | } | 199 | } |
229 | else | 200 | else { |
230 | asprintf(&output_message,_("wrong -l argument")); | 201 | output_message = strdup (_("Free disk space : Invalid drive ")); |
231 | } else | 202 | return_code=STATE_UNKNOWN; |
232 | asprintf(&output_message,_("missing -l parameters")); | 203 | } |
233 | 204 | } | |
234 | } | 205 | break; |
235 | 206 | ||
236 | else if(vars_to_check==CHECK_SERVICESTATE || vars_to_check==CHECK_PROCSTATE){ | 207 | case CHECK_SERVICESTATE: |
208 | case CHECK_PROCSTATE: | ||
237 | 209 | ||
238 | if (check_value_list==TRUE) { | 210 | if (value_list==NULL) |
211 | output_message = strdup (_("No service/process specified")); | ||
212 | else { | ||
239 | preparelist(value_list); /* replace , between services with & to send the request */ | 213 | preparelist(value_list); /* replace , between services with & to send the request */ |
240 | asprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, | 214 | asprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, |
241 | (show_all==TRUE)?_("ShowAll"):_("ShowFail"),value_list); | 215 | (show_all==TRUE)?_("ShowAll"):_("ShowFail"),value_list); |
242 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 216 | fetch_data (server_address, server_port, send_buffer); |
243 | if(result!=STATE_OK) | ||
244 | return result; | ||
245 | |||
246 | if (!strncmp(recv_buffer,"ERROR",5)) { | ||
247 | printf("NSClient - %s\n",recv_buffer); | ||
248 | exit(STATE_UNKNOWN); | ||
249 | } | ||
250 | return_code=atoi(strtok(recv_buffer,"&")); | 217 | return_code=atoi(strtok(recv_buffer,"&")); |
251 | temp_string=strtok(NULL,"&"); | 218 | temp_string=strtok(NULL,"&"); |
252 | asprintf(&output_message, "%s",temp_string); | 219 | output_message = strdup (temp_string); |
253 | } | 220 | } |
254 | else | 221 | break; |
255 | asprintf(&output_message,_("No service/process specified")); | ||
256 | } | ||
257 | 222 | ||
258 | else if(vars_to_check==CHECK_MEMUSE) { | 223 | case CHECK_MEMUSE: |
259 | 224 | ||
260 | asprintf(&send_buffer,"%s&7", req_password); | 225 | asprintf(&send_buffer,"%s&7", req_password); |
261 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 226 | fetch_data (server_address, server_port, send_buffer); |
262 | if (result!=STATE_OK) | ||
263 | return result; | ||
264 | |||
265 | if (!strncmp(recv_buffer,"ERROR",5)) { | ||
266 | printf("NSClient - %s\n",recv_buffer); | ||
267 | exit(STATE_UNKNOWN); | ||
268 | } | ||
269 | |||
270 | mem_commitLimit=atof(strtok(recv_buffer,"&")); | 227 | mem_commitLimit=atof(strtok(recv_buffer,"&")); |
271 | mem_commitByte=atof(strtok(NULL,"&")); | 228 | mem_commitByte=atof(strtok(NULL,"&")); |
272 | percent_used_space = (mem_commitByte / mem_commitLimit) * 100; | 229 | percent_used_space = (mem_commitByte / mem_commitLimit) * 100; |
@@ -280,33 +237,27 @@ int main(int argc, char **argv){ | |||
280 | return_code=STATE_WARNING; | 237 | return_code=STATE_WARNING; |
281 | else | 238 | else |
282 | return_code=STATE_OK; | 239 | return_code=STATE_OK; |
283 | |||
284 | } | ||
285 | 240 | ||
286 | else if(vars_to_check==CHECK_COUNTER) { | 241 | break; |
287 | 242 | ||
288 | if (check_value_list==TRUE) { | 243 | case CHECK_COUNTER: |
244 | |||
245 | if (value_list==NULL) | ||
246 | output_message = strdup (_("No counter specified")); | ||
247 | else { | ||
289 | preparelist(value_list); /* replace , between services with & to send the request */ | 248 | preparelist(value_list); /* replace , between services with & to send the request */ |
290 | asprintf(&send_buffer,"%s&8&%s", req_password,value_list); | 249 | asprintf(&send_buffer,"%s&8&%s", req_password,value_list); |
291 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 250 | fetch_data (server_address, server_port, send_buffer); |
292 | if (result!=STATE_OK) | ||
293 | return result; | ||
294 | |||
295 | if (!strncmp(recv_buffer,"ERROR",5)) { | ||
296 | printf("NSClient - %s\n",recv_buffer); | ||
297 | exit(STATE_UNKNOWN); | ||
298 | } | ||
299 | |||
300 | strtok(value_list,"&"); /* burn the first parameters */ | 251 | strtok(value_list,"&"); /* burn the first parameters */ |
301 | description = strtok(NULL,"&"); | 252 | description = strtok(NULL,"&"); |
302 | counter_value = atof(recv_buffer); | 253 | counter_value = atof(recv_buffer); |
254 | |||
303 | if (description == NULL) | 255 | if (description == NULL) |
304 | asprintf(&output_message, "%.f", counter_value); | 256 | asprintf(&output_message, "%.f", counter_value); |
305 | else | 257 | else |
306 | asprintf(&output_message, description, counter_value); | 258 | asprintf(&output_message,"%s = %.f", description, counter_value); |
307 | 259 | ||
308 | if (critical_value > warning_value) { | 260 | if (critical_value > warning_value) { /* Normal thresholds */ |
309 | /* Normal thresholds */ | ||
310 | if(check_critical_value==TRUE && counter_value >= critical_value) | 261 | if(check_critical_value==TRUE && counter_value >= critical_value) |
311 | return_code=STATE_CRITICAL; | 262 | return_code=STATE_CRITICAL; |
312 | else if (check_warning_value==TRUE && counter_value >= warning_value) | 263 | else if (check_warning_value==TRUE && counter_value >= warning_value) |
@@ -314,8 +265,7 @@ int main(int argc, char **argv){ | |||
314 | else | 265 | else |
315 | return_code=STATE_OK; | 266 | return_code=STATE_OK; |
316 | } | 267 | } |
317 | else { | 268 | else { /* inverse thresholds */ |
318 | /* inverse thresholds */ | ||
319 | if(check_critical_value==TRUE && counter_value <= critical_value) | 269 | if(check_critical_value==TRUE && counter_value <= critical_value) |
320 | return_code=STATE_CRITICAL; | 270 | return_code=STATE_CRITICAL; |
321 | else if (check_warning_value==TRUE && counter_value <= warning_value) | 271 | else if (check_warning_value==TRUE && counter_value <= warning_value) |
@@ -323,33 +273,22 @@ int main(int argc, char **argv){ | |||
323 | else | 273 | else |
324 | return_code=STATE_OK; | 274 | return_code=STATE_OK; |
325 | } | 275 | } |
326 | |||
327 | } | ||
328 | else { | ||
329 | asprintf(&output_message,_("No counter specified")); | ||
330 | result=STATE_UNKNOWN; | ||
331 | } | 276 | } |
332 | } | 277 | break; |
333 | else if(vars_to_check==CHECK_FILEAGE) { | 278 | |
279 | case CHECK_FILEAGE: | ||
334 | 280 | ||
335 | if (check_value_list==TRUE) { | 281 | if (value_list==NULL) |
282 | output_message = strdup (_("No counter specified")); | ||
283 | else { | ||
336 | preparelist(value_list); /* replace , between services with & to send the request */ | 284 | preparelist(value_list); /* replace , between services with & to send the request */ |
337 | asprintf(&send_buffer,"%s&9&%s", req_password,value_list); | 285 | asprintf(&send_buffer,"%s&9&%s", req_password,value_list); |
338 | result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer)); | 286 | fetch_data (server_address, server_port, send_buffer); |
339 | if (result!=STATE_OK) | ||
340 | return result; | ||
341 | |||
342 | if (!strncmp(recv_buffer,"ERROR",5)) { | ||
343 | printf("NSClient - %s\n",recv_buffer); | ||
344 | exit(STATE_UNKNOWN); | ||
345 | } | ||
346 | |||
347 | age_in_minutes = atoi(strtok(recv_buffer,"&")); | 287 | age_in_minutes = atoi(strtok(recv_buffer,"&")); |
348 | description = strtok(NULL,"&"); | 288 | description = strtok(NULL,"&"); |
349 | asprintf(&output_message, description); | 289 | output_message = strdup (description); |
350 | 290 | ||
351 | if (critical_value > warning_value) { | 291 | if (critical_value > warning_value) { /* Normal thresholds */ |
352 | /* Normal thresholds */ | ||
353 | if(check_critical_value==TRUE && age_in_minutes >= critical_value) | 292 | if(check_critical_value==TRUE && age_in_minutes >= critical_value) |
354 | return_code=STATE_CRITICAL; | 293 | return_code=STATE_CRITICAL; |
355 | else if (check_warning_value==TRUE && age_in_minutes >= warning_value) | 294 | else if (check_warning_value==TRUE && age_in_minutes >= warning_value) |
@@ -357,21 +296,22 @@ int main(int argc, char **argv){ | |||
357 | else | 296 | else |
358 | return_code=STATE_OK; | 297 | return_code=STATE_OK; |
359 | } | 298 | } |
360 | else { | 299 | else { /* inverse thresholds */ |
361 | /* inverse thresholds */ | ||
362 | if(check_critical_value==TRUE && age_in_minutes <= critical_value) | 300 | if(check_critical_value==TRUE && age_in_minutes <= critical_value) |
363 | return_code=STATE_CRITICAL; | 301 | return_code=STATE_CRITICAL; |
364 | else if (check_warning_value==TRUE && age_in_minutes <= warning_value) | 302 | else if (check_warning_value==TRUE && age_in_minutes <= warning_value) |
365 | return_code=STATE_WARNING; | 303 | return_code=STATE_WARNING; |
366 | else | 304 | else |
367 | return_code=STATE_OK; | 305 | return_code=STATE_OK; |
368 | } | 306 | } |
369 | |||
370 | } | ||
371 | else { | ||
372 | asprintf(&output_message,_("No file specified")); | ||
373 | result=STATE_UNKNOWN; | ||
374 | } | 307 | } |
308 | break; | ||
309 | |||
310 | case CHECK_NONE: | ||
311 | default: | ||
312 | usage (_("")); | ||
313 | break; | ||
314 | |||
375 | } | 315 | } |
376 | 316 | ||
377 | /* reset timeout */ | 317 | /* reset timeout */ |
@@ -410,7 +350,7 @@ int process_arguments(int argc, char **argv){ | |||
410 | 350 | ||
411 | /* backwards compatibility */ | 351 | /* backwards compatibility */ |
412 | if (! is_option(argv[1])) { | 352 | if (! is_option(argv[1])) { |
413 | server_address=argv[1]; | 353 | server_address = strdup(argv[1]); |
414 | argv[1]=argv[0]; | 354 | argv[1]=argv[0]; |
415 | argv=&argv[1]; | 355 | argv=&argv[1]; |
416 | argc--; | 356 | argc--; |
@@ -444,10 +384,11 @@ int process_arguments(int argc, char **argv){ | |||
444 | print_revision(progname,"$Revision$"); | 384 | print_revision(progname,"$Revision$"); |
445 | exit(STATE_OK); | 385 | exit(STATE_OK); |
446 | case 'H': /* hostname */ | 386 | case 'H': /* hostname */ |
447 | server_address=optarg; | 387 | if (server_address) free(server_address); |
388 | server_address = strdup(optarg); | ||
448 | break; | 389 | break; |
449 | case 's': /* password */ | 390 | case 's': /* password */ |
450 | asprintf(&req_password,optarg); | 391 | req_password = strdup (optarg); |
451 | break; | 392 | break; |
452 | case 'p': /* port */ | 393 | case 'p': /* port */ |
453 | if (is_intnonneg(optarg)) | 394 | if (is_intnonneg(optarg)) |
@@ -480,8 +421,7 @@ int process_arguments(int argc, char **argv){ | |||
480 | return ERROR; | 421 | return ERROR; |
481 | break; | 422 | break; |
482 | case 'l': /* value list */ | 423 | case 'l': /* value list */ |
483 | asprintf(&value_list,"%s",optarg); | 424 | value_list = strdup (optarg); |
484 | check_value_list=TRUE; | ||
485 | break; | 425 | break; |
486 | case 'w': /* warning threshold */ | 426 | case 'w': /* warning threshold */ |
487 | warning_value=strtoul(optarg,NULL,10); | 427 | warning_value=strtoul(optarg,NULL,10); |
@@ -506,6 +446,9 @@ int process_arguments(int argc, char **argv){ | |||
506 | if (vars_to_check==CHECK_NONE) | 446 | if (vars_to_check==CHECK_NONE) |
507 | return ERROR; | 447 | return ERROR; |
508 | 448 | ||
449 | if (req_password == NULL) | ||
450 | req_password = strdup (_("None")); | ||
451 | |||
509 | return OK; | 452 | return OK; |
510 | } | 453 | } |
511 | 454 | ||
@@ -514,6 +457,18 @@ int process_arguments(int argc, char **argv){ | |||
514 | 457 | ||
515 | 458 | ||
516 | 459 | ||
460 | void fetch_data (const char *address, int port, const char *sendb) { | ||
461 | int result; | ||
462 | |||
463 | result=process_tcp_request(address, port, sendb, recv_buffer,sizeof(recv_buffer)); | ||
464 | |||
465 | if(result!=STATE_OK) | ||
466 | die (result, "could not fetch information from server\n"); | ||
467 | |||
468 | if (!strncmp(recv_buffer,"ERROR",5)) | ||
469 | die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer); | ||
470 | } | ||
471 | |||
517 | int strtoularray(unsigned long *array, char *string, const char *delim) { | 472 | int strtoularray(unsigned long *array, char *string, const char *delim) { |
518 | /* split a <delim> delimited string into a long array */ | 473 | /* split a <delim> delimited string into a long array */ |
519 | int idx=0; | 474 | int idx=0; |