Fix INADDR_NONE value (for systems which don't define it).
[monitoring-plugins.git] / plugins / check_nwstat.c
blob37e92290178e849f6cc7ddda8dc000d45b51a690
1 /******************************************************************************
3 * Nagios check_nwstat plugin
5 * License: GPL
6 * Copyright (c) 2000-2006 nagios-plugins team
8 * Last Modified: $Date$
10 * Description:
12 * This file contains the check_nwstat plugin
14 * This plugin attempts to contact the MRTGEXT NLM running on a
15 * Novell server to gather the requested system information.
18 * License Information:
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 $Id$
36 ******************************************************************************/
38 const char *progname = "check_nwstat";
39 const char *revision = "$Revision$";
40 const char *copyright = "2000-2006";
41 const char *email = "nagiosplug-devel@lists.sourceforge.net";
43 #include "common.h"
44 #include "netutils.h"
45 #include "utils.h"
47 enum checkvar {
48 NONE,
49 LOAD1, /* check 1 minute CPU load */
50 LOAD5, /* check 5 minute CPU load */
51 LOAD15, /* check 15 minute CPU load */
52 CONNS, /* check number of connections */
53 VPF, /* check % free space on volume */
54 VMF, /* check MB free space on volume */
55 VMU, /* check MB used space on volume */
56 VMP, /* check MB purgeable space on volume */
57 VKF, /* check KB free space on volume */
58 LTCH, /* check long-term cache hit percentage */
59 CBUFF, /* check total cache buffers */
60 CDBUFF, /* check dirty cache buffers */
61 LRUM, /* check LRU sitting time in minutes */
62 DSDB, /* check to see if DS Database is open */
63 LOGINS, /* check to see if logins are enabled */
64 NRMH, /* check to see NRM Health Status */
65 PUPRB, /* check % of used packet receive buffers */
66 UPRB, /* check used packet receive buffers */
67 SAPENTRIES, /* check SAP entries */
68 OFILES, /* check number of open files */
69 VKP, /* check KB purgeable space on volume */
70 VPP, /* check % purgeable space on volume */
71 VKNP, /* check KB not yet purgeable space on volume */
72 VPNP, /* check % not yet purgeable space on volume */
73 ABENDS, /* check abended thread count */
74 CSPROCS, /* check number of current service processes */
75 TSYNC, /* check timesync status 0=no 1=yes in sync to the network */
76 LRUS, /* check LRU sitting time in seconds */
77 DCB, /* check dirty cache buffers as a percentage of the total */
78 TCB, /* check total cache buffers as a percentage of the original */
79 DSVER, /* check NDS version */
80 UPTIME, /* check server uptime */
81 NLM, /* check NLM loaded */
82 NRMP, /* check NRM Process Values */
83 NRMM, /* check NRM Memory Values */
84 NRMS, /* check NRM Values */
85 NSS1, /* check Statistics from _Admin:Manage_NSS\GeneralStats.xml */
86 NSS2, /* check Statistics from _Admin:Manage_NSS\BufferCache.xml */
87 NSS3, /* check statistics from _Admin:Manage_NSS\NameCache.xml */
88 NSS4, /* check statistics from _Admin:Manage_NSS\FileStats.xml */
89 NSS5, /* check statistics from _Admin:Manage_NSS\ObjectCache.xml */
90 NSS6, /* check statistics from _Admin:Manage_NSS\Thread.xml */
91 NSS7 /* check statistics from _Admin:Manage_NSS\AuthorizationCache.xml */
94 enum {
95 PORT = 9999
98 char *server_address=NULL;
99 char *volume_name=NULL;
100 char *nlm_name=NULL;
101 char *nrmp_name=NULL;
102 char *nrmm_name=NULL;
103 char *nrms_name=NULL;
104 char *nss1_name=NULL;
105 char *nss2_name=NULL;
106 char *nss3_name=NULL;
107 char *nss4_name=NULL;
108 char *nss5_name=NULL;
109 char *nss6_name=NULL;
110 char *nss7_name=NULL;
111 int server_port=PORT;
112 unsigned long warning_value=0L;
113 unsigned long critical_value=0L;
114 int check_warning_value=FALSE;
115 int check_critical_value=FALSE;
116 int check_netware_version=FALSE;
117 enum checkvar vars_to_check = NONE;
118 int sap_number=-1;
120 int process_arguments(int, char **);
121 void print_help(void);
122 void print_usage(void);
127 main(int argc, char **argv) {
128 int result = STATE_UNKNOWN;
129 int sd;
130 char *send_buffer=NULL;
131 char recv_buffer[MAX_INPUT_BUFFER];
132 char *output_message=NULL;
133 char *temp_buffer=NULL;
134 char *netware_version=NULL;
136 int time_sync_status=0;
137 int nrm_health_status=0;
138 unsigned long total_cache_buffers=0;
139 unsigned long dirty_cache_buffers=0;
140 unsigned long open_files=0;
141 unsigned long abended_threads=0;
142 unsigned long max_service_processes=0;
143 unsigned long current_service_processes=0;
144 unsigned long free_disk_space=0L;
145 unsigned long nrmp_value=0L;
146 unsigned long nrmm_value=0L;
147 unsigned long nrms_value=0L;
148 unsigned long nss1_value=0L;
149 unsigned long nss2_value=0L;
150 unsigned long nss3_value=0L;
151 unsigned long nss4_value=0L;
152 unsigned long nss5_value=0L;
153 unsigned long nss6_value=0L;
154 unsigned long nss7_value=0L;
155 unsigned long total_disk_space=0L;
156 unsigned long purgeable_disk_space=0L;
157 unsigned long non_purgeable_disk_space=0L;
158 unsigned long percent_free_space=0;
159 unsigned long percent_purgeable_space=0;
160 unsigned long percent_non_purgeable_space=0;
161 unsigned long current_connections=0L;
162 unsigned long utilization=0L;
163 unsigned long cache_hits=0;
164 unsigned long cache_buffers=0L;
165 unsigned long lru_time=0L;
166 unsigned long max_packet_receive_buffers=0;
167 unsigned long used_packet_receive_buffers=0;
168 unsigned long percent_used_packet_receive_buffers=0L;
169 unsigned long sap_entries=0;
170 char uptime[MAX_INPUT_BUFFER];
172 setlocale (LC_ALL, "");
173 bindtextdomain (PACKAGE, LOCALEDIR);
174 textdomain (PACKAGE);
176 if (process_arguments(argc,argv) == ERROR)
177 usage4 (_("Could not parse arguments"));
179 /* initialize alarm signal handling */
180 signal(SIGALRM,socket_timeout_alarm_handler);
182 /* set socket timeout */
183 alarm(socket_timeout);
185 /* open connection */
186 my_tcp_connect (server_address, server_port, &sd);
188 /* get OS version string */
189 if (check_netware_version==TRUE) {
190 send_buffer = strdup ("S19\r\n");
191 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
192 if (result!=STATE_OK)
193 return result;
194 if (!strcmp(recv_buffer,"-1\n"))
195 netware_version = strdup("");
196 else {
197 recv_buffer[strlen(recv_buffer)-1]=0;
198 asprintf (&netware_version,_("NetWare %s: "),recv_buffer);
200 } else
201 netware_version = strdup("");
204 /* check CPU load */
205 if (vars_to_check==LOAD1 || vars_to_check==LOAD5 || vars_to_check==LOAD15) {
207 switch(vars_to_check) {
208 case LOAD1:
209 temp_buffer = strdup ("1");
210 break;
211 case LOAD5:
212 temp_buffer = strdup ("5");
213 break;
214 default:
215 temp_buffer = strdup ("15");
216 break;
219 close(sd);
220 my_tcp_connect (server_address, server_port, &sd);
222 asprintf (&send_buffer,"UTIL%s\r\n",temp_buffer);
223 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
224 if (result!=STATE_OK)
225 return result;
226 utilization=strtoul(recv_buffer,NULL,10);
228 close(sd);
229 my_tcp_connect (server_address, server_port, &sd);
231 send_buffer = strdup ("UPTIME\r\n");
232 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
233 if (result!=STATE_OK)
234 return result;
235 recv_buffer[strlen(recv_buffer)-1]=0;
236 sprintf(uptime,_("Up %s,"),recv_buffer);
238 if (check_critical_value==TRUE && utilization >= critical_value)
239 result=STATE_CRITICAL;
240 else if (check_warning_value==TRUE && utilization >= warning_value)
241 result=STATE_WARNING;
243 asprintf (&output_message,
244 _("Load %s - %s %s-min load average = %lu%%|load%s=%lu;%lu;%lu;0;100"),
245 state_text(result),
246 uptime,
247 temp_buffer,
248 utilization,
249 temp_buffer,
250 utilization,
251 warning_value,
252 critical_value);
254 /* check number of user connections */
255 } else if (vars_to_check==CONNS) {
257 close(sd);
258 my_tcp_connect (server_address, server_port, &sd);
260 send_buffer = strdup ("CONNECT\r\n");
261 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
262 if (result!=STATE_OK)
263 return result;
264 current_connections=strtoul(recv_buffer,NULL,10);
266 if (check_critical_value==TRUE && current_connections >= critical_value)
267 result=STATE_CRITICAL;
268 else if (check_warning_value==TRUE && current_connections >= warning_value)
269 result=STATE_WARNING;
271 asprintf (&output_message,
272 _("Conns %s - %lu current connections|Conns=%lu;%lu;%lu;;"),
273 state_text(result),
274 current_connections,
275 current_connections,
276 warning_value,
277 critical_value);
279 /* check % long term cache hits */
280 } else if (vars_to_check==LTCH) {
282 close(sd);
283 my_tcp_connect (server_address, server_port, &sd);
285 send_buffer = strdup ("S1\r\n");
286 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
287 if (result!=STATE_OK)
288 return result;
289 cache_hits=atoi(recv_buffer);
291 if (check_critical_value==TRUE && cache_hits <= critical_value)
292 result=STATE_CRITICAL;
293 else if (check_warning_value==TRUE && cache_hits <= warning_value)
294 result=STATE_WARNING;
296 asprintf (&output_message,
297 _("%s: Long term cache hits = %lu%%"),
298 state_text(result),
299 cache_hits);
301 /* check cache buffers */
302 } else if (vars_to_check==CBUFF) {
304 close(sd);
305 my_tcp_connect (server_address, server_port, &sd);
307 send_buffer = strdup ("S2\r\n");
308 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
309 if (result!=STATE_OK)
310 return result;
311 cache_buffers=strtoul(recv_buffer,NULL,10);
313 if (check_critical_value==TRUE && cache_buffers <= critical_value)
314 result=STATE_CRITICAL;
315 else if (check_warning_value==TRUE && cache_buffers <= warning_value)
316 result=STATE_WARNING;
318 asprintf (&output_message,
319 _("%s: Total cache buffers = %lu|Cachebuffers=%lu;%lu;%lu;;"),
320 state_text(result),
321 cache_buffers,
322 cache_buffers,
323 warning_value,
324 critical_value);
326 /* check dirty cache buffers */
327 } else if (vars_to_check==CDBUFF) {
329 close(sd);
330 my_tcp_connect (server_address, server_port, &sd);
332 send_buffer = strdup ("S3\r\n");
333 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
334 if (result!=STATE_OK)
335 return result;
336 cache_buffers=strtoul(recv_buffer,NULL,10);
338 if (check_critical_value==TRUE && cache_buffers >= critical_value)
339 result=STATE_CRITICAL;
340 else if (check_warning_value==TRUE && cache_buffers >= warning_value)
341 result=STATE_WARNING;
343 asprintf (&output_message,
344 _("%s: Dirty cache buffers = %lu|Dirty-Cache-Buffers=%lu;%lu;%lu;;"),
345 state_text(result),
346 cache_buffers,
347 cache_buffers,
348 warning_value,
349 critical_value);
351 /* check LRU sitting time in minutes */
352 } else if (vars_to_check==LRUM) {
354 close(sd);
355 my_tcp_connect (server_address, server_port, &sd);
357 send_buffer = strdup ("S5\r\n");
358 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
359 if (result!=STATE_OK)
360 return result;
361 lru_time=strtoul(recv_buffer,NULL,10);
363 if (check_critical_value==TRUE && lru_time <= critical_value)
364 result=STATE_CRITICAL;
365 else if (check_warning_value==TRUE && lru_time <= warning_value)
366 result=STATE_WARNING;
368 asprintf (&output_message,
369 _("%s: LRU sitting time = %lu minutes"),
370 state_text(result),
371 lru_time);
374 /* check KB free space on volume */
375 } else if (vars_to_check==VKF) {
377 close(sd);
378 my_tcp_connect (server_address, server_port, &sd);
380 asprintf (&send_buffer,"VKF%s\r\n",volume_name);
381 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
382 if (result!=STATE_OK)
383 return result;
385 if (!strcmp(recv_buffer,"-1\n")) {
386 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
387 result=STATE_CRITICAL;
388 } else {
389 free_disk_space=strtoul(recv_buffer,NULL,10);
390 if (check_critical_value==TRUE && free_disk_space <= critical_value)
391 result=STATE_CRITICAL;
392 else if (check_warning_value==TRUE && free_disk_space <= warning_value)
393 result=STATE_WARNING;
394 asprintf (&output_message,
395 _("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"),
396 (result==STATE_OK)?"":_("Only "),
397 free_disk_space,
398 volume_name,
399 volume_name,
400 free_disk_space,
401 warning_value,
402 critical_value);
405 /* check MB free space on volume */
406 } else if (vars_to_check==VMF) {
408 asprintf (&send_buffer,"VMF%s\r\n",volume_name);
409 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
410 if (result!=STATE_OK)
411 return result;
413 if (!strcmp(recv_buffer,"-1\n")) {
414 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
415 result=STATE_CRITICAL;
416 } else {
417 free_disk_space=strtoul(recv_buffer,NULL,10);
418 if (check_critical_value==TRUE && free_disk_space <= critical_value)
419 result=STATE_CRITICAL;
420 else if (check_warning_value==TRUE && free_disk_space <= warning_value)
421 result=STATE_WARNING;
422 asprintf (&output_message,
423 _("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"),
424 (result==STATE_OK)?"":_("Only "),
425 free_disk_space,
426 volume_name,
427 volume_name,
428 free_disk_space,
429 warning_value,
430 critical_value);
432 /* check MB used space on volume */
433 } else if (vars_to_check==VMU) {
435 asprintf (&send_buffer,"VMU%s\r\n",volume_name);
436 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
437 if (result!=STATE_OK)
438 return result;
440 if (!strcmp(recv_buffer,"-1\n")) {
441 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
442 result=STATE_CRITICAL;
443 } else {
444 free_disk_space=strtoul(recv_buffer,NULL,10);
445 if (check_critical_value==TRUE && free_disk_space <= critical_value)
446 result=STATE_CRITICAL;
447 else if (check_warning_value==TRUE && free_disk_space <= warning_value)
448 result=STATE_WARNING;
449 asprintf (&output_message,
450 _("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"),
451 (result==STATE_OK)?"":_("Only "),
452 free_disk_space,
453 volume_name,
454 volume_name,
455 free_disk_space,
456 warning_value,
457 critical_value);
461 /* check % free space on volume */
462 } else if (vars_to_check==VPF) {
464 close(sd);
465 my_tcp_connect (server_address, server_port, &sd);
467 asprintf (&send_buffer,"VKF%s\r\n",volume_name);
468 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
469 if (result!=STATE_OK)
470 return result;
472 if (!strcmp(recv_buffer,"-1\n")) {
474 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
475 result=STATE_CRITICAL;
477 } else {
479 free_disk_space=strtoul(recv_buffer,NULL,10);
481 close(sd);
482 my_tcp_connect (server_address, server_port, &sd);
484 asprintf (&send_buffer,"VKS%s\r\n",volume_name);
485 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
486 if (result!=STATE_OK)
487 return result;
488 total_disk_space=strtoul(recv_buffer,NULL,10);
490 percent_free_space=(unsigned long)(((double)free_disk_space/(double)total_disk_space)*100.0);
492 if (check_critical_value==TRUE && percent_free_space <= critical_value)
493 result=STATE_CRITICAL;
494 else if (check_warning_value==TRUE && percent_free_space <= warning_value)
495 result=STATE_WARNING;
496 free_disk_space/=1024;
497 total_disk_space/=1024;
498 asprintf (&output_message,_("%lu MB (%lu%%) free on volume %s - total %lu MB|FreeMB%s=%lu;%lu;%lu;0;100"),
499 free_disk_space,
500 percent_free_space,
501 volume_name,
502 total_disk_space,
503 volume_name,
504 percent_free_space,
505 warning_value,
506 critical_value
510 /* check to see if DS Database is open or closed */
511 } else if (vars_to_check==DSDB) {
513 close(sd);
514 my_tcp_connect (server_address, server_port, &sd);
516 send_buffer = strdup ("S11\r\n");
517 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
518 if (result!=STATE_OK)
519 return result;
520 if (atoi(recv_buffer)==1)
521 result=STATE_OK;
522 else
523 result=STATE_WARNING;
525 close(sd);
526 my_tcp_connect (server_address, server_port, &sd);
528 send_buffer = strdup ("S13\r\n");
529 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
530 temp_buffer=strtok(recv_buffer,"\r\n");
532 asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer);
534 /* check to see if logins are enabled */
535 } else if (vars_to_check==LOGINS) {
537 close(sd);
538 my_tcp_connect (server_address, server_port, &sd);
540 send_buffer = strdup ("S12\r\n");
541 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
542 if (result!=STATE_OK)
543 return result;
544 if (atoi(recv_buffer)==1)
545 result=STATE_OK;
546 else
547 result=STATE_WARNING;
549 asprintf (&output_message,_("Logins are %s"),(result==STATE_OK)?_("enabled"):_("disabled"));
552 /* check NRM Health Status Summary*/
553 } else if (vars_to_check==NRMH) {
555 asprintf (&send_buffer,"NRMH\r\n");
556 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
557 if (result!=STATE_OK)
558 return result;
560 nrm_health_status=atoi(recv_buffer);
562 if (nrm_health_status==2) {
563 result=STATE_OK;
564 asprintf (&output_message,_("CRITICAL - NRM Status is bad!"));
566 else {
567 if (nrm_health_status==1) {
568 result=STATE_WARNING;
569 asprintf (&output_message,_("Warning - NRM Status is suspect!"));
572 asprintf (&output_message,_("OK - NRM Status is good!"));
577 /* check packet receive buffers */
578 } else if (vars_to_check==UPRB || vars_to_check==PUPRB) {
580 close(sd);
581 my_tcp_connect (server_address, server_port, &sd);
583 asprintf (&send_buffer,"S15\r\n");
584 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
585 if (result!=STATE_OK)
586 return result;
588 used_packet_receive_buffers=atoi(recv_buffer);
590 close(sd);
591 my_tcp_connect (server_address, server_port, &sd);
593 asprintf (&send_buffer,"S16\r\n");
594 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
595 if (result!=STATE_OK)
596 return result;
598 max_packet_receive_buffers=atoi(recv_buffer);
600 percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0);
602 if (vars_to_check==UPRB) {
603 if (check_critical_value==TRUE && used_packet_receive_buffers >= critical_value)
604 result=STATE_CRITICAL;
605 else if (check_warning_value==TRUE && used_packet_receive_buffers >= warning_value)
606 result=STATE_WARNING;
607 } else {
608 if (check_critical_value==TRUE && percent_used_packet_receive_buffers >= critical_value)
609 result=STATE_CRITICAL;
610 else if (check_warning_value==TRUE && percent_used_packet_receive_buffers >= warning_value)
611 result=STATE_WARNING;
614 asprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
616 /* check SAP table entries */
617 } else if (vars_to_check==SAPENTRIES) {
619 close(sd);
620 my_tcp_connect (server_address, server_port, &sd);
622 if (sap_number==-1)
623 asprintf (&send_buffer,"S9\r\n");
624 else
625 asprintf (&send_buffer,"S9.%d\r\n",sap_number);
626 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
627 if (result!=STATE_OK)
628 return result;
630 sap_entries=atoi(recv_buffer);
632 if (check_critical_value==TRUE && sap_entries >= critical_value)
633 result=STATE_CRITICAL;
634 else if (check_warning_value==TRUE && sap_entries >= warning_value)
635 result=STATE_WARNING;
637 if (sap_number==-1)
638 asprintf (&output_message,_("%lu entries in SAP table"),sap_entries);
639 else
640 asprintf (&output_message,_("%lu entries in SAP table for SAP type %d"),sap_entries,sap_number);
642 /* check KB purgeable space on volume */
643 } else if (vars_to_check==VKP) {
645 close(sd);
646 my_tcp_connect (server_address, server_port, &sd);
648 asprintf (&send_buffer,"VKP%s\r\n",volume_name);
649 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
650 if (result!=STATE_OK)
651 return result;
653 if (!strcmp(recv_buffer,"-1\n")) {
654 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
655 result=STATE_CRITICAL;
656 } else {
657 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
658 if (check_critical_value==TRUE && purgeable_disk_space >= critical_value)
659 result=STATE_CRITICAL;
660 else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
661 result=STATE_WARNING;
662 asprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
663 (result==STATE_OK)?"":_("Only "),
664 purgeable_disk_space,
665 volume_name,
666 volume_name,
667 purgeable_disk_space,
668 warning_value,
669 critical_value);
671 /* check MB purgeable space on volume */
672 } else if (vars_to_check==VMP) {
674 asprintf (&send_buffer,"VMP%s\r\n",volume_name);
675 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
676 if (result!=STATE_OK)
677 return result;
679 if (!strcmp(recv_buffer,"-1\n")) {
680 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
681 result=STATE_CRITICAL;
682 } else {
683 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
684 if (check_critical_value==TRUE && purgeable_disk_space >= critical_value)
685 result=STATE_CRITICAL;
686 else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
687 result=STATE_WARNING;
688 asprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
689 (result==STATE_OK)?"":_("Only "),
690 purgeable_disk_space,
691 volume_name,
692 volume_name,
693 purgeable_disk_space,
694 warning_value,
695 critical_value);
698 /* check % purgeable space on volume */
699 } else if (vars_to_check==VPP) {
701 close(sd);
702 my_tcp_connect (server_address, server_port, &sd);
704 asprintf (&send_buffer,"VKP%s\r\n",volume_name);
705 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
706 if (result!=STATE_OK)
707 return result;
709 if (!strcmp(recv_buffer,"-1\n")) {
711 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
712 result=STATE_CRITICAL;
714 } else {
716 purgeable_disk_space=strtoul(recv_buffer,NULL,10);
718 close(sd);
719 my_tcp_connect (server_address, server_port, &sd);
721 asprintf (&send_buffer,"VKS%s\r\n",volume_name);
722 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
723 if (result!=STATE_OK)
724 return result;
725 total_disk_space=strtoul(recv_buffer,NULL,10);
727 percent_purgeable_space=(unsigned long)(((double)purgeable_disk_space/(double)total_disk_space)*100.0);
729 if (check_critical_value==TRUE && percent_purgeable_space >= critical_value)
730 result=STATE_CRITICAL;
731 else if (check_warning_value==TRUE && percent_purgeable_space >= warning_value)
732 result=STATE_WARNING;
733 purgeable_disk_space/=1024;
734 asprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"),
735 purgeable_disk_space,
736 percent_purgeable_space,
737 volume_name,
738 volume_name,
739 percent_purgeable_space,
740 warning_value,
741 critical_value
745 /* check KB not yet purgeable space on volume */
746 } else if (vars_to_check==VKNP) {
748 close(sd);
749 my_tcp_connect (server_address, server_port, &sd);
751 asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
752 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
753 if (result!=STATE_OK)
754 return result;
756 if (!strcmp(recv_buffer,"-1\n")) {
757 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
758 result=STATE_CRITICAL;
759 } else {
760 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
761 if (check_critical_value==TRUE && non_purgeable_disk_space >= critical_value)
762 result=STATE_CRITICAL;
763 else if (check_warning_value==TRUE && non_purgeable_disk_space >= warning_value)
764 result=STATE_WARNING;
765 asprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name);
768 /* check % not yet purgeable space on volume */
769 } else if (vars_to_check==VPNP) {
771 close(sd);
772 my_tcp_connect (server_address, server_port, &sd);
774 asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
775 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
776 if (result!=STATE_OK)
777 return result;
779 if (!strcmp(recv_buffer,"-1\n")) {
781 asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
782 result=STATE_CRITICAL;
784 } else {
786 non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
788 close(sd);
789 my_tcp_connect (server_address, server_port, &sd);
791 asprintf (&send_buffer,"VKS%s\r\n",volume_name);
792 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
793 if (result!=STATE_OK)
794 return result;
795 total_disk_space=strtoul(recv_buffer,NULL,10);
797 percent_non_purgeable_space=(unsigned long)(((double)non_purgeable_disk_space/(double)total_disk_space)*100.0);
799 if (check_critical_value==TRUE && percent_non_purgeable_space >= critical_value)
800 result=STATE_CRITICAL;
801 else if (check_warning_value==TRUE && percent_non_purgeable_space >= warning_value)
802 result=STATE_WARNING;
803 purgeable_disk_space/=1024;
804 asprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
807 /* check # of open files */
808 } else if (vars_to_check==OFILES) {
810 close(sd);
811 my_tcp_connect (server_address, server_port, &sd);
813 asprintf (&send_buffer,"S18\r\n");
814 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
815 if (result!=STATE_OK)
816 return result;
818 open_files=atoi(recv_buffer);
820 if (check_critical_value==TRUE && open_files >= critical_value)
821 result=STATE_CRITICAL;
822 else if (check_warning_value==TRUE && open_files >= warning_value)
823 result=STATE_WARNING;
825 asprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"),
826 open_files,
827 open_files,
828 warning_value,
829 critical_value);
832 /* check # of abended threads (Netware > 5.x only) */
833 } else if (vars_to_check==ABENDS) {
835 close(sd);
836 my_tcp_connect (server_address, server_port, &sd);
838 asprintf (&send_buffer,"S17\r\n");
839 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
840 if (result!=STATE_OK)
841 return result;
843 abended_threads=atoi(recv_buffer);
845 if (check_critical_value==TRUE && abended_threads >= critical_value)
846 result=STATE_CRITICAL;
847 else if (check_warning_value==TRUE && abended_threads >= warning_value)
848 result=STATE_WARNING;
850 asprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"),
851 abended_threads,
852 abended_threads,
853 warning_value,
854 critical_value);
856 /* check # of current service processes (Netware 5.x only) */
857 } else if (vars_to_check==CSPROCS) {
859 close(sd);
860 my_tcp_connect (server_address, server_port, &sd);
862 asprintf (&send_buffer,"S20\r\n");
863 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
864 if (result!=STATE_OK)
865 return result;
867 max_service_processes=atoi(recv_buffer);
869 close(sd);
870 my_tcp_connect (server_address, server_port, &sd);
872 asprintf (&send_buffer,"S21\r\n");
873 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
874 if (result!=STATE_OK)
875 return result;
877 current_service_processes=atoi(recv_buffer);
879 if (check_critical_value==TRUE && current_service_processes >= critical_value)
880 result=STATE_CRITICAL;
881 else if (check_warning_value==TRUE && current_service_processes >= warning_value)
882 result=STATE_WARNING;
884 asprintf (&output_message,
885 _("%lu current service processes (%lu max)|Processes=%lu;%lu;%lu;0;%lu"),
886 current_service_processes,
887 max_service_processes,
888 current_service_processes,
889 warning_value,
890 critical_value,
891 max_service_processes);
893 /* check # Timesync Status */
894 } else if (vars_to_check==TSYNC) {
896 close(sd);
897 my_tcp_connect (server_address, server_port, &sd);
899 asprintf (&send_buffer,"S22\r\n");
900 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
901 if (result!=STATE_OK)
902 return result;
904 time_sync_status=atoi(recv_buffer);
906 if (time_sync_status==0) {
907 result=STATE_CRITICAL;
908 asprintf (&output_message,_("CRITICAL - Time not in sync with network!"));
910 else {
911 asprintf (&output_message,_("OK - Time in sync with network!"));
918 /* check LRU sitting time in secondss */
919 } else if (vars_to_check==LRUS) {
921 close(sd);
922 my_tcp_connect (server_address, server_port, &sd);
924 send_buffer = strdup ("S4\r\n");
925 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
926 if (result!=STATE_OK)
927 return result;
928 lru_time=strtoul(recv_buffer,NULL,10);
930 if (check_critical_value==TRUE && lru_time <= critical_value)
931 result=STATE_CRITICAL;
932 else if (check_warning_value==TRUE && lru_time <= warning_value)
933 result=STATE_WARNING;
934 asprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time);
937 /* check % dirty cacheobuffers as a percentage of the total*/
938 } else if (vars_to_check==DCB) {
940 close(sd);
941 my_tcp_connect (server_address, server_port, &sd);
943 send_buffer = strdup ("S6\r\n");
944 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
945 if (result!=STATE_OK)
946 return result;
947 dirty_cache_buffers=atoi(recv_buffer);
949 if (check_critical_value==TRUE && dirty_cache_buffers <= critical_value)
950 result=STATE_CRITICAL;
951 else if (check_warning_value==TRUE && dirty_cache_buffers <= warning_value)
952 result=STATE_WARNING;
953 asprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"),
954 dirty_cache_buffers,
955 dirty_cache_buffers,
956 warning_value,
957 critical_value);
959 /* check % total cache buffers as a percentage of the original*/
960 } else if (vars_to_check==TCB) {
962 close(sd);
963 my_tcp_connect (server_address, server_port, &sd);
965 send_buffer = strdup ("S7\r\n");
966 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
967 if (result!=STATE_OK)
968 return result;
969 total_cache_buffers=atoi(recv_buffer);
971 if (check_critical_value==TRUE && total_cache_buffers <= critical_value)
972 result=STATE_CRITICAL;
973 else if (check_warning_value==TRUE && total_cache_buffers <= warning_value)
974 result=STATE_WARNING;
975 asprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"),
976 total_cache_buffers,
977 total_cache_buffers,
978 warning_value,
979 critical_value);
981 } else if (vars_to_check==DSVER) {
983 close(sd);
984 my_tcp_connect (server_address, server_port, &sd);
986 asprintf (&send_buffer,"S13\r\n");
987 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
988 if (result!=STATE_OK)
989 return result;
991 recv_buffer[strlen(recv_buffer)-1]=0;
993 asprintf (&output_message,_("NDS Version %s"),recv_buffer);
995 } else if (vars_to_check==UPTIME) {
997 close(sd);
998 my_tcp_connect (server_address, server_port, &sd);
1000 asprintf (&send_buffer,"UPTIME\r\n");
1001 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1002 if (result!=STATE_OK)
1003 return result;
1006 recv_buffer[sizeof(recv_buffer)-1]=0;
1007 recv_buffer[strlen(recv_buffer)-1]=0;
1009 asprintf (&output_message,_("Up %s"),recv_buffer);
1011 } else if (vars_to_check==NLM) {
1013 close(sd);
1014 my_tcp_connect (server_address, server_port, &sd);
1016 asprintf (&send_buffer,"S24:%s\r\n",nlm_name);
1017 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1018 if (result!=STATE_OK)
1019 return result;
1021 recv_buffer[strlen(recv_buffer)-1]=0;
1022 if (strcmp(recv_buffer,"-1")) {
1023 asprintf (&output_message,_("Module %s version %s is loaded"),nlm_name,recv_buffer);
1024 } else {
1025 result=STATE_CRITICAL;
1026 asprintf (&output_message,_("Module %s is not loaded"),nlm_name);
1029 } else if (vars_to_check==NRMP) {
1031 asprintf (&send_buffer,"NRMP:%s\r\n",nrmp_name);
1032 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1033 if (result!=STATE_OK)
1034 return result;
1036 if (!strcmp(recv_buffer,"-1\n")) {
1037 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmp_name);
1038 result=STATE_CRITICAL;
1039 } else {
1040 nrmp_value=strtoul(recv_buffer,NULL,10);
1041 if (check_critical_value==TRUE && nrmp_value <= critical_value)
1042 result=STATE_CRITICAL;
1043 else if (check_warning_value==TRUE && nrmp_value <= warning_value)
1044 result=STATE_WARNING;
1045 asprintf (&output_message,
1046 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1047 nrmp_name,
1048 nrmp_value,
1049 nrmp_name,
1050 nrmp_value,
1051 warning_value,
1052 critical_value);
1055 } else if (vars_to_check==NRMM) {
1057 asprintf (&send_buffer,"NRMM:%s\r\n",nrmm_name);
1058 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1059 if (result!=STATE_OK)
1060 return result;
1062 if (!strcmp(recv_buffer,"-1\n")) {
1063 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmm_name);
1064 result=STATE_CRITICAL;
1065 } else {
1066 nrmm_value=strtoul(recv_buffer,NULL,10);
1067 if (check_critical_value==TRUE && nrmm_value <= critical_value)
1068 result=STATE_CRITICAL;
1069 else if (check_warning_value==TRUE && nrmm_value <= warning_value)
1070 result=STATE_WARNING;
1071 asprintf (&output_message,
1072 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1073 nrmm_name,
1074 nrmm_value,
1075 nrmm_name,
1076 nrmm_value,
1077 warning_value,
1078 critical_value);
1081 } else if (vars_to_check==NRMS) {
1083 asprintf (&send_buffer,"NRMS:%s\r\n",nrms_name);
1084 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1085 if (result!=STATE_OK)
1086 return result;
1088 if (!strcmp(recv_buffer,"-1\n")) {
1089 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrms_name);
1090 result=STATE_CRITICAL;
1091 } else {
1092 nrms_value=strtoul(recv_buffer,NULL,10);
1093 if (check_critical_value==TRUE && nrms_value >= critical_value)
1094 result=STATE_CRITICAL;
1095 else if (check_warning_value==TRUE && nrms_value >= warning_value)
1096 result=STATE_WARNING;
1097 asprintf (&output_message,
1098 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1099 nrms_name,
1100 nrms_value,
1101 nrms_name,
1102 nrms_value,
1103 warning_value,
1104 critical_value);
1107 } else if (vars_to_check==NSS1) {
1109 asprintf (&send_buffer,"NSS1:%s\r\n",nss1_name);
1110 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1111 if (result!=STATE_OK)
1112 return result;
1114 if (!strcmp(recv_buffer,"-1\n")) {
1115 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss1_name);
1116 result=STATE_CRITICAL;
1117 } else {
1118 nss1_value=strtoul(recv_buffer,NULL,10);
1119 if (check_critical_value==TRUE && nss1_value >= critical_value)
1120 result=STATE_CRITICAL;
1121 else if (check_warning_value==TRUE && nss1_value >= warning_value)
1122 result=STATE_WARNING;
1123 asprintf (&output_message,
1124 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1125 nss1_name,
1126 nss1_value,
1127 nss1_name,
1128 nss1_value,
1129 warning_value,
1130 critical_value);
1133 } else if (vars_to_check==NSS2) {
1135 asprintf (&send_buffer,"NSS2:%s\r\n",nss2_name);
1136 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1137 if (result!=STATE_OK)
1138 return result;
1140 if (!strcmp(recv_buffer,"-1\n")) {
1141 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss2_name);
1142 result=STATE_CRITICAL;
1143 } else {
1144 nss2_value=strtoul(recv_buffer,NULL,10);
1145 if (check_critical_value==TRUE && nss2_value >= critical_value)
1146 result=STATE_CRITICAL;
1147 else if (check_warning_value==TRUE && nss2_value >= warning_value)
1148 result=STATE_WARNING;
1149 asprintf (&output_message,
1150 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1151 nss2_name,
1152 nss2_value,
1153 nss2_name,
1154 nss2_value,
1155 warning_value,
1156 critical_value);
1159 } else if (vars_to_check==NSS3) {
1161 asprintf (&send_buffer,"NSS3:%s\r\n",nss3_name);
1162 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1163 if (result!=STATE_OK)
1164 return result;
1166 if (!strcmp(recv_buffer,"-1\n")) {
1167 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss3_name);
1168 result=STATE_CRITICAL;
1169 } else {
1170 nss3_value=strtoul(recv_buffer,NULL,10);
1171 if (check_critical_value==TRUE && nss3_value >= critical_value)
1172 result=STATE_CRITICAL;
1173 else if (check_warning_value==TRUE && nss3_value >= warning_value)
1174 result=STATE_WARNING;
1175 asprintf (&output_message,
1176 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1177 nss3_name,
1178 nss3_value,
1179 nss3_name,
1180 nss3_value,
1181 warning_value,
1182 critical_value);
1185 } else if (vars_to_check==NSS4) {
1187 asprintf (&send_buffer,"NSS4:%s\r\n",nss4_name);
1188 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1189 if (result!=STATE_OK)
1190 return result;
1192 if (!strcmp(recv_buffer,"-1\n")) {
1193 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss4_name);
1194 result=STATE_CRITICAL;
1195 } else {
1196 nss4_value=strtoul(recv_buffer,NULL,10);
1197 if (check_critical_value==TRUE && nss4_value >= critical_value)
1198 result=STATE_CRITICAL;
1199 else if (check_warning_value==TRUE && nss4_value >= warning_value)
1200 result=STATE_WARNING;
1201 asprintf (&output_message,
1202 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1203 nss4_name,
1204 nss4_value,
1205 nss4_name,
1206 nss4_value,
1207 warning_value,
1208 critical_value);
1211 } else if (vars_to_check==NSS5) {
1213 asprintf (&send_buffer,"NSS5:%s\r\n",nss5_name);
1214 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1215 if (result!=STATE_OK)
1216 return result;
1218 if (!strcmp(recv_buffer,"-1\n")) {
1219 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss5_name);
1220 result=STATE_CRITICAL;
1221 } else {
1222 nss5_value=strtoul(recv_buffer,NULL,10);
1223 if (check_critical_value==TRUE && nss5_value >= critical_value)
1224 result=STATE_CRITICAL;
1225 else if (check_warning_value==TRUE && nss5_value >= warning_value)
1226 result=STATE_WARNING;
1227 asprintf (&output_message,
1228 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1229 nss5_name,
1230 nss5_value,
1231 nss5_name,
1232 nss5_value,
1233 warning_value,
1234 critical_value);
1237 } else if (vars_to_check==NSS6) {
1239 asprintf (&send_buffer,"NSS6:%s\r\n",nss6_name);
1240 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1241 if (result!=STATE_OK)
1242 return result;
1244 if (!strcmp(recv_buffer,"-1\n")) {
1245 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss6_name);
1246 result=STATE_CRITICAL;
1247 } else {
1248 nss6_value=strtoul(recv_buffer,NULL,10);
1249 if (check_critical_value==TRUE && nss6_value >= critical_value)
1250 result=STATE_CRITICAL;
1251 else if (check_warning_value==TRUE && nss6_value >= warning_value)
1252 result=STATE_WARNING;
1253 asprintf (&output_message,
1254 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1255 nss6_name,
1256 nss6_value,
1257 nss6_name,
1258 nss6_value,
1259 warning_value,
1260 critical_value);
1263 } else if (vars_to_check==NSS7) {
1265 asprintf (&send_buffer,"NSS7:%s\r\n",nss7_name);
1266 result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
1267 if (result!=STATE_OK)
1268 return result;
1270 if (!strcmp(recv_buffer,"-1\n")) {
1271 asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss7_name);
1272 result=STATE_CRITICAL;
1273 } else {
1274 nss7_value=strtoul(recv_buffer,NULL,10);
1275 if (check_critical_value==TRUE && nss7_value >= critical_value)
1276 result=STATE_CRITICAL;
1277 else if (check_warning_value==TRUE && nss7_value >= warning_value)
1278 result=STATE_WARNING;
1279 asprintf (&output_message,
1280 _("%s is %lu|%s=%lu;%lu;%lu;;"),
1281 nss7_name,
1282 nss7_value,
1283 nss7_name,
1284 nss7_value,
1285 warning_value,
1286 critical_value);
1291 else {
1293 output_message = strdup (_("Nothing to check!\n"));
1294 result=STATE_UNKNOWN;
1298 close (sd);
1300 /* reset timeout */
1301 alarm(0);
1303 printf("%s%s\n",netware_version,output_message);
1305 return result;
1310 /* process command-line arguments */
1311 int process_arguments(int argc, char **argv) {
1312 int c;
1314 int option = 0;
1315 static struct option longopts[] =
1317 {"port", required_argument,0,'p'},
1318 {"timeout", required_argument,0,'t'},
1319 {"critical", required_argument,0,'c'},
1320 {"warning", required_argument,0,'w'},
1321 {"variable", required_argument,0,'v'},
1322 {"hostname", required_argument,0,'H'},
1323 {"osversion",no_argument, 0,'o'},
1324 {"version", no_argument, 0,'V'},
1325 {"help", no_argument, 0,'h'},
1326 {0,0,0,0}
1329 /* no options were supplied */
1330 if (argc<2) return ERROR;
1332 /* backwards compatibility */
1333 if (! is_option(argv[1])) {
1334 server_address=argv[1];
1335 argv[1]=argv[0];
1336 argv=&argv[1];
1337 argc--;
1340 for (c=1;c<argc;c++) {
1341 if (strcmp("-to",argv[c])==0)
1342 strcpy(argv[c],"-t");
1343 else if (strcmp("-wv",argv[c])==0)
1344 strcpy(argv[c],"-w");
1345 else if (strcmp("-cv",argv[c])==0)
1346 strcpy(argv[c],"-c");
1349 while (1) {
1350 c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",longopts,&option);
1352 if (c==-1||c==EOF||c==1)
1353 break;
1355 switch (c)
1357 case '?': /* print short usage statement if args not parsable */
1358 usage5 ();
1359 case 'h': /* help */
1360 print_help();
1361 exit(STATE_OK);
1362 case 'V': /* version */
1363 print_revision(progname, revision);
1364 exit(STATE_OK);
1365 case 'H': /* hostname */
1366 server_address=optarg;
1367 break;
1368 case 'o': /* display nos version */
1369 check_netware_version=TRUE;
1370 break;
1371 case 'p': /* port */
1372 if (is_intnonneg(optarg))
1373 server_port=atoi(optarg);
1374 else
1375 die(STATE_UNKNOWN,_("Server port an integer\n"));
1376 break;
1377 case 'v':
1378 if (strlen(optarg)<3)
1379 return ERROR;
1380 if (!strcmp(optarg,"LOAD1"))
1381 vars_to_check=LOAD1;
1382 else if (!strcmp(optarg,"LOAD5"))
1383 vars_to_check=LOAD5;
1384 else if (!strcmp(optarg,"LOAD15"))
1385 vars_to_check=LOAD15;
1386 else if (!strcmp(optarg,"CONNS"))
1387 vars_to_check=CONNS;
1388 else if (!strcmp(optarg,"LTCH"))
1389 vars_to_check=LTCH;
1390 else if (!strcmp(optarg,"DCB"))
1391 vars_to_check=DCB;
1392 else if (!strcmp(optarg,"TCB"))
1393 vars_to_check=TCB;
1394 else if (!strcmp(optarg,"CBUFF"))
1395 vars_to_check=CBUFF;
1396 else if (!strcmp(optarg,"CDBUFF"))
1397 vars_to_check=CDBUFF;
1398 else if (!strcmp(optarg,"LRUM"))
1399 vars_to_check=LRUM;
1400 else if (!strcmp(optarg,"LRUS"))
1401 vars_to_check=LRUS;
1402 else if (strncmp(optarg,"VPF",3)==0) {
1403 vars_to_check=VPF;
1404 volume_name = strdup (optarg+3);
1405 if (!strcmp(volume_name,""))
1406 volume_name = strdup ("SYS");
1408 else if (strncmp(optarg,"VKF",3)==0) {
1409 vars_to_check=VKF;
1410 volume_name = strdup (optarg+3);
1411 if (!strcmp(volume_name,""))
1412 volume_name = strdup ("SYS");
1414 else if (strncmp(optarg,"VMF",3)==0) {
1415 vars_to_check=VMF;
1416 volume_name = strdup (optarg+3);
1417 if (!strcmp(volume_name,""))
1418 volume_name = strdup ("SYS");
1420 else if (!strcmp(optarg,"DSDB"))
1421 vars_to_check=DSDB;
1422 else if (!strcmp(optarg,"LOGINS"))
1423 vars_to_check=LOGINS;
1424 else if (!strcmp(optarg,"NRMH"))
1425 vars_to_check=NRMH;
1426 else if (!strcmp(optarg,"UPRB"))
1427 vars_to_check=UPRB;
1428 else if (!strcmp(optarg,"PUPRB"))
1429 vars_to_check=PUPRB;
1430 else if (!strncmp(optarg,"SAPENTRIES",10)) {
1431 vars_to_check=SAPENTRIES;
1432 if (strlen(optarg)>10)
1433 sap_number=atoi(optarg+10);
1434 else
1435 sap_number=-1;
1437 else if (!strcmp(optarg,"OFILES"))
1438 vars_to_check=OFILES;
1439 else if (strncmp(optarg,"VKP",3)==0) {
1440 vars_to_check=VKP;
1441 volume_name = strdup (optarg+3);
1442 if (!strcmp(volume_name,""))
1443 volume_name = strdup ("SYS");
1445 else if (strncmp(optarg,"VMP",3)==0) {
1446 vars_to_check=VMP;
1447 volume_name = strdup (optarg+3);
1448 if (!strcmp(volume_name,""))
1449 volume_name = strdup ("SYS");
1451 else if (strncmp(optarg,"VMU",3)==0) {
1452 vars_to_check=VMU;
1453 volume_name = strdup (optarg+3);
1454 if (!strcmp(volume_name,""))
1455 volume_name = strdup ("SYS");
1457 else if (strncmp(optarg,"VPP",3)==0) {
1458 vars_to_check=VPP;
1459 volume_name = strdup (optarg+3);
1460 if (!strcmp(volume_name,""))
1461 volume_name = strdup ("SYS");
1463 else if (strncmp(optarg,"VKNP",4)==0) {
1464 vars_to_check=VKNP;
1465 volume_name = strdup (optarg+4);
1466 if (!strcmp(volume_name,""))
1467 volume_name = strdup ("SYS");
1469 else if (strncmp(optarg,"VPNP",4)==0) {
1470 vars_to_check=VPNP;
1471 volume_name = strdup (optarg+4);
1472 if (!strcmp(volume_name,""))
1473 volume_name = strdup("SYS");
1475 else if (!strcmp(optarg,"ABENDS"))
1476 vars_to_check=ABENDS;
1477 else if (!strcmp(optarg,"CSPROCS"))
1478 vars_to_check=CSPROCS;
1479 else if (!strcmp(optarg,"TSYNC"))
1480 vars_to_check=TSYNC;
1481 else if (!strcmp(optarg,"DSVER"))
1482 vars_to_check=DSVER;
1483 else if (!strcmp(optarg,"UPTIME")) {
1484 vars_to_check=UPTIME;
1486 else if (strncmp(optarg,"NLM:",4)==0) {
1487 vars_to_check=NLM;
1488 nlm_name=strdup (optarg+4);
1490 else if (strncmp(optarg,"NRMP",4)==0) {
1491 vars_to_check=NRMP;
1492 nrmp_name = strdup (optarg+4);
1493 if (!strcmp(nrmp_name,""))
1494 nrmp_name = strdup ("AVAILABLE_MEMORY");
1496 else if (strncmp(optarg,"NRMM",4)==0) {
1497 vars_to_check=NRMM;
1498 nrmm_name = strdup (optarg+4);
1499 if (!strcmp(nrmm_name,""))
1500 nrmm_name = strdup ("AVAILABLE_CACHE_MEMORY");
1504 else if (strncmp(optarg,"NRMS",4)==0) {
1505 vars_to_check=NRMS;
1506 nrms_name = strdup (optarg+4);
1507 if (!strcmp(nrms_name,""))
1508 nrms_name = strdup ("USED_SWAP_SPACE");
1512 else if (strncmp(optarg,"NSS1",4)==0) {
1513 vars_to_check=NSS1;
1514 nss1_name = strdup (optarg+4);
1515 if (!strcmp(nss1_name,""))
1516 nss1_name = strdup ("CURRENTBUFFERCACHESIZE");
1520 else if (strncmp(optarg,"NSS2",4)==0) {
1521 vars_to_check=NSS2;
1522 nss2_name = strdup (optarg+4);
1523 if (!strcmp(nss2_name,""))
1524 nss2_name = strdup ("CACHEHITS");
1528 else if (strncmp(optarg,"NSS3",4)==0) {
1529 vars_to_check=NSS3;
1530 nss3_name = strdup (optarg+4);
1531 if (!strcmp(nss3_name,""))
1532 nss3_name = strdup ("CACHEGITPERCENT");
1536 else if (strncmp(optarg,"NSS4",4)==0) {
1537 vars_to_check=NSS4;
1538 nss4_name = strdup (optarg+4);
1539 if (!strcmp(nss4_name,""))
1540 nss4_name = strdup ("CURRENTOPENCOUNT");
1544 else if (strncmp(optarg,"NSS5",4)==0) {
1545 vars_to_check=NSS5;
1546 nss5_name = strdup (optarg+4);
1547 if (!strcmp(nss5_name,""))
1548 nss5_name = strdup ("CACHEMISSES");
1553 else if (strncmp(optarg,"NSS6",4)==0) {
1554 vars_to_check=NSS6;
1555 nss6_name = strdup (optarg+4);
1556 if (!strcmp(nss6_name,""))
1557 nss6_name = strdup ("PENDINGWORKSCOUNT");
1562 else if (strncmp(optarg,"NSS7",4)==0) {
1563 vars_to_check=NSS7;
1564 nss7_name = strdup (optarg+4);
1565 if (!strcmp(nss7_name,""))
1566 nss7_name = strdup ("CACHESIZE");
1571 else
1572 return ERROR;
1573 break;
1574 case 'w': /* warning threshold */
1575 warning_value=strtoul(optarg,NULL,10);
1576 check_warning_value=TRUE;
1577 break;
1578 case 'c': /* critical threshold */
1579 critical_value=strtoul(optarg,NULL,10);
1580 check_critical_value=TRUE;
1581 break;
1582 case 't': /* timeout */
1583 socket_timeout=atoi(optarg);
1584 if (socket_timeout<=0)
1585 return ERROR;
1590 return OK;
1595 void print_help(void)
1597 char *myport;
1598 asprintf (&myport, "%d", PORT);
1600 print_revision (progname, revision);
1602 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
1603 printf (COPYRIGHT, copyright, email);
1605 printf ("%s\n", _("This plugin attempts to contact the MRTGEXT NLM running on a"));
1606 printf ("%s\n", _("Novell server to gather the requested system information."));
1608 printf ("\n\n");
1610 print_usage();
1612 printf (_(UT_HELP_VRSN));
1614 printf (_(UT_HOST_PORT), 'p', myport);
1616 printf (" %s\n", "-v, --variable=STRING");
1617 printf (" %s\n", _("Variable to check. Valid variables include:"));
1618 printf (" %s\n", _("LOAD1 = 1 minute average CPU load"));
1619 printf (" %s\n", _("LOAD5 = 5 minute average CPU load"));
1620 printf (" %s\n", _("LOAD15 = 15 minute average CPU load"));
1621 printf (" %s\n", _("CSPROCS = number of current service processes (NW 5.x only)"));
1622 printf (" %s\n", _("ABENDS = number of abended threads (NW 5.x only)"));
1623 printf (" %s\n", _("UPTIME = server uptime"));
1624 printf (" %s\n", _("LTCH = percent long term cache hits"));
1625 printf (" %s\n", _("CBUFF = current number of cache buffers"));
1626 printf (" %s\n", _("CDBUFF = current number of dirty cache buffers"));
1627 printf (" %s\n", _("DCB = dirty cache buffers as a percentage of the total"));
1628 printf (" %s\n", _("TCB = dirty cache buffers as a percentage of the original"));
1629 printf (" %s\n", _("OFILES = number of open files"));
1630 printf (" %s\n", _(" VMF<vol> = MB of free space on Volume <vol>"));
1631 printf (" %s\n", _(" VMU<vol> = MB used space on Volume <vol>"));
1632 printf (" %s\n", _(" VMP<vol> = MB of purgeable space on Volume <vol>"));
1633 printf (" %s\n", _(" VPF<vol> = percent free space on volume <vol>"));
1634 printf (" %s\n", _(" VKF<vol> = KB of free space on volume <vol>"));
1635 printf (" %s\n", _(" VPP<vol> = percent purgeable space on volume <vol>"));
1636 printf (" %s\n", _(" VKP<vol> = KB of purgeable space on volume <vol>"));
1637 printf (" %s\n", _(" VPNP<vol> = percent not yet purgeable space on volume <vol>"));
1638 printf (" %s\n", _(" VKNP<vol> = KB of not yet purgeable space on volume <vol>"));
1639 printf (" %s\n", _(" LRUM = LRU sitting time in minutes"));
1640 printf (" %s\n", _(" LRUS = LRU sitting time in seconds"));
1641 printf (" %s\n", _(" DSDB = check to see if DS Database is open"));
1642 printf (" %s\n", _(" DSVER = NDS version"));
1643 printf (" %s\n", _(" UPRB = used packet receive buffers"));
1644 printf (" %s\n", _(" PUPRB = percent (of max) used packet receive buffers"));
1645 printf (" %s\n", _(" SAPENTRIES = number of entries in the SAP table"));
1646 printf (" %s\n", _(" SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>"));
1647 printf (" %s\n", _(" TSYNC = timesync status"));
1648 printf (" %s\n", _(" LOGINS = check to see if logins are enabled"));
1649 printf (" %s\n", _(" CONNS = number of currently licensed connections"));
1650 printf (" %s\n", _(" NRMH = NRM Summary Status"));
1651 printf (" %s\n", _(" NRMP<stat> = Returns the current value for a NRM health item"));
1652 printf (" %s\n", _(" NRMM<stat> = Returns the current memory stats from NRM"));
1653 printf (" %s\n", _(" NRMS<stat> = Returns the current Swapfile stats from NRM"));
1654 printf (" %s\n", _(" NSS1<stat> = Statistics from _Admin:Manage_NSS\\GeneralStats.xml"));
1655 printf (" %s\n", _(" NSS3<stat> = Statistics from _Admin:Manage_NSS\\NameCache.xml"));
1656 printf (" %s\n", _(" NSS4<stat> = Statistics from _Admin:Manage_NSS\\FileStats.xml"));
1657 printf (" %s\n", _(" NSS5<stat> = Statistics from _Admin:Manage_NSS\\ObjectCache.xml"));
1658 printf (" %s\n", _(" NSS6<stat> = Statistics from _Admin:Manage_NSS\\Thread.xml"));
1659 printf (" %s\n", _(" NSS7<stat> = Statistics from _Admin:Manage_NSS\\AuthorizationCache.xml"));
1660 printf (" %s\n", _(" NLM:<nlm> = check if NLM is loaded and report version"));
1661 printf (" %s\n", _(" (e.g. NLM:TSANDS.NLM)"));
1662 printf ("\n");
1663 printf (" %s\n", "-w, --warning=INTEGER");
1664 printf (" %s\n", _("Threshold which will result in a warning status"));
1665 printf (" %s\n", "-c, --critical=INTEGER");
1666 printf (" %s\n", _("Threshold which will result in a critical status"));
1667 printf (" %s\n", "-o, --osversion");
1668 printf (" %s\n", _("Include server version string in results"));
1670 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
1672 printf ("\n");
1673 printf ("%s\n", _("Notes:"));
1674 printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"));
1675 printf (" %s\n", _(" extension for NetWare be loaded on the Novell servers you wish to check."));
1676 printf (" %s\n", _(" (available from http://www.engr.wisc.edu/~drews/mrtg/)"));
1677 printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds"));
1678 printf (" %s\n", _(" when the following variables are checked: VPF, VKF, LTCH, CBUFF, DCB, "));
1679 printf (" %s\n", _(" TCB, LRUS and LRUM.\n"));
1681 printf (_(UT_SUPPORT));
1686 void print_usage(void)
1688 printf (_("Usage:"));
1689 printf ("%s -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]\n",progname);