Back to index

nagios-plugins  1.4.16
check_nwstat.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * 
00003 * Nagios check_nwstat plugin
00004 * 
00005 * License: GPL
00006 * Copyright (c) 2000-2007 Nagios Plugins Development Team
00007 * 
00008 * Description:
00009 * 
00010 * This file contains the check_nwstat plugin
00011 * 
00012 * This plugin attempts to contact the MRTGEXT NLM running on a
00013 * Novell server to gather the requested system information.
00014 * 
00015 * 
00016 * This program is free software: you can redistribute it and/or modify
00017 * it under the terms of the GNU General Public License as published by
00018 * the Free Software Foundation, either version 3 of the License, or
00019 * (at your option) any later version.
00020 * 
00021 * This program is distributed in the hope that it will be useful,
00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 * GNU General Public License for more details.
00025 * 
00026 * You should have received a copy of the GNU General Public License
00027 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00028 * 
00029 * 
00030 *****************************************************************************/
00031 
00032 const char *progname = "check_nwstat";
00033 const char *copyright = "2000-2007";
00034 const char *email = "nagiosplug-devel@lists.sourceforge.net";
00035 
00036 #include "common.h"
00037 #include "netutils.h"
00038 #include "utils.h"
00039 
00040 enum checkvar {
00041        NONE,
00042        LOAD1,      /* check 1 minute CPU load */
00043        LOAD5,      /* check 5 minute CPU load */
00044        LOAD15,     /* check 15 minute CPU load */
00045        CONNS,      /* check number of connections */
00046        VPF,        /* check % free space on volume */
00047        VMF,       /* check MB free space on volume */
00048        VMU,       /* check MB used space on volume */
00049        VMP,       /* check MB purgeable space on volume */
00050        VKF,        /* check KB free space on volume */
00051        LTCH,       /* check long-term cache hit percentage */
00052        CBUFF,      /* check total cache buffers */
00053        CDBUFF,     /* check dirty cache buffers */
00054        LRUM,       /* check LRU sitting time in minutes */
00055        DSDB,       /* check to see if DS Database is open */
00056        LOGINS,     /* check to see if logins are enabled */
00057        NRMH,      /* check to see NRM Health Status */
00058        PUPRB,      /* check % of used packet receive buffers */
00059        UPRB,       /* check used packet receive buffers */
00060        SAPENTRIES, /* check SAP entries */
00061        OFILES,     /* check number of open files */
00062        VKP,        /* check KB purgeable space on volume */
00063        VPP,        /* check % purgeable space on volume */
00064        VKNP,       /* check KB not yet purgeable space on volume */
00065        VPNP,       /* check % not yet purgeable space on volume */
00066        ABENDS,     /* check abended thread count */
00067        CSPROCS,    /* check number of current service processes */
00068        TSYNC,      /* check timesync status 0=no 1=yes in sync to the network */
00069        LRUS,       /* check LRU sitting time in seconds */
00070        DCB,        /* check dirty cache buffers as a percentage of the total */
00071        TCB,        /* check total cache buffers as a percentage of the original */
00072        DSVER,      /* check NDS version */
00073        UPTIME,     /* check server uptime */
00074        NLM,        /* check NLM loaded */
00075        NRMP,      /* check NRM Process Values */
00076        NRMM,      /* check NRM Memory Values */
00077        NRMS,       /* check NRM Values */
00078        NSS1,       /* check Statistics from _Admin:Manage_NSS\GeneralStats.xml */
00079        NSS2,       /* check Statistics from _Admin:Manage_NSS\BufferCache.xml */
00080        NSS3,       /* check statistics from _Admin:Manage_NSS\NameCache.xml */
00081        NSS4,       /* check statistics from _Admin:Manage_NSS\FileStats.xml */
00082        NSS5,       /* check statistics from _Admin:Manage_NSS\ObjectCache.xml */
00083        NSS6,       /* check statistics from _Admin:Manage_NSS\Thread.xml */
00084        NSS7        /* check statistics from _Admin:Manage_NSS\AuthorizationCache.xml */
00085 };
00086 
00087 enum {
00088        PORT = 9999
00089 };
00090 
00091 char *server_address=NULL;
00092 char *volume_name=NULL;
00093 char *nlm_name=NULL;
00094 char *nrmp_name=NULL;
00095 char *nrmm_name=NULL;
00096 char *nrms_name=NULL;
00097 char *nss1_name=NULL;
00098 char *nss2_name=NULL;
00099 char *nss3_name=NULL;
00100 char *nss4_name=NULL;
00101 char *nss5_name=NULL;
00102 char *nss6_name=NULL;
00103 char *nss7_name=NULL;
00104 int server_port=PORT;
00105 unsigned long warning_value=0L;
00106 unsigned long critical_value=0L;
00107 int check_warning_value=FALSE;
00108 int check_critical_value=FALSE;
00109 int check_netware_version=FALSE;
00110 enum checkvar vars_to_check = NONE;
00111 int sap_number=-1;
00112 
00113 int process_arguments(int, char **);
00114 void print_help(void);
00115 void print_usage(void);
00116 
00117 
00118 
00119 int
00120 main(int argc, char **argv) {
00121        int result = STATE_UNKNOWN;
00122        int sd;
00123        char *send_buffer=NULL;
00124        char recv_buffer[MAX_INPUT_BUFFER];
00125        char *output_message=NULL;
00126        char *temp_buffer=NULL;
00127        char *netware_version=NULL;
00128 
00129        int time_sync_status=0;
00130        int nrm_health_status=0;
00131        unsigned long total_cache_buffers=0;
00132        unsigned long dirty_cache_buffers=0;
00133        unsigned long open_files=0;
00134        unsigned long abended_threads=0;
00135        unsigned long max_service_processes=0;
00136        unsigned long current_service_processes=0;
00137        unsigned long free_disk_space=0L;
00138        unsigned long nrmp_value=0L;
00139        unsigned long nrmm_value=0L;
00140        unsigned long nrms_value=0L;
00141        unsigned long nss1_value=0L;
00142        unsigned long nss2_value=0L;
00143        unsigned long nss3_value=0L;
00144        unsigned long nss4_value=0L;
00145        unsigned long nss5_value=0L;
00146        unsigned long nss6_value=0L;
00147        unsigned long nss7_value=0L;
00148        unsigned long total_disk_space=0L;
00149        unsigned long purgeable_disk_space=0L;
00150        unsigned long non_purgeable_disk_space=0L;
00151        unsigned long percent_free_space=0;
00152        unsigned long percent_purgeable_space=0;
00153        unsigned long percent_non_purgeable_space=0;
00154        unsigned long current_connections=0L;
00155        unsigned long utilization=0L;
00156        unsigned long cache_hits=0;
00157        unsigned long cache_buffers=0L;
00158        unsigned long lru_time=0L;
00159        unsigned long max_packet_receive_buffers=0;
00160        unsigned long used_packet_receive_buffers=0;
00161        unsigned long percent_used_packet_receive_buffers=0L;
00162        unsigned long sap_entries=0;
00163        char uptime[MAX_INPUT_BUFFER];
00164 
00165        setlocale (LC_ALL, "");
00166        bindtextdomain (PACKAGE, LOCALEDIR);
00167        textdomain (PACKAGE);
00168 
00169        /* Parse extra opts if any */
00170        argv=np_extra_opts(&argc, argv, progname);
00171 
00172        if (process_arguments(argc,argv) == ERROR)
00173               usage4 (_("Could not parse arguments"));
00174 
00175        /* initialize alarm signal handling */
00176        signal(SIGALRM,socket_timeout_alarm_handler);
00177 
00178        /* set socket timeout */
00179        alarm(socket_timeout);
00180 
00181        /* open connection */
00182        my_tcp_connect (server_address, server_port, &sd);
00183 
00184        /* get OS version string */
00185        if (check_netware_version==TRUE) {
00186               send_buffer = strdup ("S19\r\n");
00187               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00188               if (result!=STATE_OK)
00189                      return result;
00190               if (!strcmp(recv_buffer,"-1\n"))
00191                      netware_version = strdup("");
00192               else {
00193                      recv_buffer[strlen(recv_buffer)-1]=0;
00194                      asprintf (&netware_version,_("NetWare %s: "),recv_buffer);
00195               }
00196        } else
00197               netware_version = strdup("");
00198 
00199 
00200        /* check CPU load */
00201        if (vars_to_check==LOAD1 || vars_to_check==LOAD5 || vars_to_check==LOAD15) {
00202 
00203               switch(vars_to_check) {
00204               case LOAD1:
00205                      temp_buffer = strdup ("1");
00206                      break;
00207               case LOAD5:
00208                      temp_buffer = strdup ("5");
00209                      break;
00210               default:
00211                      temp_buffer = strdup ("15");
00212                      break;
00213               }
00214 
00215               close(sd);
00216               my_tcp_connect (server_address, server_port, &sd);
00217 
00218               asprintf (&send_buffer,"UTIL%s\r\n",temp_buffer);
00219               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00220               if (result!=STATE_OK)
00221                      return result;
00222               utilization=strtoul(recv_buffer,NULL,10);
00223 
00224               close(sd);
00225               my_tcp_connect (server_address, server_port, &sd);
00226 
00227               send_buffer = strdup ("UPTIME\r\n");
00228               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00229               if (result!=STATE_OK)
00230                      return result;
00231               recv_buffer[strlen(recv_buffer)-1]=0;
00232               sprintf(uptime,_("Up %s,"),recv_buffer);
00233 
00234               if (check_critical_value==TRUE && utilization >= critical_value)
00235                      result=STATE_CRITICAL;
00236               else if (check_warning_value==TRUE && utilization >= warning_value)
00237                      result=STATE_WARNING;
00238 
00239               asprintf (&output_message,
00240                         _("Load %s - %s %s-min load average = %lu%%|load%s=%lu;%lu;%lu;0;100"),
00241                         state_text(result),
00242                         uptime,
00243                         temp_buffer,
00244                         utilization,
00245                        temp_buffer,
00246                        utilization,
00247                        warning_value,
00248                        critical_value);
00249 
00250               /* check number of user connections */
00251        } else if (vars_to_check==CONNS) {
00252 
00253               close(sd);
00254               my_tcp_connect (server_address, server_port, &sd);
00255 
00256               send_buffer = strdup ("CONNECT\r\n");
00257               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00258               if (result!=STATE_OK)
00259                      return result;
00260               current_connections=strtoul(recv_buffer,NULL,10);
00261 
00262               if (check_critical_value==TRUE && current_connections >= critical_value)
00263                      result=STATE_CRITICAL;
00264               else if (check_warning_value==TRUE && current_connections >= warning_value)
00265                      result=STATE_WARNING;
00266 
00267               asprintf (&output_message,
00268                      _("Conns %s - %lu current connections|Conns=%lu;%lu;%lu;;"),
00269                         state_text(result),
00270                         current_connections,
00271                         current_connections,
00272                        warning_value,
00273                        critical_value);
00274 
00275               /* check % long term cache hits */
00276        } else if (vars_to_check==LTCH) {
00277 
00278               close(sd);
00279               my_tcp_connect (server_address, server_port, &sd);
00280 
00281               send_buffer = strdup ("S1\r\n");
00282               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00283               if (result!=STATE_OK)
00284                      return result;
00285               cache_hits=atoi(recv_buffer);
00286 
00287               if (check_critical_value==TRUE && cache_hits <= critical_value)
00288                      result=STATE_CRITICAL;
00289               else if (check_warning_value==TRUE && cache_hits <= warning_value)
00290                      result=STATE_WARNING;
00291 
00292               asprintf (&output_message,
00293                         _("%s: Long term cache hits = %lu%%"),
00294                         state_text(result),
00295                         cache_hits);
00296 
00297               /* check cache buffers */
00298        } else if (vars_to_check==CBUFF) {
00299 
00300               close(sd);
00301               my_tcp_connect (server_address, server_port, &sd);
00302 
00303               send_buffer = strdup ("S2\r\n");
00304               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00305               if (result!=STATE_OK)
00306                      return result;
00307               cache_buffers=strtoul(recv_buffer,NULL,10);
00308 
00309               if (check_critical_value==TRUE && cache_buffers <= critical_value)
00310                      result=STATE_CRITICAL;
00311               else if (check_warning_value==TRUE && cache_buffers <= warning_value)
00312                      result=STATE_WARNING;
00313 
00314               asprintf (&output_message,
00315                         _("%s: Total cache buffers = %lu|Cachebuffers=%lu;%lu;%lu;;"),
00316                         state_text(result),
00317                         cache_buffers,
00318                        cache_buffers,
00319                        warning_value,
00320                        critical_value);
00321 
00322               /* check dirty cache buffers */
00323        } else if (vars_to_check==CDBUFF) {
00324 
00325               close(sd);
00326               my_tcp_connect (server_address, server_port, &sd);
00327 
00328               send_buffer = strdup ("S3\r\n");
00329               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00330               if (result!=STATE_OK)
00331                      return result;
00332               cache_buffers=strtoul(recv_buffer,NULL,10);
00333 
00334               if (check_critical_value==TRUE && cache_buffers >= critical_value)
00335                      result=STATE_CRITICAL;
00336               else if (check_warning_value==TRUE && cache_buffers >= warning_value)
00337                      result=STATE_WARNING;
00338 
00339               asprintf (&output_message,
00340                         _("%s: Dirty cache buffers = %lu|Dirty-Cache-Buffers=%lu;%lu;%lu;;"),
00341                         state_text(result),
00342                         cache_buffers,
00343                        cache_buffers,
00344                        warning_value,
00345                        critical_value);
00346 
00347               /* check LRU sitting time in minutes */
00348        } else if (vars_to_check==LRUM) {
00349 
00350               close(sd);
00351               my_tcp_connect (server_address, server_port, &sd);
00352 
00353               send_buffer = strdup ("S5\r\n");
00354               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00355               if (result!=STATE_OK)
00356                      return result;
00357               lru_time=strtoul(recv_buffer,NULL,10);
00358 
00359               if (check_critical_value==TRUE && lru_time <= critical_value)
00360                      result=STATE_CRITICAL;
00361               else if (check_warning_value==TRUE && lru_time <= warning_value)
00362                      result=STATE_WARNING;
00363 
00364               asprintf (&output_message,
00365                         _("%s: LRU sitting time = %lu minutes"),
00366                         state_text(result),
00367                         lru_time);
00368 
00369 
00370               /* check KB free space on volume */
00371        } else if (vars_to_check==VKF) {
00372 
00373               close(sd);
00374               my_tcp_connect (server_address, server_port, &sd);
00375 
00376               asprintf (&send_buffer,"VKF%s\r\n",volume_name);
00377               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00378               if (result!=STATE_OK)
00379                      return result;
00380 
00381               if (!strcmp(recv_buffer,"-1\n")) {
00382                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00383                      result=STATE_CRITICAL;
00384               }      else {
00385                      free_disk_space=strtoul(recv_buffer,NULL,10);
00386                      if (check_critical_value==TRUE && free_disk_space <= critical_value)
00387                             result=STATE_CRITICAL;
00388                      else if (check_warning_value==TRUE && free_disk_space <= warning_value)
00389                             result=STATE_WARNING;
00390                      asprintf (&output_message,
00391                                _("%s%lu KB free on volume %s|KBFree%s=%lu;%lu;%lu;;"),
00392                               (result==STATE_OK)?"":_("Only "),
00393                               free_disk_space,
00394                               volume_name,
00395                              volume_name,
00396                              free_disk_space,
00397                              warning_value,
00398                              critical_value);
00399               }
00400 
00401               /* check MB free space on volume */
00402        } else if (vars_to_check==VMF) {
00403 
00404               asprintf (&send_buffer,"VMF%s\r\n",volume_name);
00405               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00406               if (result!=STATE_OK)
00407                      return result;
00408 
00409               if (!strcmp(recv_buffer,"-1\n")) {
00410                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00411                      result=STATE_CRITICAL;
00412               }      else {
00413                      free_disk_space=strtoul(recv_buffer,NULL,10);
00414                      if (check_critical_value==TRUE && free_disk_space <= critical_value)
00415                             result=STATE_CRITICAL;
00416                      else if (check_warning_value==TRUE && free_disk_space <= warning_value)
00417                             result=STATE_WARNING;
00418                      asprintf (&output_message,
00419                                _("%s%lu MB free on volume %s|MBFree%s=%lu;%lu;%lu;;"),
00420                               (result==STATE_OK)?"":_("Only "),
00421                               free_disk_space,
00422                               volume_name,
00423                              volume_name,
00424                              free_disk_space,
00425                              warning_value,
00426                              critical_value);
00427               }
00428               /* check MB used space on volume */
00429        } else if (vars_to_check==VMU) {
00430 
00431               asprintf (&send_buffer,"VMU%s\r\n",volume_name);
00432               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00433               if (result!=STATE_OK)
00434                      return result;
00435 
00436               if (!strcmp(recv_buffer,"-1\n")) {
00437                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00438                      result=STATE_CRITICAL;
00439               }      else {
00440                      free_disk_space=strtoul(recv_buffer,NULL,10);
00441                      if (check_critical_value==TRUE && free_disk_space <= critical_value)
00442                             result=STATE_CRITICAL;
00443                      else if (check_warning_value==TRUE && free_disk_space <= warning_value)
00444                             result=STATE_WARNING;
00445                      asprintf (&output_message,
00446                                _("%s%lu MB used on volume %s|MBUsed%s=%lu;%lu;%lu;;"),
00447                               (result==STATE_OK)?"":_("Only "),
00448                               free_disk_space,
00449                               volume_name,
00450                              volume_name,
00451                              free_disk_space,
00452                              warning_value,
00453                              critical_value);
00454               }
00455 
00456 
00457               /* check % free space on volume */
00458        } else if (vars_to_check==VPF) {
00459 
00460               close(sd);
00461               my_tcp_connect (server_address, server_port, &sd);
00462 
00463               asprintf (&send_buffer,"VKF%s\r\n",volume_name);
00464               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00465               if (result!=STATE_OK)
00466                      return result;
00467 
00468               if (!strcmp(recv_buffer,"-1\n")) {
00469 
00470                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00471                      result=STATE_CRITICAL;
00472 
00473               } else {
00474 
00475                      free_disk_space=strtoul(recv_buffer,NULL,10);
00476 
00477                      close(sd);
00478                      my_tcp_connect (server_address, server_port, &sd);
00479 
00480                      asprintf (&send_buffer,"VKS%s\r\n",volume_name);
00481                      result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00482                      if (result!=STATE_OK)
00483                             return result;
00484                      total_disk_space=strtoul(recv_buffer,NULL,10);
00485 
00486                      percent_free_space=(unsigned long)(((double)free_disk_space/(double)total_disk_space)*100.0);
00487 
00488                      if (check_critical_value==TRUE && percent_free_space <= critical_value)
00489                             result=STATE_CRITICAL;
00490                      else if (check_warning_value==TRUE && percent_free_space <= warning_value)
00491                             result=STATE_WARNING;
00492                      free_disk_space/=1024;
00493                      total_disk_space/=1024;
00494                      asprintf (&output_message,_("%lu MB (%lu%%) free on volume %s - total %lu MB|FreeMB%s=%lu;%lu;%lu;0;100"),
00495                             free_disk_space,
00496                             percent_free_space,
00497                             volume_name,
00498                             total_disk_space,
00499                             volume_name,
00500                                 percent_free_space,
00501                                 warning_value,
00502                                 critical_value
00503                                 );
00504               }
00505 
00506               /* check to see if DS Database is open or closed */
00507        } else if (vars_to_check==DSDB) {
00508 
00509               close(sd);
00510               my_tcp_connect (server_address, server_port, &sd);
00511 
00512               send_buffer = strdup ("S11\r\n");
00513               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00514               if (result!=STATE_OK)
00515                      return result;
00516               if (atoi(recv_buffer)==1)
00517                      result=STATE_OK;
00518               else
00519                      result=STATE_WARNING;
00520 
00521               close(sd);
00522               my_tcp_connect (server_address, server_port, &sd);
00523 
00524               send_buffer = strdup ("S13\r\n");
00525               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00526               temp_buffer=strtok(recv_buffer,"\r\n");
00527 
00528               asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer);
00529 
00530               /* check to see if logins are enabled */
00531        } else if (vars_to_check==LOGINS) {
00532 
00533               close(sd);
00534               my_tcp_connect (server_address, server_port, &sd);
00535 
00536               send_buffer = strdup ("S12\r\n");
00537               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00538               if (result!=STATE_OK)
00539                      return result;
00540               if (atoi(recv_buffer)==1)
00541                      result=STATE_OK;
00542               else
00543                      result=STATE_WARNING;
00544 
00545               asprintf (&output_message,_("Logins are %s"),(result==STATE_OK)?_("enabled"):_("disabled"));
00546 
00547 
00548               /* check NRM Health Status Summary*/
00549        } else if (vars_to_check==NRMH) {
00550 
00551               asprintf (&send_buffer,"NRMH\r\n");
00552               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00553               if (result!=STATE_OK)
00554                      return result;
00555 
00556               nrm_health_status=atoi(recv_buffer);
00557 
00558               if (nrm_health_status==2) {
00559                      result=STATE_OK;
00560                      asprintf (&output_message,_("CRITICAL - NRM Status is bad!"));
00561               }
00562               else {
00563                      if (nrm_health_status==1) {
00564                             result=STATE_WARNING;
00565                             asprintf (&output_message,_("Warning - NRM Status is suspect!"));
00566                      }
00567 
00568                      asprintf (&output_message,_("OK - NRM Status is good!"));
00569               }
00570 
00571 
00572 
00573               /* check packet receive buffers */
00574        } else if (vars_to_check==UPRB || vars_to_check==PUPRB) {
00575 
00576               close(sd);
00577               my_tcp_connect (server_address, server_port, &sd);
00578 
00579               asprintf (&send_buffer,"S15\r\n");
00580               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00581               if (result!=STATE_OK)
00582                      return result;
00583 
00584               used_packet_receive_buffers=atoi(recv_buffer);
00585 
00586               close(sd);
00587               my_tcp_connect (server_address, server_port, &sd);
00588 
00589               asprintf (&send_buffer,"S16\r\n");
00590               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00591               if (result!=STATE_OK)
00592                      return result;
00593 
00594               max_packet_receive_buffers=atoi(recv_buffer);
00595 
00596               percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0);
00597 
00598               if (vars_to_check==UPRB) {
00599                      if (check_critical_value==TRUE && used_packet_receive_buffers >= critical_value)
00600                             result=STATE_CRITICAL;
00601                      else if (check_warning_value==TRUE && used_packet_receive_buffers >= warning_value)
00602                             result=STATE_WARNING;
00603               } else {
00604                      if (check_critical_value==TRUE && percent_used_packet_receive_buffers >= critical_value)
00605                             result=STATE_CRITICAL;
00606                      else if (check_warning_value==TRUE && percent_used_packet_receive_buffers >= warning_value)
00607                             result=STATE_WARNING;
00608               }
00609 
00610               asprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
00611 
00612               /* check SAP table entries */
00613        } else if (vars_to_check==SAPENTRIES) {
00614 
00615               close(sd);
00616               my_tcp_connect (server_address, server_port, &sd);
00617 
00618               if (sap_number==-1)
00619                      asprintf (&send_buffer,"S9\r\n");
00620               else
00621                      asprintf (&send_buffer,"S9.%d\r\n",sap_number);
00622               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00623               if (result!=STATE_OK)
00624                      return result;
00625 
00626               sap_entries=atoi(recv_buffer);
00627 
00628               if (check_critical_value==TRUE && sap_entries >= critical_value)
00629                      result=STATE_CRITICAL;
00630               else if (check_warning_value==TRUE && sap_entries >= warning_value)
00631                      result=STATE_WARNING;
00632 
00633               if (sap_number==-1)
00634                      asprintf (&output_message,_("%lu entries in SAP table"),sap_entries);
00635               else
00636                      asprintf (&output_message,_("%lu entries in SAP table for SAP type %d"),sap_entries,sap_number);
00637 
00638               /* check KB purgeable space on volume */
00639        } else if (vars_to_check==VKP) {
00640 
00641               close(sd);
00642               my_tcp_connect (server_address, server_port, &sd);
00643 
00644               asprintf (&send_buffer,"VKP%s\r\n",volume_name);
00645               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00646               if (result!=STATE_OK)
00647                      return result;
00648 
00649               if (!strcmp(recv_buffer,"-1\n")) {
00650                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00651                      result=STATE_CRITICAL;
00652               } else {
00653                      purgeable_disk_space=strtoul(recv_buffer,NULL,10);
00654                      if (check_critical_value==TRUE && purgeable_disk_space >= critical_value)
00655                             result=STATE_CRITICAL;
00656                      else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
00657                             result=STATE_WARNING;
00658                      asprintf (&output_message,_("%s%lu KB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
00659                              (result==STATE_OK)?"":_("Only "),
00660                              purgeable_disk_space,
00661                              volume_name,
00662                              volume_name,
00663                              purgeable_disk_space,
00664                              warning_value,
00665                              critical_value);
00666               }
00667               /* check MB purgeable space on volume */
00668        } else if (vars_to_check==VMP) {
00669 
00670               asprintf (&send_buffer,"VMP%s\r\n",volume_name);
00671               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00672               if (result!=STATE_OK)
00673                      return result;
00674 
00675               if (!strcmp(recv_buffer,"-1\n")) {
00676                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00677                      result=STATE_CRITICAL;
00678               } else {
00679                      purgeable_disk_space=strtoul(recv_buffer,NULL,10);
00680                      if (check_critical_value==TRUE && purgeable_disk_space >= critical_value)
00681                             result=STATE_CRITICAL;
00682                      else if (check_warning_value==TRUE && purgeable_disk_space >= warning_value)
00683                             result=STATE_WARNING;
00684                      asprintf (&output_message,_("%s%lu MB purgeable on volume %s|Purge%s=%lu;%lu;%lu;;"),
00685                              (result==STATE_OK)?"":_("Only "),
00686                              purgeable_disk_space,
00687                              volume_name,
00688                              volume_name,
00689                              purgeable_disk_space,
00690                              warning_value,
00691                              critical_value);
00692               }
00693 
00694               /* check % purgeable space on volume */
00695        } else if (vars_to_check==VPP) {
00696 
00697               close(sd);
00698               my_tcp_connect (server_address, server_port, &sd);
00699 
00700               asprintf (&send_buffer,"VKP%s\r\n",volume_name);
00701               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00702               if (result!=STATE_OK)
00703                      return result;
00704 
00705               if (!strcmp(recv_buffer,"-1\n")) {
00706 
00707                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00708                      result=STATE_CRITICAL;
00709 
00710               } else {
00711 
00712                      purgeable_disk_space=strtoul(recv_buffer,NULL,10);
00713 
00714                      close(sd);
00715                      my_tcp_connect (server_address, server_port, &sd);
00716 
00717                      asprintf (&send_buffer,"VKS%s\r\n",volume_name);
00718                      result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00719                      if (result!=STATE_OK)
00720                             return result;
00721                      total_disk_space=strtoul(recv_buffer,NULL,10);
00722 
00723                      percent_purgeable_space=(unsigned long)(((double)purgeable_disk_space/(double)total_disk_space)*100.0);
00724 
00725                      if (check_critical_value==TRUE && percent_purgeable_space >= critical_value)
00726                             result=STATE_CRITICAL;
00727                      else if (check_warning_value==TRUE && percent_purgeable_space >= warning_value)
00728                             result=STATE_WARNING;
00729                      purgeable_disk_space/=1024;
00730                      asprintf (&output_message,_("%lu MB (%lu%%) purgeable on volume %s|Purgeable%s=%lu;%lu;%lu;0;100"),
00731                                    purgeable_disk_space,
00732                                    percent_purgeable_space,
00733                                    volume_name,
00734                                    volume_name,
00735                                    percent_purgeable_space,
00736                                    warning_value,
00737                                    critical_value
00738                                    );
00739               }
00740 
00741               /* check KB not yet purgeable space on volume */
00742        } else if (vars_to_check==VKNP) {
00743 
00744               close(sd);
00745               my_tcp_connect (server_address, server_port, &sd);
00746 
00747               asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
00748               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00749               if (result!=STATE_OK)
00750                      return result;
00751 
00752               if (!strcmp(recv_buffer,"-1\n")) {
00753                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00754                      result=STATE_CRITICAL;
00755               } else {
00756                      non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
00757                      if (check_critical_value==TRUE && non_purgeable_disk_space >= critical_value)
00758                             result=STATE_CRITICAL;
00759                      else if (check_warning_value==TRUE && non_purgeable_disk_space >= warning_value)
00760                             result=STATE_WARNING;
00761                      asprintf (&output_message,_("%s%lu KB not yet purgeable on volume %s"),(result==STATE_OK)?"":_("Only "),non_purgeable_disk_space,volume_name);
00762               }
00763 
00764               /* check % not yet purgeable space on volume */
00765        } else if (vars_to_check==VPNP) {
00766 
00767               close(sd);
00768               my_tcp_connect (server_address, server_port, &sd);
00769 
00770               asprintf (&send_buffer,"VKNP%s\r\n",volume_name);
00771               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00772               if (result!=STATE_OK)
00773                      return result;
00774 
00775               if (!strcmp(recv_buffer,"-1\n")) {
00776 
00777                      asprintf (&output_message,_("CRITICAL - Volume '%s' does not exist!"),volume_name);
00778                      result=STATE_CRITICAL;
00779 
00780               } else {
00781 
00782                      non_purgeable_disk_space=strtoul(recv_buffer,NULL,10);
00783 
00784                      close(sd);
00785                      my_tcp_connect (server_address, server_port, &sd);
00786 
00787                      asprintf (&send_buffer,"VKS%s\r\n",volume_name);
00788                      result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00789                      if (result!=STATE_OK)
00790                             return result;
00791                      total_disk_space=strtoul(recv_buffer,NULL,10);
00792 
00793                      percent_non_purgeable_space=(unsigned long)(((double)non_purgeable_disk_space/(double)total_disk_space)*100.0);
00794 
00795                      if (check_critical_value==TRUE && percent_non_purgeable_space >= critical_value)
00796                             result=STATE_CRITICAL;
00797                      else if (check_warning_value==TRUE && percent_non_purgeable_space >= warning_value)
00798                             result=STATE_WARNING;
00799                      purgeable_disk_space/=1024;
00800                      asprintf (&output_message,_("%lu MB (%lu%%) not yet purgeable on volume %s"),non_purgeable_disk_space,percent_non_purgeable_space,volume_name);
00801               }
00802 
00803               /* check # of open files */
00804        } else if (vars_to_check==OFILES) {
00805 
00806               close(sd);
00807               my_tcp_connect (server_address, server_port, &sd);
00808 
00809               asprintf (&send_buffer,"S18\r\n");
00810               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00811               if (result!=STATE_OK)
00812                      return result;
00813 
00814               open_files=atoi(recv_buffer);
00815 
00816               if (check_critical_value==TRUE && open_files >= critical_value)
00817                      result=STATE_CRITICAL;
00818               else if (check_warning_value==TRUE && open_files >= warning_value)
00819                      result=STATE_WARNING;
00820 
00821               asprintf (&output_message,_("%lu open files|Openfiles=%lu;%lu;%lu;0,0"),
00822                             open_files,
00823                             open_files,
00824                             warning_value,
00825                             critical_value);
00826 
00827 
00828               /* check # of abended threads (Netware > 5.x only) */
00829        } else if (vars_to_check==ABENDS) {
00830 
00831               close(sd);
00832               my_tcp_connect (server_address, server_port, &sd);
00833 
00834               asprintf (&send_buffer,"S17\r\n");
00835               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00836               if (result!=STATE_OK)
00837                      return result;
00838 
00839               abended_threads=atoi(recv_buffer);
00840 
00841               if (check_critical_value==TRUE && abended_threads >= critical_value)
00842                      result=STATE_CRITICAL;
00843               else if (check_warning_value==TRUE && abended_threads >= warning_value)
00844                      result=STATE_WARNING;
00845 
00846               asprintf (&output_message,_("%lu abended threads|Abends=%lu;%lu;%lu;;"),
00847                             abended_threads,
00848                             abended_threads,
00849                             warning_value,
00850                             critical_value);
00851 
00852               /* check # of current service processes (Netware 5.x only) */
00853        } else if (vars_to_check==CSPROCS) {
00854 
00855               close(sd);
00856               my_tcp_connect (server_address, server_port, &sd);
00857 
00858               asprintf (&send_buffer,"S20\r\n");
00859               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00860               if (result!=STATE_OK)
00861                      return result;
00862 
00863               max_service_processes=atoi(recv_buffer);
00864 
00865               close(sd);
00866               my_tcp_connect (server_address, server_port, &sd);
00867 
00868               asprintf (&send_buffer,"S21\r\n");
00869               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00870               if (result!=STATE_OK)
00871                      return result;
00872 
00873               current_service_processes=atoi(recv_buffer);
00874 
00875               if (check_critical_value==TRUE && current_service_processes >= critical_value)
00876                      result=STATE_CRITICAL;
00877               else if (check_warning_value==TRUE && current_service_processes >= warning_value)
00878                      result=STATE_WARNING;
00879 
00880               asprintf (&output_message,
00881                         _("%lu current service processes (%lu max)|Processes=%lu;%lu;%lu;0;%lu"),
00882                         current_service_processes,
00883                         max_service_processes,
00884                        current_service_processes,
00885                        warning_value,
00886                        critical_value,
00887                        max_service_processes);
00888 
00889               /* check # Timesync Status */
00890        } else if (vars_to_check==TSYNC) {
00891 
00892               close(sd);
00893               my_tcp_connect (server_address, server_port, &sd);
00894 
00895               asprintf (&send_buffer,"S22\r\n");
00896               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00897               if (result!=STATE_OK)
00898                      return result;
00899 
00900               time_sync_status=atoi(recv_buffer);
00901 
00902               if (time_sync_status==0) {
00903                      result=STATE_CRITICAL;
00904                      asprintf (&output_message,_("CRITICAL - Time not in sync with network!"));
00905               }
00906               else {
00907                      asprintf (&output_message,_("OK - Time in sync with network!"));
00908               }
00909 
00910 
00911 
00912 
00913 
00914               /* check LRU sitting time in secondss */
00915        } else if (vars_to_check==LRUS) {
00916 
00917               close(sd);
00918               my_tcp_connect (server_address, server_port, &sd);
00919 
00920               send_buffer = strdup ("S4\r\n");
00921               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00922               if (result!=STATE_OK)
00923                      return result;
00924               lru_time=strtoul(recv_buffer,NULL,10);
00925 
00926               if (check_critical_value==TRUE && lru_time <= critical_value)
00927                      result=STATE_CRITICAL;
00928               else if (check_warning_value==TRUE && lru_time <= warning_value)
00929                      result=STATE_WARNING;
00930               asprintf (&output_message,_("LRU sitting time = %lu seconds"),lru_time);
00931 
00932 
00933               /* check % dirty cacheobuffers as a percentage of the total*/
00934        } else if (vars_to_check==DCB) {
00935 
00936               close(sd);
00937               my_tcp_connect (server_address, server_port, &sd);
00938 
00939               send_buffer = strdup ("S6\r\n");
00940               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00941               if (result!=STATE_OK)
00942                      return result;
00943               dirty_cache_buffers=atoi(recv_buffer);
00944 
00945               if (check_critical_value==TRUE && dirty_cache_buffers <= critical_value)
00946                      result=STATE_CRITICAL;
00947               else if (check_warning_value==TRUE && dirty_cache_buffers <= warning_value)
00948                      result=STATE_WARNING;
00949               asprintf (&output_message,_("Dirty cache buffers = %lu%% of the total|DCB=%lu;%lu;%lu;0;100"),
00950                             dirty_cache_buffers,
00951                             dirty_cache_buffers,
00952                             warning_value,
00953                             critical_value);
00954 
00955               /* check % total cache buffers as a percentage of the original*/
00956        } else if (vars_to_check==TCB) {
00957 
00958               close(sd);
00959               my_tcp_connect (server_address, server_port, &sd);
00960 
00961               send_buffer = strdup ("S7\r\n");
00962               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00963               if (result!=STATE_OK)
00964                      return result;
00965               total_cache_buffers=atoi(recv_buffer);
00966 
00967               if (check_critical_value==TRUE && total_cache_buffers <= critical_value)
00968                      result=STATE_CRITICAL;
00969               else if (check_warning_value==TRUE && total_cache_buffers <= warning_value)
00970                      result=STATE_WARNING;
00971               asprintf (&output_message,_("Total cache buffers = %lu%% of the original|TCB=%lu;%lu;%lu;0;100"),
00972                             total_cache_buffers,
00973                             total_cache_buffers,
00974                             warning_value,
00975                             critical_value);
00976 
00977        } else if (vars_to_check==DSVER) {
00978 
00979               close(sd);
00980               my_tcp_connect (server_address, server_port, &sd);
00981 
00982               asprintf (&send_buffer,"S13\r\n");
00983               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00984               if (result!=STATE_OK)
00985                      return result;
00986 
00987               recv_buffer[strlen(recv_buffer)-1]=0;
00988 
00989               asprintf (&output_message,_("NDS Version %s"),recv_buffer);
00990 
00991        } else if (vars_to_check==UPTIME) {
00992 
00993               close(sd);
00994               my_tcp_connect (server_address, server_port, &sd);
00995 
00996               asprintf (&send_buffer,"UPTIME\r\n");
00997               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
00998               if (result!=STATE_OK)
00999                      return result;
01000 
01001 
01002               recv_buffer[sizeof(recv_buffer)-1]=0;
01003               recv_buffer[strlen(recv_buffer)-1]=0;
01004 
01005               asprintf (&output_message,_("Up %s"),recv_buffer);
01006 
01007        } else if (vars_to_check==NLM) {
01008 
01009               close(sd);
01010               my_tcp_connect (server_address, server_port, &sd);
01011 
01012               asprintf (&send_buffer,"S24:%s\r\n",nlm_name);
01013               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01014               if (result!=STATE_OK)
01015                      return result;
01016 
01017               recv_buffer[strlen(recv_buffer)-1]=0;
01018               if (strcmp(recv_buffer,"-1")) {
01019                      asprintf (&output_message,_("Module %s version %s is loaded"),nlm_name,recv_buffer);
01020               } else {
01021                      result=STATE_CRITICAL;
01022                      asprintf (&output_message,_("Module %s is not loaded"),nlm_name);
01023 
01024                      }
01025        } else if (vars_to_check==NRMP) {
01026 
01027               asprintf (&send_buffer,"NRMP:%s\r\n",nrmp_name);
01028               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01029               if (result!=STATE_OK)
01030                      return result;
01031 
01032               if (!strcmp(recv_buffer,"-1\n")) {
01033                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmp_name);
01034                      result=STATE_CRITICAL;
01035               }      else {
01036                      nrmp_value=strtoul(recv_buffer,NULL,10);
01037                      if (check_critical_value==TRUE && nrmp_value <= critical_value)
01038                             result=STATE_CRITICAL;
01039                      else if (check_warning_value==TRUE && nrmp_value <= warning_value)
01040                             result=STATE_WARNING;
01041                      asprintf (&output_message,
01042                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01043                               nrmp_name,
01044                               nrmp_value,
01045                              nrmp_name,
01046                              nrmp_value,
01047                              warning_value,
01048                              critical_value);
01049               }
01050 
01051        } else if (vars_to_check==NRMM) {
01052 
01053               asprintf (&send_buffer,"NRMM:%s\r\n",nrmm_name);
01054               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01055               if (result!=STATE_OK)
01056                      return result;
01057 
01058               if (!strcmp(recv_buffer,"-1\n")) {
01059                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrmm_name);
01060                      result=STATE_CRITICAL;
01061               }      else {
01062                      nrmm_value=strtoul(recv_buffer,NULL,10);
01063                      if (check_critical_value==TRUE && nrmm_value <= critical_value)
01064                             result=STATE_CRITICAL;
01065                      else if (check_warning_value==TRUE && nrmm_value <= warning_value)
01066                             result=STATE_WARNING;
01067                      asprintf (&output_message,
01068                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01069                               nrmm_name,
01070                               nrmm_value,
01071                              nrmm_name,
01072                              nrmm_value,
01073                              warning_value,
01074                              critical_value);
01075               }
01076 
01077        } else if (vars_to_check==NRMS) {
01078 
01079               asprintf (&send_buffer,"NRMS:%s\r\n",nrms_name);
01080               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01081               if (result!=STATE_OK)
01082                      return result;
01083 
01084               if (!strcmp(recv_buffer,"-1\n")) {
01085                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nrms_name);
01086                      result=STATE_CRITICAL;
01087               }      else {
01088                      nrms_value=strtoul(recv_buffer,NULL,10);
01089                      if (check_critical_value==TRUE && nrms_value >= critical_value)
01090                             result=STATE_CRITICAL;
01091                      else if (check_warning_value==TRUE && nrms_value >= warning_value)
01092                             result=STATE_WARNING;
01093                      asprintf (&output_message,
01094                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01095                               nrms_name,
01096                               nrms_value,
01097                              nrms_name,
01098                              nrms_value,
01099                              warning_value,
01100                              critical_value);
01101               }
01102 
01103        } else if (vars_to_check==NSS1) {
01104 
01105               asprintf (&send_buffer,"NSS1:%s\r\n",nss1_name);
01106               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01107               if (result!=STATE_OK)
01108                      return result;
01109 
01110               if (!strcmp(recv_buffer,"-1\n")) {
01111                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss1_name);
01112                      result=STATE_CRITICAL;
01113               }      else {
01114                      nss1_value=strtoul(recv_buffer,NULL,10);
01115                      if (check_critical_value==TRUE && nss1_value >= critical_value)
01116                             result=STATE_CRITICAL;
01117                      else if (check_warning_value==TRUE && nss1_value >= warning_value)
01118                             result=STATE_WARNING;
01119                      asprintf (&output_message,
01120                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01121                               nss1_name,
01122                               nss1_value,
01123                              nss1_name,
01124                              nss1_value,
01125                              warning_value,
01126                              critical_value);
01127               }
01128 
01129        } else if (vars_to_check==NSS2) {
01130 
01131               asprintf (&send_buffer,"NSS2:%s\r\n",nss2_name);
01132               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01133               if (result!=STATE_OK)
01134                      return result;
01135 
01136               if (!strcmp(recv_buffer,"-1\n")) {
01137                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss2_name);
01138                      result=STATE_CRITICAL;
01139               }      else {
01140                      nss2_value=strtoul(recv_buffer,NULL,10);
01141                      if (check_critical_value==TRUE && nss2_value >= critical_value)
01142                             result=STATE_CRITICAL;
01143                      else if (check_warning_value==TRUE && nss2_value >= warning_value)
01144                             result=STATE_WARNING;
01145                      asprintf (&output_message,
01146                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01147                               nss2_name,
01148                               nss2_value,
01149                              nss2_name,
01150                              nss2_value,
01151                              warning_value,
01152                              critical_value);
01153               }
01154 
01155        } else if (vars_to_check==NSS3) {
01156 
01157               asprintf (&send_buffer,"NSS3:%s\r\n",nss3_name);
01158               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01159               if (result!=STATE_OK)
01160                      return result;
01161 
01162               if (!strcmp(recv_buffer,"-1\n")) {
01163                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss3_name);
01164                      result=STATE_CRITICAL;
01165               }      else {
01166                      nss3_value=strtoul(recv_buffer,NULL,10);
01167                      if (check_critical_value==TRUE && nss3_value >= critical_value)
01168                             result=STATE_CRITICAL;
01169                      else if (check_warning_value==TRUE && nss3_value >= warning_value)
01170                             result=STATE_WARNING;
01171                      asprintf (&output_message,
01172                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01173                               nss3_name,
01174                               nss3_value,
01175                              nss3_name,
01176                              nss3_value,
01177                              warning_value,
01178                              critical_value);
01179               }
01180 
01181        } else if (vars_to_check==NSS4) {
01182 
01183               asprintf (&send_buffer,"NSS4:%s\r\n",nss4_name);
01184               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01185               if (result!=STATE_OK)
01186                      return result;
01187 
01188               if (!strcmp(recv_buffer,"-1\n")) {
01189                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss4_name);
01190                      result=STATE_CRITICAL;
01191               }      else {
01192                      nss4_value=strtoul(recv_buffer,NULL,10);
01193                      if (check_critical_value==TRUE && nss4_value >= critical_value)
01194                             result=STATE_CRITICAL;
01195                      else if (check_warning_value==TRUE && nss4_value >= warning_value)
01196                             result=STATE_WARNING;
01197                      asprintf (&output_message,
01198                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01199                               nss4_name,
01200                               nss4_value,
01201                              nss4_name,
01202                              nss4_value,
01203                              warning_value,
01204                              critical_value);
01205               }
01206 
01207        } else if (vars_to_check==NSS5) {
01208 
01209               asprintf (&send_buffer,"NSS5:%s\r\n",nss5_name);
01210               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01211               if (result!=STATE_OK)
01212                      return result;
01213 
01214               if (!strcmp(recv_buffer,"-1\n")) {
01215                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss5_name);
01216                      result=STATE_CRITICAL;
01217               }      else {
01218                      nss5_value=strtoul(recv_buffer,NULL,10);
01219                      if (check_critical_value==TRUE && nss5_value >= critical_value)
01220                             result=STATE_CRITICAL;
01221                      else if (check_warning_value==TRUE && nss5_value >= warning_value)
01222                             result=STATE_WARNING;
01223                      asprintf (&output_message,
01224                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01225                               nss5_name,
01226                               nss5_value,
01227                              nss5_name,
01228                              nss5_value,
01229                              warning_value,
01230                              critical_value);
01231               }
01232 
01233        } else if (vars_to_check==NSS6) {
01234 
01235               asprintf (&send_buffer,"NSS6:%s\r\n",nss6_name);
01236               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01237               if (result!=STATE_OK)
01238                      return result;
01239 
01240               if (!strcmp(recv_buffer,"-1\n")) {
01241                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss6_name);
01242                      result=STATE_CRITICAL;
01243               }      else {
01244                      nss6_value=strtoul(recv_buffer,NULL,10);
01245                      if (check_critical_value==TRUE && nss6_value >= critical_value)
01246                             result=STATE_CRITICAL;
01247                      else if (check_warning_value==TRUE && nss6_value >= warning_value)
01248                             result=STATE_WARNING;
01249                      asprintf (&output_message,
01250                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01251                               nss6_name,
01252                               nss6_value,
01253                              nss6_name,
01254                              nss6_value,
01255                              warning_value,
01256                              critical_value);
01257               }
01258 
01259        } else if (vars_to_check==NSS7) {
01260 
01261               asprintf (&send_buffer,"NSS7:%s\r\n",nss7_name);
01262               result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
01263               if (result!=STATE_OK)
01264                      return result;
01265 
01266               if (!strcmp(recv_buffer,"-1\n")) {
01267                      asprintf (&output_message,_("CRITICAL - Value '%s' does not exist!"),nss7_name);
01268                      result=STATE_CRITICAL;
01269               }      else {
01270                      nss7_value=strtoul(recv_buffer,NULL,10);
01271                      if (check_critical_value==TRUE && nss7_value >= critical_value)
01272                             result=STATE_CRITICAL;
01273                      else if (check_warning_value==TRUE && nss7_value >= warning_value)
01274                             result=STATE_WARNING;
01275                      asprintf (&output_message,
01276                                _("%s is  %lu|%s=%lu;%lu;%lu;;"),
01277                               nss7_name,
01278                               nss7_value,
01279                              nss7_name,
01280                              nss7_value,
01281                              warning_value,
01282                              critical_value);
01283               }
01284 
01285 
01286 }
01287        else {
01288 
01289               output_message = strdup (_("Nothing to check!\n"));
01290               result=STATE_UNKNOWN;
01291 
01292        }
01293 
01294        close (sd);
01295 
01296        /* reset timeout */
01297        alarm(0);
01298 
01299        printf("%s%s\n",netware_version,output_message);
01300 
01301        return result;
01302 }
01303 
01304 
01305 
01306 /* process command-line arguments */
01307 int process_arguments(int argc, char **argv) {
01308        int c;
01309 
01310        int option = 0;
01311        static struct option longopts[] =
01312               {
01313                      {"port",     required_argument,0,'p'},
01314                      {"timeout",  required_argument,0,'t'},
01315                      {"critical", required_argument,0,'c'},
01316                      {"warning",  required_argument,0,'w'},
01317                      {"variable", required_argument,0,'v'},
01318                      {"hostname", required_argument,0,'H'},
01319                      {"osversion",no_argument,      0,'o'},
01320                      {"version",  no_argument,      0,'V'},
01321                      {"help",     no_argument,      0,'h'},
01322                      {0,0,0,0}
01323               };
01324 
01325        /* no options were supplied */
01326        if (argc<2) return ERROR;
01327 
01328        /* backwards compatibility */
01329        if (! is_option(argv[1])) {
01330               server_address=argv[1];
01331               argv[1]=argv[0];
01332               argv=&argv[1];
01333               argc--;
01334        }
01335 
01336   for (c=1;c<argc;c++) {
01337     if (strcmp("-to",argv[c])==0)
01338       strcpy(argv[c],"-t");
01339     else if (strcmp("-wv",argv[c])==0)
01340       strcpy(argv[c],"-w");
01341     else if (strcmp("-cv",argv[c])==0)
01342       strcpy(argv[c],"-c");
01343        }
01344 
01345        while (1) {
01346               c = getopt_long(argc,argv,"+hoVH:t:c:w:p:v:",longopts,&option);
01347 
01348               if (c==-1||c==EOF||c==1)
01349                      break;
01350 
01351               switch (c)
01352                      {
01353                      case '?': /* print short usage statement if args not parsable */
01354                      usage5 ();
01355                      case 'h': /* help */
01356                             print_help();
01357                             exit(STATE_OK);
01358                      case 'V': /* version */
01359                             print_revision(progname, NP_VERSION);
01360                             exit(STATE_OK);
01361                      case 'H': /* hostname */
01362                             server_address=optarg;
01363                             break;
01364                      case 'o': /* display nos version */
01365                             check_netware_version=TRUE;
01366                             break;
01367                      case 'p': /* port */
01368                             if (is_intnonneg(optarg))
01369                                    server_port=atoi(optarg);
01370                             else
01371                                    die(STATE_UNKNOWN,_("Server port an integer\n"));
01372                             break;
01373                      case 'v':
01374                             if (strlen(optarg)<3)
01375                                    return ERROR;
01376                             if (!strcmp(optarg,"LOAD1"))
01377                                    vars_to_check=LOAD1;
01378                             else if (!strcmp(optarg,"LOAD5"))
01379                                    vars_to_check=LOAD5;
01380                             else if (!strcmp(optarg,"LOAD15"))
01381                                    vars_to_check=LOAD15;
01382                             else if (!strcmp(optarg,"CONNS"))
01383                                    vars_to_check=CONNS;
01384                             else if (!strcmp(optarg,"LTCH"))
01385                                    vars_to_check=LTCH;
01386                             else if (!strcmp(optarg,"DCB"))
01387                                    vars_to_check=DCB;
01388                             else if (!strcmp(optarg,"TCB"))
01389                                    vars_to_check=TCB;
01390                             else if (!strcmp(optarg,"CBUFF"))
01391                                    vars_to_check=CBUFF;
01392                             else if (!strcmp(optarg,"CDBUFF"))
01393                                    vars_to_check=CDBUFF;
01394                             else if (!strcmp(optarg,"LRUM"))
01395                                    vars_to_check=LRUM;
01396                             else if (!strcmp(optarg,"LRUS"))
01397                                    vars_to_check=LRUS;
01398                             else if (strncmp(optarg,"VPF",3)==0) {
01399                                    vars_to_check=VPF;
01400                                    volume_name = strdup (optarg+3);
01401                                    if (!strcmp(volume_name,""))
01402                                           volume_name = strdup ("SYS");
01403                             }
01404                             else if (strncmp(optarg,"VKF",3)==0) {
01405                                    vars_to_check=VKF;
01406                                    volume_name = strdup (optarg+3);
01407                                    if (!strcmp(volume_name,""))
01408                                           volume_name = strdup ("SYS");
01409                             }
01410                             else if (strncmp(optarg,"VMF",3)==0) {
01411                                    vars_to_check=VMF;
01412                                    volume_name = strdup (optarg+3);
01413                                    if (!strcmp(volume_name,""))
01414                                           volume_name = strdup ("SYS");
01415                             }
01416                             else if (!strcmp(optarg,"DSDB"))
01417                                    vars_to_check=DSDB;
01418                             else if (!strcmp(optarg,"LOGINS"))
01419                                    vars_to_check=LOGINS;
01420                             else if (!strcmp(optarg,"NRMH"))
01421                                    vars_to_check=NRMH;
01422                             else if (!strcmp(optarg,"UPRB"))
01423                                    vars_to_check=UPRB;
01424                             else if (!strcmp(optarg,"PUPRB"))
01425                                    vars_to_check=PUPRB;
01426                             else if (!strncmp(optarg,"SAPENTRIES",10)) {
01427                                    vars_to_check=SAPENTRIES;
01428                                    if (strlen(optarg)>10)
01429                                           sap_number=atoi(optarg+10);
01430                                    else
01431                                           sap_number=-1;
01432                             }
01433                             else if (!strcmp(optarg,"OFILES"))
01434                                    vars_to_check=OFILES;
01435                             else if (strncmp(optarg,"VKP",3)==0) {
01436                                    vars_to_check=VKP;
01437                                    volume_name = strdup (optarg+3);
01438                                    if (!strcmp(volume_name,""))
01439                                           volume_name = strdup ("SYS");
01440                             }
01441                             else if (strncmp(optarg,"VMP",3)==0) {
01442                                    vars_to_check=VMP;
01443                                    volume_name = strdup (optarg+3);
01444                                    if (!strcmp(volume_name,""))
01445                                           volume_name = strdup ("SYS");
01446                             }
01447                             else if (strncmp(optarg,"VMU",3)==0) {
01448                                    vars_to_check=VMU;
01449                                    volume_name = strdup (optarg+3);
01450                                    if (!strcmp(volume_name,""))
01451                                           volume_name = strdup ("SYS");
01452                             }
01453                             else if (strncmp(optarg,"VPP",3)==0) {
01454                                    vars_to_check=VPP;
01455                                    volume_name = strdup (optarg+3);
01456                                    if (!strcmp(volume_name,""))
01457                                           volume_name = strdup ("SYS");
01458                             }
01459                             else if (strncmp(optarg,"VKNP",4)==0) {
01460                                    vars_to_check=VKNP;
01461                                    volume_name = strdup (optarg+4);
01462                                    if (!strcmp(volume_name,""))
01463                                           volume_name = strdup ("SYS");
01464                             }
01465                             else if (strncmp(optarg,"VPNP",4)==0) {
01466                                    vars_to_check=VPNP;
01467                                    volume_name = strdup (optarg+4);
01468                                    if (!strcmp(volume_name,""))
01469                                           volume_name = strdup("SYS");
01470                             }
01471                             else if (!strcmp(optarg,"ABENDS"))
01472                                    vars_to_check=ABENDS;
01473                             else if (!strcmp(optarg,"CSPROCS"))
01474                                    vars_to_check=CSPROCS;
01475                             else if (!strcmp(optarg,"TSYNC"))
01476                                    vars_to_check=TSYNC;
01477                             else if (!strcmp(optarg,"DSVER"))
01478                                    vars_to_check=DSVER;
01479                             else if (!strcmp(optarg,"UPTIME")) {
01480                                    vars_to_check=UPTIME;
01481                             }
01482                             else if (strncmp(optarg,"NLM:",4)==0) {
01483                                    vars_to_check=NLM;
01484                                    nlm_name=strdup (optarg+4);
01485                             }
01486                             else if (strncmp(optarg,"NRMP",4)==0) {
01487                                    vars_to_check=NRMP;
01488                                    nrmp_name = strdup (optarg+4);
01489                                    if (!strcmp(nrmp_name,""))
01490                                           nrmp_name = strdup ("AVAILABLE_MEMORY");
01491                             }
01492                             else if (strncmp(optarg,"NRMM",4)==0) {
01493                                    vars_to_check=NRMM;
01494                                    nrmm_name = strdup (optarg+4);
01495                                    if (!strcmp(nrmm_name,""))
01496                                           nrmm_name = strdup ("AVAILABLE_CACHE_MEMORY");
01497 
01498                             }
01499 
01500                             else if (strncmp(optarg,"NRMS",4)==0) {
01501                                    vars_to_check=NRMS;
01502                                    nrms_name = strdup (optarg+4);
01503                                    if (!strcmp(nrms_name,""))
01504                                           nrms_name = strdup ("USED_SWAP_SPACE");
01505 
01506                             }
01507 
01508                             else if (strncmp(optarg,"NSS1",4)==0) {
01509                                    vars_to_check=NSS1;
01510                                    nss1_name = strdup (optarg+4);
01511                                    if (!strcmp(nss1_name,""))
01512                                           nss1_name = strdup ("CURRENTBUFFERCACHESIZE");
01513 
01514                             }
01515 
01516                             else if (strncmp(optarg,"NSS2",4)==0) {
01517                                    vars_to_check=NSS2;
01518                                    nss2_name = strdup (optarg+4);
01519                                    if (!strcmp(nss2_name,""))
01520                                           nss2_name = strdup ("CACHEHITS");
01521 
01522                             }
01523 
01524                             else if (strncmp(optarg,"NSS3",4)==0) {
01525                                    vars_to_check=NSS3;
01526                                    nss3_name = strdup (optarg+4);
01527                                    if (!strcmp(nss3_name,""))
01528                                           nss3_name = strdup ("CACHEGITPERCENT");
01529 
01530                             }
01531 
01532                             else if (strncmp(optarg,"NSS4",4)==0) {
01533                                    vars_to_check=NSS4;
01534                                    nss4_name = strdup (optarg+4);
01535                                    if (!strcmp(nss4_name,""))
01536                                           nss4_name = strdup ("CURRENTOPENCOUNT");
01537 
01538                             }
01539 
01540                             else if (strncmp(optarg,"NSS5",4)==0) {
01541                                    vars_to_check=NSS5;
01542                                    nss5_name = strdup (optarg+4);
01543                                    if (!strcmp(nss5_name,""))
01544                                           nss5_name = strdup ("CACHEMISSES");
01545 
01546                             }
01547 
01548 
01549                             else if (strncmp(optarg,"NSS6",4)==0) {
01550                                    vars_to_check=NSS6;
01551                                    nss6_name = strdup (optarg+4);
01552                                    if (!strcmp(nss6_name,""))
01553                                           nss6_name = strdup ("PENDINGWORKSCOUNT");
01554 
01555                             }
01556 
01557 
01558                             else if (strncmp(optarg,"NSS7",4)==0) {
01559                                    vars_to_check=NSS7;
01560                                    nss7_name = strdup (optarg+4);
01561                                    if (!strcmp(nss7_name,""))
01562                                           nss7_name = strdup ("CACHESIZE");
01563 
01564                             }
01565 
01566 
01567                             else
01568                                    return ERROR;
01569                             break;
01570                      case 'w': /* warning threshold */
01571                             warning_value=strtoul(optarg,NULL,10);
01572                             check_warning_value=TRUE;
01573                             break;
01574                      case 'c': /* critical threshold */
01575                             critical_value=strtoul(optarg,NULL,10);
01576                             check_critical_value=TRUE;
01577                             break;
01578                      case 't': /* timeout */
01579                             socket_timeout=atoi(optarg);
01580                             if (socket_timeout<=0)
01581                                    return ERROR;
01582                      }
01583 
01584        }
01585 
01586        return OK;
01587 }
01588 
01589 
01590 
01591 void print_help(void)
01592 {
01593        char *myport;
01594        asprintf (&myport, "%d", PORT);
01595 
01596        print_revision (progname, NP_VERSION);
01597 
01598        printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
01599        printf (COPYRIGHT, copyright, email);
01600 
01601        printf ("%s\n", _("This plugin attempts to contact the MRTGEXT NLM running on a"));
01602   printf ("%s\n", _("Novell server to gather the requested system information."));
01603 
01604   printf ("\n\n");
01605 
01606        print_usage();
01607 
01608        printf (UT_HELP_VRSN);
01609        printf (UT_EXTRA_OPTS);
01610 
01611        printf (UT_HOST_PORT, 'p', myport);
01612 
01613        printf (" %s\n", "-v, --variable=STRING");
01614   printf ("   %s\n", _("Variable to check.  Valid variables include:"));
01615   printf ("    %s\n", _("LOAD1     = 1 minute average CPU load"));
01616   printf ("    %s\n", _("LOAD5     = 5 minute average CPU load"));
01617   printf ("    %s\n", _("LOAD15    = 15 minute average CPU load"));
01618   printf ("    %s\n", _("CSPROCS   = number of current service processes (NW 5.x only)"));
01619   printf ("    %s\n", _("ABENDS    = number of abended threads (NW 5.x only)"));
01620   printf ("    %s\n", _("UPTIME    = server uptime"));
01621        printf ("    %s\n", _("LTCH      = percent long term cache hits"));
01622   printf ("    %s\n", _("CBUFF     = current number of cache buffers"));
01623   printf ("    %s\n", _("CDBUFF    = current number of dirty cache buffers"));
01624   printf ("    %s\n", _("DCB       = dirty cache buffers as a percentage of the total"));
01625   printf ("    %s\n", _("TCB       = dirty cache buffers as a percentage of the original"));
01626        printf ("    %s\n", _("OFILES    = number of open files"));
01627   printf ("    %s\n", _("    VMF<vol>  = MB of free space on Volume <vol>"));
01628   printf ("    %s\n", _("    VMU<vol>  = MB used space on Volume <vol>"));
01629   printf ("    %s\n", _("    VMP<vol>  = MB of purgeable space on Volume <vol>"));
01630   printf ("    %s\n", _("    VPF<vol>  = percent free space on volume <vol>"));
01631   printf ("    %s\n", _("    VKF<vol>  = KB of free space on volume <vol>"));
01632   printf ("    %s\n", _("    VPP<vol>  = percent purgeable space on volume <vol>"));
01633   printf ("    %s\n", _("    VKP<vol>  = KB of purgeable space on volume <vol>"));
01634   printf ("    %s\n", _("    VPNP<vol> = percent not yet purgeable space on volume <vol>"));
01635   printf ("    %s\n", _("    VKNP<vol> = KB of not yet purgeable space on volume <vol>"));
01636   printf ("    %s\n", _("    LRUM      = LRU sitting time in minutes"));
01637   printf ("    %s\n", _("    LRUS      = LRU sitting time in seconds"));
01638   printf ("    %s\n", _("    DSDB      = check to see if DS Database is open"));
01639   printf ("    %s\n", _("    DSVER     = NDS version"));
01640   printf ("    %s\n", _("    UPRB      = used packet receive buffers"));
01641   printf ("    %s\n", _("    PUPRB     = percent (of max) used packet receive buffers"));
01642   printf ("    %s\n", _("    SAPENTRIES = number of entries in the SAP table"));
01643   printf ("    %s\n", _("    SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>"));
01644   printf ("    %s\n", _("    TSYNC     = timesync status"));
01645   printf ("    %s\n", _("    LOGINS    = check to see if logins are enabled"));
01646   printf ("    %s\n", _("    CONNS     = number of currently licensed connections"));
01647   printf ("    %s\n", _("    NRMH  = NRM Summary Status"));
01648   printf ("    %s\n", _("    NRMP<stat> = Returns the current value for a NRM health item"));
01649   printf ("    %s\n", _("    NRMM<stat> = Returns the current memory stats from NRM"));
01650   printf ("    %s\n", _("    NRMS<stat> = Returns the current Swapfile stats from NRM"));
01651   printf ("    %s\n", _("    NSS1<stat> = Statistics from _Admin:Manage_NSS\\GeneralStats.xml"));
01652   printf ("    %s\n", _("    NSS3<stat> = Statistics from _Admin:Manage_NSS\\NameCache.xml"));
01653   printf ("    %s\n", _("    NSS4<stat> = Statistics from _Admin:Manage_NSS\\FileStats.xml"));
01654   printf ("    %s\n", _("    NSS5<stat> = Statistics from _Admin:Manage_NSS\\ObjectCache.xml"));
01655   printf ("    %s\n", _("    NSS6<stat> = Statistics from _Admin:Manage_NSS\\Thread.xml"));
01656   printf ("    %s\n", _("    NSS7<stat> = Statistics from _Admin:Manage_NSS\\AuthorizationCache.xml"));
01657   printf ("    %s\n", _("    NLM:<nlm> = check if NLM is loaded and report version"));
01658   printf ("    %s\n", _("                (e.g. NLM:TSANDS.NLM)"));
01659   printf ("\n");
01660        printf (" %s\n", "-w, --warning=INTEGER");
01661   printf ("    %s\n", _("Threshold which will result in a warning status"));
01662   printf (" %s\n", "-c, --critical=INTEGER");
01663   printf ("    %s\n", _("Threshold which will result in a critical status"));
01664   printf (" %s\n", "-o, --osversion");
01665   printf ("    %s\n", _("Include server version string in results"));
01666 
01667        printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
01668 
01669   printf ("\n");
01670   printf ("%s\n", _("Notes:"));
01671        printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"));
01672   printf (" %s\n", _("  extension for NetWare be loaded on the Novell servers you wish to check."));
01673   printf (" %s\n", _("  (available from http://www.engr.wisc.edu/~drews/mrtg/)"));
01674   printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds"));
01675   printf (" %s\n", _("  when the following variables are checked: VPF, VKF, LTCH, CBUFF, DCB, "));
01676   printf (" %s\n", _("  TCB, LRUS and LRUM."));
01677 
01678        printf (UT_SUPPORT);
01679 }
01680 
01681 
01682 
01683 void print_usage(void)
01684 {
01685   printf ("%s\n", _("Usage:"));
01686        printf ("%s -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]\n",progname);
01687 }