summaryrefslogtreecommitdiffstats
path: root/plugins/check_nwstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_nwstat.c')
-rw-r--r--plugins/check_nwstat.c821
1 files changed, 821 insertions, 0 deletions
diff --git a/plugins/check_nwstat.c b/plugins/check_nwstat.c
new file mode 100644
index 0000000..e142670
--- /dev/null
+++ b/plugins/check_nwstat.c
@@ -0,0 +1,821 @@
1/******************************************************************************
2 *
3 * Program: NetWare statistics plugin for Nagios
4 * License: GPL
5 *
6 * License Information:
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * $Id$
23 *
24 *****************************************************************************/
25
26#define PROGNAME "check_nwstat"
27#define REVISION "$Revision$"
28#define COPYRIGHT "Copyright (c) 1999-2001 Ethan Galstad"
29
30#define SUMMARY "\
31This plugin attempts to contact the MRTGEXT NLM running on a Novell server\n\
32to gather the requested system information.\n"
33
34#define OPTIONS "\
35-H host [-v variable] [-w warning] [-c critical]\n\
36 [-p port] [-t timeout]"
37
38#define LONGOPTIONS "\
39-H, --hostname=HOST\n\
40 Name of the host to check\n\
41-v, --variable=STRING\n\
42 Variable to check. Valid variables include:\n\
43 LOAD1 = 1 minute average CPU load\n\
44 LOAD5 = 5 minute average CPU load\n\
45 LOAD15 = 15 minute average CPU load\n\
46 CONNS = number of currently licensed connections\n\
47 VPF<vol> = percent free space on volume <vol>\n\
48 VKF<vol> = KB of free space on volume <vol>\n\
49 LTCH = percent long term cache hits\n\
50 CBUFF = current number of cache buffers\n\
51 CDBUFF = current number of dirty cache buffers\n\
52 LRUM = LRU sitting time in minutes\n\
53 DSDB = check to see if DS Database is open\n\
54 LOGINS = check to see if logins are enabled\n\
55 UPRB = used packet receive buffers\n\
56 PUPRB = percent (of max) used packet receive buffers\n\
57 SAPENTRIES = number of entries in the SAP table\n\
58 SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>\n\
59 OFILES = number of open files\n\
60 VPP<vol> = percent purgeable space on volume <vol>\n\
61 VKP<vol> = KB of purgeable space on volume <vol>\n\
62 VPNP<vol> = percent not yet purgeable space on volume <vol>\n\
63 VKNP<vol> = KB of not yet purgeable space on volume <vol>\n\
64 ABENDS = number of abended threads (NW 5.x only)\n\
65 CSPROCS = number of current service processes (NW 5.x only)\n\
66-w, --warning=INTEGER\n\
67 Threshold which will result in a warning status\n\
68-c, --critical=INTEGER\n\
69 Threshold which will result in a critical status\n\
70-p, --port=INTEGER\n\
71 Optional port number (default: %d)\n\
72-t, --timeout=INTEGER\n\
73 Seconds before connection attempt times out (default: %d)\n\
74-o, --osversion\n\
75 Include server version string in results\n\
76-h, --help\n\
77 Print this help screen\n\
78-V, --version\n\
79 Print version information\n"
80
81#define DESCRIPTION "\
82Notes:\n\
83- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG\n\
84 extension for NetWare be loaded on the Novell servers you wish to check.\n\
85 (available from http://www.engr.wisc.edu/~drews/mrtg/)\n\
86- Values for critical thresholds should be lower than warning thresholds\n\
87 when the following variables are checked: VPF, VKF, LTCH, CBUFF, and LRUM.\n"
88
89#include "config.h"
90#include "common.h"
91#include "netutils.h"
92#include "utils.h"
93
94#define CHECK_NONE 0
95#define CHECK_LOAD1 1 /* check 1 minute CPU load */
96#define CHECK_LOAD5 2 /* check 5 minute CPU load */
97#define CHECK_LOAD15 3 /* check 15 minute CPU load */
98#define CHECK_CONNS 4 /* check number of connections */
99#define CHECK_VPF 5 /* check % free space on volume */
100#define CHECK_VKF 6 /* check KB free space on volume */
101#define CHECK_LTCH 7 /* check long-term cache hit percentage */
102#define CHECK_CBUFF 8 /* check total cache buffers */
103#define CHECK_CDBUFF 9 /* check dirty cache buffers */
104#define CHECK_LRUM 10 /* check LRU sitting time in minutes */
105#define CHECK_DSDB 11 /* check to see if DS Database is open */
106#define CHECK_LOGINS 12 /* check to see if logins are enabled */
107#define CHECK_PUPRB 13 /* check % of used packet receive buffers */
108#define CHECK_UPRB 14 /* check used packet receive buffers */
109#define CHECK_SAPENTRIES 15 /* check SAP entries */
110#define CHECK_OFILES 16 /* check number of open files */
111#define CHECK_VKP 17 /* check KB purgeable space on volume */
112#define CHECK_VPP 18 /* check % purgeable space on volume */
113#define CHECK_VKNP 19 /* check KB not yet purgeable space on volume */
114#define CHECK_VPNP 20 /* check % not yet purgeable space on volume */
115#define CHECK_ABENDS 21 /* check abended thread count */
116#define CHECK_CSPROCS 22 /* check number of current service processes */
117
118#define PORT 9999
119
120char *server_address=NULL;
121char *volume_name=NULL;
122int server_port=PORT;
123unsigned long warning_value=0L;
124unsigned long critical_value=0L;
125int check_warning_value=FALSE;
126int check_critical_value=FALSE;
127int check_netware_version=FALSE;
128unsigned long vars_to_check=CHECK_NONE;
129int sap_number=-1;
130
131#define PROGNAME "check_nwstat"
132
133int process_arguments(int, char **);
134void print_usage(void);
135void print_help(void);
136
137int main(int argc, char **argv){
138 int result;
139 char *send_buffer=NULL;
140 char recv_buffer[MAX_INPUT_BUFFER];
141 char *output_message=NULL;
142 char *temp_buffer=NULL;
143 char *netware_version=NULL;
144
145 int open_files=0;
146 int abended_threads=0;
147 int max_service_processes=0;
148 int current_service_processes=0;
149 unsigned long free_disk_space=0L;
150 unsigned long total_disk_space=0L;
151 unsigned long purgeable_disk_space=0L;
152 unsigned long non_purgeable_disk_space=0L;
153 int percent_free_space=0;
154 int percent_purgeable_space=0;
155 int percent_non_purgeable_space=0;
156 unsigned long current_connections=0L;
157 unsigned long utilization=0L;
158 int cache_hits=0;
159 unsigned long cache_buffers=0L;
160 unsigned long lru_time=0L;
161 char uptime[MAX_INPUT_BUFFER];
162 int max_packet_receive_buffers=0;
163 int used_packet_receive_buffers=0;
164 unsigned long percent_used_packet_receive_buffers=0L;
165 int sap_entries=0;
166
167 if(process_arguments(argc,argv)==ERROR)
168 usage("Could not parse arguments\n");
169
170 /* initialize alarm signal handling */
171 signal(SIGALRM,socket_timeout_alarm_handler);
172
173 /* set socket timeout */
174 alarm(socket_timeout);
175
176 /* get OS version string */
177 if (check_netware_version==TRUE) {
178 send_buffer = strscpy(send_buffer,"S19\r\n");
179 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
180 if(result!=STATE_OK)
181 return result;
182 if(!strcmp(recv_buffer,"-1\n"))
183 netware_version = ssprintf(netware_version,"");
184 else {
185 recv_buffer[strlen(recv_buffer)-1]=0;
186 netware_version = ssprintf(netware_version,"NetWare %s: ",recv_buffer);
187 }
188 } else
189 netware_version = ssprintf(netware_version,"");
190
191
192 /* check CPU load */
193 if (vars_to_check==CHECK_LOAD1 || vars_to_check==CHECK_LOAD5 || vars_to_check==CHECK_LOAD15) {
194
195 switch(vars_to_check){
196 case CHECK_LOAD1:
197 temp_buffer = strscpy(temp_buffer,"1");
198 break;
199 case CHECK_LOAD5:
200 temp_buffer = strscpy(temp_buffer,"5");
201 break;
202 default:
203 temp_buffer = strscpy(temp_buffer,"15");
204 break;
205 }
206
207 send_buffer = ssprintf(send_buffer,"UTIL%s\r\n",temp_buffer);
208 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
209 if(result!=STATE_OK)
210 return result;
211 utilization=strtoul(recv_buffer,NULL,10);
212 send_buffer = strscpy(send_buffer,"UPTIME\r\n");
213 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
214 if(result!=STATE_OK)
215 return result;
216 recv_buffer[strlen(recv_buffer)-1]=0;
217 sprintf(uptime,"Up %s,",recv_buffer);
218
219 if(check_critical_value==TRUE && utilization >= critical_value)
220 result=STATE_CRITICAL;
221 else if(check_warning_value==TRUE && utilization >= warning_value)
222 result=STATE_WARNING;
223
224 output_message = ssprintf(output_message,"Load %s - %s %s-min load average = %lu%%",(result==STATE_OK)?"ok":"problem",uptime,temp_buffer,utilization);
225
226 /* check number of user connections */
227 } else if (vars_to_check==CHECK_CONNS) {
228
229 send_buffer = strscpy(send_buffer,"CONNECT\r\n");
230 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
231 if(result!=STATE_OK)
232 return result;
233 current_connections=strtoul(recv_buffer,NULL,10);
234
235 if(check_critical_value==TRUE && current_connections >= critical_value)
236 result=STATE_CRITICAL;
237 else if(check_warning_value==TRUE && current_connections >= warning_value)
238 result=STATE_WARNING;
239 output_message = ssprintf(output_message,"Conns %s - %lu current connections",(result==STATE_OK)?"ok":"problem",current_connections);
240
241 /* check % long term cache hits */
242 } else if (vars_to_check==CHECK_LTCH) {
243
244 send_buffer = strscpy(send_buffer,"S1\r\n");
245 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
246 if(result!=STATE_OK)
247 return result;
248 cache_hits=atoi(recv_buffer);
249
250 if(check_critical_value==TRUE && cache_hits <= critical_value)
251 result=STATE_CRITICAL;
252 else if(check_warning_value==TRUE && cache_hits <= warning_value)
253 result=STATE_WARNING;
254 output_message = ssprintf(output_message,"Long term cache hits = %d%%",cache_hits);
255
256 /* check cache buffers */
257 } else if (vars_to_check==CHECK_CBUFF) {
258
259 send_buffer = strscpy(send_buffer,"S2\r\n");
260 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
261 if(result!=STATE_OK)
262 return result;
263 cache_buffers=strtoul(recv_buffer,NULL,10);
264
265 if(check_critical_value==TRUE && cache_buffers <= critical_value)
266 result=STATE_CRITICAL;
267 else if(check_warning_value==TRUE && cache_buffers <= warning_value)
268 result=STATE_WARNING;
269 output_message = ssprintf(output_message,"Total cache buffers = %lu",cache_buffers);
270
271 /* check dirty cache buffers */
272 } else if (vars_to_check==CHECK_CDBUFF) {
273
274 send_buffer = strscpy(send_buffer,"S3\r\n");
275 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
276 if(result!=STATE_OK)
277 return result;
278 cache_buffers=strtoul(recv_buffer,NULL,10);
279
280 if(check_critical_value==TRUE && cache_buffers >= critical_value)
281 result=STATE_CRITICAL;
282 else if(check_warning_value==TRUE && cache_buffers >= warning_value)
283 result=STATE_WARNING;
284 output_message = ssprintf(output_message,"Dirty cache buffers = %lu",cache_buffers);
285
286 /* check LRU sitting time in minutes */
287 } else if (vars_to_check==CHECK_LRUM) {
288
289 send_buffer = strscpy(send_buffer,"S5\r\n");
290 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
291 if(result!=STATE_OK)
292 return result;
293 lru_time=strtoul(recv_buffer,NULL,10);
294
295 if(check_critical_value==TRUE && lru_time <= critical_value)
296 result=STATE_CRITICAL;
297 else if(check_warning_value==TRUE && lru_time <= warning_value)
298 result=STATE_WARNING;
299 output_message = ssprintf(output_message,"LRU sitting time = %lu minutes",lru_time);
300
301
302 /* check KB free space on volume */
303 } else if (vars_to_check==CHECK_VKF) {
304
305 send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name);
306 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
307 if(result!=STATE_OK)
308 return result;
309
310 if (!strcmp(recv_buffer,"-1\n")) {
311 output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
312 result=STATE_CRITICAL;
313 } else {
314 free_disk_space=strtoul(recv_buffer,NULL,10);
315 if(check_critical_value==TRUE && free_disk_space <= critical_value)
316 result=STATE_CRITICAL;
317 else if(check_warning_value==TRUE && free_disk_space <= warning_value)
318 result=STATE_WARNING;
319 output_message = ssprintf(output_message,"%s%lu KB free on volume %s",(result==STATE_OK)?"":"Only ",free_disk_space,volume_name);
320 }
321
322 /* check % free space on volume */
323 } else if (vars_to_check==CHECK_VPF) {
324
325 send_buffer = ssprintf(send_buffer,"VKF%s\r\n",volume_name);
326 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
327 if(result!=STATE_OK)
328 return result;
329
330 if(!strcmp(recv_buffer,"-1\n")){
331
332 output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
333 result=STATE_CRITICAL;
334
335 } else {
336
337 free_disk_space=strtoul(recv_buffer,NULL,10);
338
339 send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
340 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
341 if(result!=STATE_OK)
342 return result;
343 total_disk_space=strtoul(recv_buffer,NULL,10);
344
345 percent_free_space=(int)(((double)free_disk_space/(double)total_disk_space)*100.0);
346
347 if(check_critical_value==TRUE && percent_free_space <= critical_value)
348 result=STATE_CRITICAL;
349 else if(check_warning_value==TRUE && percent_free_space <= warning_value)
350 result=STATE_WARNING;
351 free_disk_space/=1024;
352 output_message = ssprintf(output_message,"%lu MB (%d%%) free on volume %s",free_disk_space,percent_free_space,volume_name);
353 }
354
355 /* check to see if DS Database is open or closed */
356 } else if(vars_to_check==CHECK_DSDB) {
357
358 send_buffer = strscpy(send_buffer,"S11\r\n");
359 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
360 if(result!=STATE_OK)
361 return result;
362 if(atoi(recv_buffer)==1)
363 result=STATE_OK;
364 else
365 result=STATE_WARNING;
366
367 send_buffer = strscpy(send_buffer,"S13\r\n");
368 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
369 temp_buffer=strtok(recv_buffer,"\r\n");
370
371 output_message = ssprintf(output_message,"Directory Services Database is %s (DS version %s)",(result==STATE_OK)?"open":"closed",temp_buffer);
372
373 /* check to see if logins are enabled */
374 } else if (vars_to_check==CHECK_LOGINS) {
375
376 send_buffer = strscpy(send_buffer,"S12\r\n");
377 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
378 if(result!=STATE_OK)
379 return result;
380 if(atoi(recv_buffer)==1)
381 result=STATE_OK;
382 else
383 result=STATE_WARNING;
384
385 output_message = ssprintf(output_message,"Logins are %s",(result==STATE_OK)?"enabled":"disabled");
386
387 /* check packet receive buffers */
388 } else if (vars_to_check==CHECK_UPRB || vars_to_check==CHECK_PUPRB) {
389
390 send_buffer = ssprintf(send_buffer,"S15\r\n",volume_name);
391 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
392 if(result!=STATE_OK)
393 return result;
394
395 used_packet_receive_buffers=atoi(recv_buffer);
396
397 send_buffer = ssprintf(send_buffer,"S16\r\n",volume_name);
398 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
399 if(result!=STATE_OK)
400 return result;
401
402 max_packet_receive_buffers=atoi(recv_buffer);
403
404 percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0);
405
406 if(vars_to_check==CHECK_UPRB){
407 if(check_critical_value==TRUE && used_packet_receive_buffers >= critical_value)
408 result=STATE_CRITICAL;
409 else if(check_warning_value==TRUE && used_packet_receive_buffers >= warning_value)
410 result=STATE_WARNING;
411 } else {
412 if(check_critical_value==TRUE && percent_used_packet_receive_buffers >= critical_value)
413 result=STATE_CRITICAL;
414 else if(check_warning_value==TRUE && percent_used_packet_receive_buffers >= warning_value)
415 result=STATE_WARNING;
416 }
417
418 output_message = ssprintf(output_message,"%d of %d (%lu%%) packet receive buffers used",used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
419
420 /* check SAP table entries */
421 } else if (vars_to_check==CHECK_SAPENTRIES) {
422
423 if(sap_number==-1)
424 send_buffer = ssprintf(send_buffer,"S9\r\n");
425 else
426 send_buffer = ssprintf(send_buffer,"S9.%d\r\n",sap_number);
427 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
428 if(result!=STATE_OK)
429 return result;
430
431 sap_entries=atoi(recv_buffer);
432
433 if(check_critical_value==TRUE && sap_entries >= critical_value)
434 result=STATE_CRITICAL;
435 else if(check_warning_value==TRUE && sap_entries >= warning_value)
436 result=STATE_WARNING;
437
438 if(sap_number==-1)
439 output_message = ssprintf(output_message,"%d entries in SAP table",sap_entries);
440 else
441 output_message = ssprintf(output_message,"%d entries in SAP table for SAP type %d",sap_entries,sap_number);
442
443 /* check KB purgeable space on volume */
444 } else if (vars_to_check==CHECK_VKP) {
445
446 send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name);
447 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
448 if(result!=STATE_OK)
449 return result;
450
451 if (!strcmp(recv_buffer,"-1\n")) {
452 output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
453 result=STATE_CRITICAL;
454 } else {
455 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
456 if(check_critical_value==TRUE && purgeable_disk_space >= critical_value)
457 result=STATE_CRITICAL;
458 else if(check_warning_value==TRUE && purgeable_disk_space >= warning_value)
459 result=STATE_WARNING;
460 output_message = ssprintf(output_message,"%s%lu KB purgeable on volume %s",(result==STATE_OK)?"":"Only ",purgeable_disk_space,volume_name);
461 }
462
463 /* check % purgeable space on volume */
464 } else if (vars_to_check==CHECK_VPP) {
465
466 send_buffer = ssprintf(send_buffer,"VKP%s\r\n",volume_name);
467 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
468 if(result!=STATE_OK)
469 return result;
470
471 if(!strcmp(recv_buffer,"-1\n")){
472
473 output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
474 result=STATE_CRITICAL;
475
476 } else {
477
478 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
479
480 send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
481 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
482 if(result!=STATE_OK)
483 return result;
484 total_disk_space=strtoul(recv_buffer,NULL,10);
485
486 percent_purgeable_space=(int)(((double)purgeable_disk_space/(double)total_disk_space)*100.0);
487
488 if(check_critical_value==TRUE && percent_purgeable_space >= critical_value)
489 result=STATE_CRITICAL;
490 else if(check_warning_value==TRUE && percent_purgeable_space >= warning_value)
491 result=STATE_WARNING;
492 purgeable_disk_space/=1024;
493 output_message = ssprintf(output_message,"%lu MB (%d%%) purgeable on volume %s",purgeable_disk_space,percent_purgeable_space,volume_name);
494 }
495
496 /* check KB not yet purgeable space on volume */
497 } else if (vars_to_check==CHECK_VKNP) {
498
499 send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name);
500 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
501 if(result!=STATE_OK)
502 return result;
503
504 if (!strcmp(recv_buffer,"-1\n")) {
505 output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
506 result=STATE_CRITICAL;
507 } else {
508 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
509 if(check_critical_value==TRUE && non_purgeable_disk_space >= critical_value)
510 result=STATE_CRITICAL;
511 else if(check_warning_value==TRUE && non_purgeable_disk_space >= warning_value)
512 result=STATE_WARNING;
513 output_message = ssprintf(output_message,"%s%lu KB not yet purgeable on volume %s",(result==STATE_OK)?"":"Only ",non_purgeable_disk_space,volume_name);
514 }
515
516 /* check % not yet purgeable space on volume */
517 } else if (vars_to_check==CHECK_VPNP) {
518
519 send_buffer = ssprintf(send_buffer,"VKNP%s\r\n",volume_name);
520 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
521 if(result!=STATE_OK)
522 return result;
523
524 if(!strcmp(recv_buffer,"-1\n")){
525
526 output_message = ssprintf(output_message,"Error: Volume '%s' does not exist!",volume_name);
527 result=STATE_CRITICAL;
528
529 } else {
530
531 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
532
533 send_buffer = ssprintf(send_buffer,"VKS%s\r\n",volume_name);
534 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
535 if(result!=STATE_OK)
536 return result;
537 total_disk_space=strtoul(recv_buffer,NULL,10);
538
539 percent_non_purgeable_space=(int)(((double)non_purgeable_disk_space/(double)total_disk_space)*100.0);
540
541 if(check_critical_value==TRUE && percent_non_purgeable_space >= critical_value)
542 result=STATE_CRITICAL;
543 else if(check_warning_value==TRUE && percent_non_purgeable_space >= warning_value)
544 result=STATE_WARNING;
545 purgeable_disk_space/=1024;
546 output_message = ssprintf(output_message,"%lu MB (%d%%) not yet purgeable on volume %s",non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
547 }
548
549 /* check # of open files */
550 } else if (vars_to_check==CHECK_OFILES) {
551
552 send_buffer = ssprintf(send_buffer,"S18\r\n");
553 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
554 if(result!=STATE_OK)
555 return result;
556
557 open_files=atoi(recv_buffer);
558
559 if(check_critical_value==TRUE && open_files >= critical_value)
560 result=STATE_CRITICAL;
561 else if(check_warning_value==TRUE && open_files >= warning_value)
562 result=STATE_WARNING;
563
564 output_message = ssprintf(output_message,"%d open files",open_files);
565
566 /* check # of abended threads (Netware 5.x only) */
567 } else if (vars_to_check==CHECK_ABENDS) {
568
569 send_buffer = ssprintf(send_buffer,"S17\r\n");
570 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
571 if(result!=STATE_OK)
572 return result;
573
574 abended_threads=atoi(recv_buffer);
575
576 if(check_critical_value==TRUE && abended_threads >= critical_value)
577 result=STATE_CRITICAL;
578 else if(check_warning_value==TRUE && abended_threads >= warning_value)
579 result=STATE_WARNING;
580
581 output_message = ssprintf(output_message,"%d abended threads",abended_threads);
582
583 /* check # of current service processes (Netware 5.x only) */
584 } else if (vars_to_check==CHECK_CSPROCS) {
585
586 send_buffer = ssprintf(send_buffer,"S20\r\n");
587 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
588 if(result!=STATE_OK)
589 return result;
590
591 max_service_processes=atoi(recv_buffer);
592
593 send_buffer = ssprintf(send_buffer,"S21\r\n");
594 result=process_tcp_request(server_address,server_port,send_buffer,recv_buffer,sizeof(recv_buffer));
595 if(result!=STATE_OK)
596 return result;
597
598 current_service_processes=atoi(recv_buffer);
599
600 if(check_critical_value==TRUE && current_service_processes >= critical_value)
601 result=STATE_CRITICAL;
602 else if(check_warning_value==TRUE && current_service_processes >= warning_value)
603 result=STATE_WARNING;
604
605 output_message = ssprintf(output_message,"%d current service processes (%d max)",current_service_processes,max_service_processes);
606
607 } else {
608
609 output_message = strscpy(output_message,"Nothing to check!\n");
610 result=STATE_UNKNOWN;
611
612 }
613
614 /* reset timeout */
615 alarm(0);
616
617 printf("%s%s\n",netware_version,output_message);
618
619 return result;
620}
621
622
623/* process command-line arguments */
624int process_arguments(int argc, char **argv){
625 int c;
626
627#ifdef HAVE_GETOPT_H
628 int option_index = 0;
629 static struct option long_options[] =
630 {
631 {"port", required_argument,0,'p'},
632 {"timeout", required_argument,0,'t'},
633 {"critical", required_argument,0,'c'},
634 {"warning", required_argument,0,'w'},
635 {"variable", required_argument,0,'v'},
636 {"hostname", required_argument,0,'H'},
637 {"osversion",no_argument, 0,'o'},
638 {"version", no_argument, 0,'V'},
639 {"help", no_argument, 0,'h'},
640 {0,0,0,0}
641 };
642#endif
643
644 /* no options were supplied */
645 if(argc<2) return ERROR;
646
647 /* backwards compatibility */
648 if (! is_option(argv[1])) {
649 server_address=argv[1];
650 argv[1]=argv[0];
651 argv=&argv[1];
652 argc--;
653 }
654
655 for (c=1;c<argc;c++) {
656 if(strcmp("-to",argv[c])==0)
657 strcpy(argv[c],"-t");
658 else if (strcmp("-wv",argv[c])==0)
659 strcpy(argv[c],"-w");
660 else if (strcmp("-cv",argv[c])==0)
661 strcpy(argv[c],"-c");
662 }
663
664 while (1){
665#ifdef HAVE_GETOPT_H
666 c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",long_options,&option_index);
667#else
668 c = getopt(argc,argv,"+hoVH:t:c:w:p:v:");
669#endif
670
671 if (c==-1||c==EOF||c==1)
672 break;
673
674 switch (c)
675 {
676 case '?': /* print short usage statement if args not parsable */
677 printf("%s: Unknown argument: %s\n\n",my_basename(argv[0]),optarg);
678 print_usage();
679 exit(STATE_UNKNOWN);
680 case 'h': /* help */
681 print_help();
682 exit(STATE_OK);
683 case 'V': /* version */
684 print_revision(my_basename(argv[0]),"$Revision$");
685 exit(STATE_OK);
686 case 'H': /* hostname */
687 server_address=optarg;
688 break;
689 case 'o': /* display nos version */
690 check_netware_version=TRUE;
691 break;
692 case 'p': /* port */
693 if (is_intnonneg(optarg))
694 server_port=atoi(optarg);
695 else
696 terminate(STATE_UNKNOWN,"Server port an integer (seconds)\nType '%s -h' for additional help\n",PROGNAME);
697 break;
698 case 'v':
699 if(strlen(optarg)<3)
700 return ERROR;
701 if(!strcmp(optarg,"LOAD1"))
702 vars_to_check=CHECK_LOAD1;
703 else if(!strcmp(optarg,"LOAD5"))
704 vars_to_check=CHECK_LOAD5;
705 else if(!strcmp(optarg,"LOAD15"))
706 vars_to_check=CHECK_LOAD15;
707 else if(!strcmp(optarg,"CONNS"))
708 vars_to_check=CHECK_CONNS;
709 else if(!strcmp(optarg,"LTCH"))
710 vars_to_check=CHECK_LTCH;
711 else if(!strcmp(optarg,"CBUFF"))
712 vars_to_check=CHECK_CBUFF;
713 else if(!strcmp(optarg,"CDBUFF"))
714 vars_to_check=CHECK_CDBUFF;
715 else if(!strcmp(optarg,"LRUM"))
716 vars_to_check=CHECK_LRUM;
717 else if(strncmp(optarg,"VPF",3)==0){
718 vars_to_check=CHECK_VPF;
719 volume_name = strscpy(volume_name,optarg+3);
720 if(!strcmp(volume_name,""))
721 volume_name = strscpy(volume_name,"SYS");
722 }
723 else if(strncmp(optarg,"VKF",3)==0){
724 vars_to_check=CHECK_VKF;
725 volume_name = strscpy(volume_name,optarg+3);
726 if(!strcmp(volume_name,""))
727 volume_name = strscpy(volume_name,"SYS");
728 }
729 else if(!strcmp(optarg,"DSDB"))
730 vars_to_check=CHECK_DSDB;
731 else if(!strcmp(optarg,"LOGINS"))
732 vars_to_check=CHECK_LOGINS;
733 else if(!strcmp(optarg,"UPRB"))
734 vars_to_check=CHECK_UPRB;
735 else if(!strcmp(optarg,"PUPRB"))
736 vars_to_check=CHECK_PUPRB;
737 else if(!strncmp(optarg,"SAPENTRIES",10)){
738 vars_to_check=CHECK_SAPENTRIES;
739 if(strlen(optarg)>10)
740 sap_number=atoi(optarg+10);
741 else
742 sap_number=-1;
743 }
744 else if(!strcmp(optarg,"OFILES"))
745 vars_to_check=CHECK_OFILES;
746 else if(strncmp(optarg,"VKP",3)==0){
747 vars_to_check=CHECK_VKP;
748 volume_name = strscpy(volume_name,optarg+3);
749 if(!strcmp(volume_name,""))
750 volume_name = strscpy(volume_name,"SYS");
751 }
752 else if(strncmp(optarg,"VPP",3)==0){
753 vars_to_check=CHECK_VPP;
754 volume_name = strscpy(volume_name,optarg+3);
755 if(!strcmp(volume_name,""))
756 volume_name = strscpy(volume_name,"SYS");
757 }
758 else if(strncmp(optarg,"VKNP",4)==0){
759 vars_to_check=CHECK_VKNP;
760 volume_name = strscpy(volume_name,optarg+4);
761 if(!strcmp(volume_name,""))
762 volume_name = strscpy(volume_name,"SYS");
763 }
764 else if(strncmp(optarg,"VPNP",4)==0){
765 vars_to_check=CHECK_VPNP;
766 volume_name = strscpy(volume_name,optarg+4);
767 if(!strcmp(volume_name,""))
768 volume_name = strscpy(volume_name,"SYS");
769 }
770 else if(!strcmp(optarg,"ABENDS"))
771 vars_to_check=CHECK_ABENDS;
772 else if(!strcmp(optarg,"CSPROCS"))
773 vars_to_check=CHECK_CSPROCS;
774 else
775 return ERROR;
776 break;
777 case 'w': /* warning threshold */
778 warning_value=strtoul(optarg,NULL,10);
779 check_warning_value=TRUE;
780 break;
781 case 'c': /* critical threshold */
782 critical_value=strtoul(optarg,NULL,10);
783 check_critical_value=TRUE;
784 break;
785 case 't': /* timeout */
786 socket_timeout=atoi(optarg);
787 if(socket_timeout<=0)
788 return ERROR;
789 }
790
791 }
792
793 return OK;
794}
795
796
797void print_usage(void)
798{
799 printf
800 ("Usage:\n"
801 " %s %s\n"
802#ifdef HAVE_GETOPT_H
803 " %s (-h | --help) for detailed help\n"
804 " %s (-V | --version) for version information\n",
805#else
806 " %s -h for detailed help\n"
807 " %s -V for version information\n",
808#endif
809 PROGNAME, OPTIONS, PROGNAME, PROGNAME);
810}
811
812void print_help(void)
813{
814 print_revision (PROGNAME, REVISION);
815 printf ("%s\n\n%s\n", COPYRIGHT, SUMMARY);
816 print_usage();
817 printf
818 ("\nOptions:\n" LONGOPTIONS "\n" DESCRIPTION "\n",
819 PORT, DEFAULT_SOCKET_TIMEOUT);
820 support ();
821}