Code

Update libtool
[nagiosplug.git] / plugins / check_nwstat.c
index f93dee383376847ca70b406332aa59329764c4b1..81c5575266811f644a06f0fda50dfc738de71362 100644 (file)
@@ -1,26 +1,36 @@
-/******************************************************************************
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
-******************************************************************************/
+/*****************************************************************************
+* 
+* Nagios check_nwstat plugin
+* 
+* License: GPL
+* Copyright (c) 2000-2007 Nagios Plugins Development Team
+* 
+* Description:
+* 
+* This file contains the check_nwstat plugin
+* 
+* This plugin attempts to contact the MRTGEXT NLM running on a
+* Novell server to gather the requested system information.
+* 
+* 
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+* 
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+* 
+* You should have received a copy of the GNU General Public License
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+* 
+* 
+*****************************************************************************/
 
 const char *progname = "check_nwstat";
-const char *revision = "$Revision$";
-const char *copyright = "2000-2006";
+const char *copyright = "2000-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -156,6 +166,9 @@ main(int argc, char **argv) {
        bindtextdomain (PACKAGE, LOCALEDIR);
        textdomain (PACKAGE);
 
+       /* Parse extra opts if any */
+       argv=np_extra_opts(&argc, argv, progname);
+
        if (process_arguments(argc,argv) == ERROR)
                usage4 (_("Could not parse arguments"));
 
@@ -186,7 +199,7 @@ main(int argc, char **argv) {
 
        /* check CPU load */
        if (vars_to_check==LOAD1 || vars_to_check==LOAD5 || vars_to_check==LOAD15) {
-                       
+
                switch(vars_to_check) {
                case LOAD1:
                        temp_buffer = strdup ("1");
@@ -232,7 +245,7 @@ main(int argc, char **argv) {
                          temp_buffer,
                          utilization,
                          warning_value,
-                         critical_value);      
+                         critical_value);
 
                /* check number of user connections */
        } else if (vars_to_check==CONNS) {
@@ -440,7 +453,7 @@ main(int argc, char **argv) {
                                 critical_value);
                }
 
-               
+
                /* check % free space on volume */
        } else if (vars_to_check==VPF) {
 
@@ -504,14 +517,14 @@ main(int argc, char **argv) {
                        result=STATE_OK;
                else
                        result=STATE_WARNING;
+
                close(sd);
                my_tcp_connect (server_address, server_port, &sd);
 
                send_buffer = strdup ("S13\r\n");
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                temp_buffer=strtok(recv_buffer,"\r\n");
+
                asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer);
 
                /* check to see if logins are enabled */
@@ -551,11 +564,11 @@ main(int argc, char **argv) {
                                result=STATE_WARNING;
                                asprintf (&output_message,_("Warning - NRM Status is suspect!"));
                        }
-                       
+
                        asprintf (&output_message,_("OK - NRM Status is good!"));
                }
 
-               
+
 
                /* check packet receive buffers */
        } else if (vars_to_check==UPRB || vars_to_check==PUPRB) {
@@ -579,7 +592,7 @@ main(int argc, char **argv) {
                        return result;
 
                max_packet_receive_buffers=atoi(recv_buffer);
+
                percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0);
 
                if (vars_to_check==UPRB) {
@@ -593,7 +606,7 @@ main(int argc, char **argv) {
                        else if (check_warning_value==TRUE && percent_used_packet_receive_buffers >= warning_value)
                                result=STATE_WARNING;
                }
+
                asprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
 
                /* check SAP table entries */
@@ -609,9 +622,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                sap_entries=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && sap_entries >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && sap_entries >= warning_value)
@@ -797,9 +810,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                open_files=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && open_files >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && open_files >= warning_value)
@@ -810,7 +823,7 @@ main(int argc, char **argv) {
                                open_files,
                                warning_value,
                                critical_value);
-                       
+
 
                /* check # of abended threads (Netware > 5.x only) */
        } else if (vars_to_check==ABENDS) {
@@ -822,9 +835,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                abended_threads=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && abended_threads >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && abended_threads >= warning_value)
@@ -846,9 +859,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                max_service_processes=atoi(recv_buffer);
+
                close(sd);
                my_tcp_connect (server_address, server_port, &sd);
 
@@ -856,9 +869,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                current_service_processes=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && current_service_processes >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && current_service_processes >= warning_value)
@@ -897,7 +910,7 @@ main(int argc, char **argv) {
 
 
 
-               
+
                /* check LRU sitting time in secondss */
        } else if (vars_to_check==LRUS) {
 
@@ -960,7 +973,7 @@ main(int argc, char **argv) {
                                total_cache_buffers,
                                warning_value,
                                critical_value);
-               
+
        } else if (vars_to_check==DSVER) {
 
                close(sd);
@@ -988,7 +1001,7 @@ main(int argc, char **argv) {
 
                recv_buffer[sizeof(recv_buffer)-1]=0;
                recv_buffer[strlen(recv_buffer)-1]=0;
-       
+
                asprintf (&output_message,_("Up %s"),recv_buffer);
 
        } else if (vars_to_check==NLM) {
@@ -1007,7 +1020,7 @@ main(int argc, char **argv) {
                } else {
                        result=STATE_CRITICAL;
                        asprintf (&output_message,_("Module %s is not loaded"),nlm_name);
-               
+
                        }
        } else if (vars_to_check==NRMP) {
 
@@ -1296,7 +1309,7 @@ int process_arguments(int argc, char **argv) {
 
        int option = 0;
        static struct option longopts[] =
-               { 
+               {
                        {"port",     required_argument,0,'p'},
                        {"timeout",  required_argument,0,'t'},
                        {"critical", required_argument,0,'c'},
@@ -1338,12 +1351,12 @@ int process_arguments(int argc, char **argv) {
                switch (c)
                        {
                        case '?': /* print short usage statement if args not parsable */
-                       usage2 (_("Unknown argument"), optarg);
+                       usage5 ();
                        case 'h': /* help */
                                print_help();
                                exit(STATE_OK);
                        case 'V': /* version */
-                               print_revision(progname, revision);
+                               print_revision(progname, NP_VERSION);
                                exit(STATE_OK);
                        case 'H': /* hostname */
                                server_address=optarg;
@@ -1481,7 +1494,7 @@ int process_arguments(int argc, char **argv) {
                                        nrmm_name = strdup (optarg+4);
                                        if (!strcmp(nrmm_name,""))
                                                nrmm_name = strdup ("AVAILABLE_CACHE_MEMORY");
-       
+
                                }
 
                                else if (strncmp(optarg,"NRMS",4)==0) {
@@ -1489,7 +1502,7 @@ int process_arguments(int argc, char **argv) {
                                        nrms_name = strdup (optarg+4);
                                        if (!strcmp(nrms_name,""))
                                                nrms_name = strdup ("USED_SWAP_SPACE");
-       
+
                                }
 
                                else if (strncmp(optarg,"NSS1",4)==0) {
@@ -1497,7 +1510,7 @@ int process_arguments(int argc, char **argv) {
                                        nss1_name = strdup (optarg+4);
                                        if (!strcmp(nss1_name,""))
                                                nss1_name = strdup ("CURRENTBUFFERCACHESIZE");
-       
+
                                }
 
                                else if (strncmp(optarg,"NSS2",4)==0) {
@@ -1505,7 +1518,7 @@ int process_arguments(int argc, char **argv) {
                                        nss2_name = strdup (optarg+4);
                                        if (!strcmp(nss2_name,""))
                                                nss2_name = strdup ("CACHEHITS");
-       
+
                                }
 
                                else if (strncmp(optarg,"NSS3",4)==0) {
@@ -1513,7 +1526,7 @@ int process_arguments(int argc, char **argv) {
                                        nss3_name = strdup (optarg+4);
                                        if (!strcmp(nss3_name,""))
                                                nss3_name = strdup ("CACHEGITPERCENT");
-       
+
                                }
 
                                else if (strncmp(optarg,"NSS4",4)==0) {
@@ -1521,7 +1534,7 @@ int process_arguments(int argc, char **argv) {
                                        nss4_name = strdup (optarg+4);
                                        if (!strcmp(nss4_name,""))
                                                nss4_name = strdup ("CURRENTOPENCOUNT");
-       
+
                                }
 
                                else if (strncmp(optarg,"NSS5",4)==0) {
@@ -1529,7 +1542,7 @@ int process_arguments(int argc, char **argv) {
                                        nss5_name = strdup (optarg+4);
                                        if (!strcmp(nss5_name,""))
                                                nss5_name = strdup ("CACHEMISSES");
-       
+
                                }
 
 
@@ -1538,7 +1551,7 @@ int process_arguments(int argc, char **argv) {
                                        nss6_name = strdup (optarg+4);
                                        if (!strcmp(nss6_name,""))
                                                nss6_name = strdup ("PENDINGWORKSCOUNT");
-       
+
                                }
 
 
@@ -1547,7 +1560,7 @@ int process_arguments(int argc, char **argv) {
                                        nss7_name = strdup (optarg+4);
                                        if (!strcmp(nss7_name,""))
                                                nss7_name = strdup ("CACHESIZE");
-       
+
                                }
 
 
@@ -1580,7 +1593,7 @@ void print_help(void)
        char *myport;
        asprintf (&myport, "%d", PORT);
 
-       print_revision (progname, revision);
+       print_revision (progname, NP_VERSION);
 
        printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
        printf (COPYRIGHT, copyright, email);
@@ -1592,94 +1605,83 @@ void print_help(void)
 
        print_usage();
 
-       printf (_(UT_HELP_VRSN));
-
-       printf (_(UT_HOST_PORT), 'p', myport);
-
-       printf (_("\
- -v, --variable=STRING\n\
-    Variable to check.  Valid variables include:\n\
-      LOAD1     = 1 minute average CPU load\n\
-      LOAD5     = 5 minute average CPU load\n\
-      LOAD15    = 15 minute average CPU load\n\
-      CSPROCS   = number of current service processes (NW 5.x only)\n\
-      ABENDS    = number of abended threads (NW 5.x only)\n\
-      UPTIME    = server uptime\n"));
-
-       printf (_("\
-      LTCH      = percent long term cache hits\n\
-      CBUFF     = current number of cache buffers\n\
-      CDBUFF    = current number of dirty cache buffers\n\
-      DCB       = dirty cache buffers as a percentage of the total\n\
-      TCB       = dirty cache buffers as a percentage of the original\n"));
-
-       printf (_("\
-      OFILES    = number of open files\n\
-      VMF<vol>  = MB of free space on Volume <vol>\n\
-      VMU<vol>  = MB used space on Volume <vol>\n\
-      VMP<vol>  = MB of purgeable space on Volume <vol>\n\
-      VPF<vol>  = percent free space on volume <vol>\n\
-      VKF<vol>  = KB of free space on volume <vol>\n\
-      VPP<vol>  = percent purgeable space on volume <vol>\n\
-      VKP<vol>  = KB of purgeable space on volume <vol>\n\
-      VPNP<vol> = percent not yet purgeable space on volume <vol>\n\
-      VKNP<vol> = KB of not yet purgeable space on volume <vol>\n"));
-
-       printf (_("\
-      LRUM      = LRU sitting time in minutes\n\
-      LRUS      = LRU sitting time in seconds\n\
-      DSDB      = check to see if DS Database is open\n\
-      DSVER     = NDS version\n\
-      UPRB      = used packet receive buffers\n\
-      PUPRB     = percent (of max) used packet receive buffers\n\
-      SAPENTRIES = number of entries in the SAP table\n\
-      SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>\n"));
-
-       printf (_("\
-      TSYNC     = timesync status\n\
-      LOGINS    = check to see if logins are enabled\n\
-      CONNS     = number of currently licensed connections\n\
-      NRMH     = NRM Summary Status\n\
-      NRMP<stat> = Returns the current value for a NRM health item\n\
-      NRMM<stat> = Returns the current memory stats from NRM\n\
-      NRMS<stat> = Returns the current Swapfile stats from NRM\n\
-      NSS1<stat> = Statistics from _Admin:Manage_NSS\\GeneralStats.xml\n\
-      NSS2<stat> = Statistics from _Admin:Manage_NSS\\BufferCache.xml\n\
-      NSS3<stat> = Statistics from _Admin:Manage_NSS\\NameCache.xml\n\
-      NSS4<stat> = Statistics from _Admin:Manage_NSS\\FileStats.xml\n\
-      NSS5<stat> = Statistics from _Admin:Manage_NSS\\ObjectCache.xml\n\
-      NSS6<stat> = Statistics from _Admin:Manage_NSS\\Thread.xml\n\
-      NSS7<stat> = Statistics from _Admin:Manage_NSS\\AuthorizationCache.xml\n\
-      NLM:<nlm> = check if NLM is loaded and report version\n\
-                  (e.g. \"NLM:TSANDS.NLM\")\n"));
-
-       printf (_("\
- -w, --warning=INTEGER\n\
-    Threshold which will result in a warning status\n\
- -c, --critical=INTEGER\n\
-    Threshold which will result in a critical status\n\
- -o, --osversion\n\
-    Include server version string in results\n"));
-
-       printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+       printf (UT_HELP_VRSN);
+       printf (UT_EXTRA_OPTS);
+
+       printf (UT_HOST_PORT, 'p', myport);
+
+       printf (" %s\n", "-v, --variable=STRING");
+  printf ("   %s\n", _("Variable to check.  Valid variables include:"));
+  printf ("    %s\n", _("LOAD1     = 1 minute average CPU load"));
+  printf ("    %s\n", _("LOAD5     = 5 minute average CPU load"));
+  printf ("    %s\n", _("LOAD15    = 15 minute average CPU load"));
+  printf ("    %s\n", _("CSPROCS   = number of current service processes (NW 5.x only)"));
+  printf ("    %s\n", _("ABENDS    = number of abended threads (NW 5.x only)"));
+  printf ("    %s\n", _("UPTIME    = server uptime"));
+       printf ("    %s\n", _("LTCH      = percent long term cache hits"));
+  printf ("    %s\n", _("CBUFF     = current number of cache buffers"));
+  printf ("    %s\n", _("CDBUFF    = current number of dirty cache buffers"));
+  printf ("    %s\n", _("DCB       = dirty cache buffers as a percentage of the total"));
+  printf ("    %s\n", _("TCB       = dirty cache buffers as a percentage of the original"));
+       printf ("    %s\n", _("OFILES    = number of open files"));
+  printf ("    %s\n", _("    VMF<vol>  = MB of free space on Volume <vol>"));
+  printf ("    %s\n", _("    VMU<vol>  = MB used space on Volume <vol>"));
+  printf ("    %s\n", _("    VMP<vol>  = MB of purgeable space on Volume <vol>"));
+  printf ("    %s\n", _("    VPF<vol>  = percent free space on volume <vol>"));
+  printf ("    %s\n", _("    VKF<vol>  = KB of free space on volume <vol>"));
+  printf ("    %s\n", _("    VPP<vol>  = percent purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    VKP<vol>  = KB of purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    VPNP<vol> = percent not yet purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    VKNP<vol> = KB of not yet purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    LRUM      = LRU sitting time in minutes"));
+  printf ("    %s\n", _("    LRUS      = LRU sitting time in seconds"));
+  printf ("    %s\n", _("    DSDB      = check to see if DS Database is open"));
+  printf ("    %s\n", _("    DSVER     = NDS version"));
+  printf ("    %s\n", _("    UPRB      = used packet receive buffers"));
+  printf ("    %s\n", _("    PUPRB     = percent (of max) used packet receive buffers"));
+  printf ("    %s\n", _("    SAPENTRIES = number of entries in the SAP table"));
+  printf ("    %s\n", _("    SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>"));
+  printf ("    %s\n", _("    TSYNC     = timesync status"));
+  printf ("    %s\n", _("    LOGINS    = check to see if logins are enabled"));
+  printf ("    %s\n", _("    CONNS     = number of currently licensed connections"));
+  printf ("    %s\n", _("    NRMH      = NRM Summary Status"));
+  printf ("    %s\n", _("    NRMP<stat> = Returns the current value for a NRM health item"));
+  printf ("    %s\n", _("    NRMM<stat> = Returns the current memory stats from NRM"));
+  printf ("    %s\n", _("    NRMS<stat> = Returns the current Swapfile stats from NRM"));
+  printf ("    %s\n", _("    NSS1<stat> = Statistics from _Admin:Manage_NSS\\GeneralStats.xml"));
+  printf ("    %s\n", _("    NSS3<stat> = Statistics from _Admin:Manage_NSS\\NameCache.xml"));
+  printf ("    %s\n", _("    NSS4<stat> = Statistics from _Admin:Manage_NSS\\FileStats.xml"));
+  printf ("    %s\n", _("    NSS5<stat> = Statistics from _Admin:Manage_NSS\\ObjectCache.xml"));
+  printf ("    %s\n", _("    NSS6<stat> = Statistics from _Admin:Manage_NSS\\Thread.xml"));
+  printf ("    %s\n", _("    NSS7<stat> = Statistics from _Admin:Manage_NSS\\AuthorizationCache.xml"));
+  printf ("    %s\n", _("    NLM:<nlm> = check if NLM is loaded and report version"));
+  printf ("    %s\n", _("                (e.g. NLM:TSANDS.NLM)"));
+  printf ("\n");
+       printf (" %s\n", "-w, --warning=INTEGER");
+  printf ("    %s\n", _("Threshold which will result in a warning status"));
+  printf (" %s\n", "-c, --critical=INTEGER");
+  printf ("    %s\n", _("Threshold which will result in a critical status"));
+  printf (" %s\n", "-o, --osversion");
+  printf ("    %s\n", _("Include server version string in results"));
+
+       printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
 
   printf ("\n");
   printf ("%s\n", _("Notes:"));
-       printf (_("\
-- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG\n\
-  extension for NetWare be loaded on the Novell servers you wish to check.\n\
-  (available from http://www.engr.wisc.edu/~drews/mrtg/)\n\
-- Values for critical thresholds should be lower than warning thresholds\n\
-  when the following variables are checked: VPF, VKF, LTCH, CBUFF, DCB, \n\
-  TCB, LRUS and LRUM.\n"));
-
-       printf (_(UT_SUPPORT));
+       printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"));
+  printf (" %s\n", _("  extension for NetWare be loaded on the Novell servers you wish to check."));
+  printf (" %s\n", _("  (available from http://www.engr.wisc.edu/~drews/mrtg/)"));
+  printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds"));
+  printf (" %s\n", _("  when the following variables are checked: VPF, VKF, LTCH, CBUFF, DCB, "));
+  printf (" %s\n", _("  TCB, LRUS and LRUM."));
+
+       printf (UT_SUPPORT);
 }
 
 
 
 void print_usage(void)
 {
-  printf (_("Usage:"));
+  printf ("%s\n", _("Usage:"));
        printf ("%s -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]\n",progname);
 }