Code

Fix minor test issues
[nagiosplug.git] / plugins / check_cluster.c
index 98003f1f64ef0b54fba988e7a1fb26a33939846e..d4e39e0f37db71a84d392743de179c4e697eef90 100644 (file)
@@ -1,43 +1,41 @@
 /*****************************************************************************
- *
- * CHECK_CLUSTER2.C - Host and Service Cluster Plugin for Nagios 2.x
- *
- * Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)
- * Copyright (c) 2007 nagios-plugins team
- * License: GPL
- * Last Modified: $Date$
- *
- * License 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 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$
- * 
-******************************************************************************/
+* 
+* check_cluster.c - Host and Service Cluster Plugin for Nagios 2.x
+* 
+* License: GPL
+* Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)
+* Copyright (c) 2007 Nagios Plugins Development Team
+* 
+* 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_cluster";
-const char *revision = "$Revision$";
 const char *copyright = "2000-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
 #include "utils.h"
+#include "utils_base.h"
 
 #define CHECK_SERVICES 1
 #define CHECK_HOSTS    2
 
+void print_help (void);
+void print_usage (void);
+
 int total_services_ok=0;
 int total_services_warning=0;
 int total_services_unknown=0;
@@ -62,12 +60,17 @@ int process_arguments(int,char **);
 
 
 int main(int argc, char **argv){
-       char input_buffer[MAX_INPUT_BUFFER];
        char *ptr;
        int data_val;
        int return_code=STATE_OK;
-       int error=FALSE;
-       thresholds *thresholds;
+       thresholds *thresholds = NULL;
+
+       setlocale (LC_ALL, "");
+       bindtextdomain (PACKAGE, LOCALEDIR);
+       textdomain (PACKAGE);
+
+       /* Parse extra opts if any */
+       argv=np_extra_opts(&argc, argv, progname);
 
        if(process_arguments(argc,argv)==ERROR)
                usage(_("Could not parse arguments"));
@@ -98,8 +101,8 @@ int main(int argc, char **argv){
                                break;
                        default:
                                break;
-                               }
                        }
+               }
                else{
                        switch(data_val){
                        case 0:
@@ -113,10 +116,10 @@ int main(int argc, char **argv){
                                break;
                        default:
                                break;
-                               }
                        }
                }
-       
+        }
+
 
        /* return the status of the cluster */
        if(check_type==CHECK_SERVICES){
@@ -125,23 +128,23 @@ int main(int argc, char **argv){
                        state_text(return_code), (label==NULL)?"Service cluster":label,
                        total_services_ok,total_services_warning,
                        total_services_unknown,total_services_critical);
-                }
+       }
        else{
                return_code=get_status(total_hosts_down+total_hosts_unreachable, thresholds);
                printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n",
                        state_text(return_code), (label==NULL)?"Host cluster":label,
                        total_hosts_up,total_hosts_down,total_hosts_unreachable);
-                }
+       }
 
        return return_code;
-        }
+}
 
 
 
 int process_arguments(int argc, char **argv){
        int c;
        int option=0;
-       static struct option longopts[]={ 
+       static struct option longopts[]={
                {"data",     required_argument,0,'d'},
                {"warning",  required_argument,0,'w'},
                {"critical", required_argument,0,'c'},
@@ -149,9 +152,10 @@ int process_arguments(int argc, char **argv){
                {"host",     no_argument,      0,'h'},
                {"service",  no_argument,      0,'s'},
                {"verbose",  no_argument,      0,'v'},
+               {"version",  no_argument,      0,'V'},
                {"help",     no_argument,      0,'H'},
                {0,0,0,0}
-               };
+       };
 
        /* no options were supplied */
        if(argc<2)
@@ -159,7 +163,7 @@ int process_arguments(int argc, char **argv){
 
        while(1){
 
-               c=getopt_long(argc,argv,"hHsvw:c:d:l:",longopts,&option);
+               c=getopt_long(argc,argv,"hHsvVw:c:d:l:",longopts,&option);
 
                if(c==-1 || c==EOF || c==1)
                        break;
@@ -175,14 +179,10 @@ int process_arguments(int argc, char **argv){
                        break;
 
                case 'w': /* warning threshold */
-                       if (strspn (optarg, "0123456789:,") < strlen (optarg))
-                               usage2 (_("Invalid warning threshold: %s\n"), optarg);
                        warn_threshold = strdup(optarg);
                        break;
 
                case 'c': /* warning threshold */
-                       if (strspn (optarg, "0123456789:,") < strlen (optarg))
-                               usage2 (_("Invalid critical threshold: %s\n"), optarg);
                        crit_threshold = strdup(optarg);
                        break;
 
@@ -198,6 +198,11 @@ int process_arguments(int argc, char **argv){
                        verbose++;
                        break;
 
+               case 'V': /* version */
+                       print_revision (progname, NP_VERSION);
+                       exit (STATE_OK);
+                       break;
+
                case 'H': /* help */
                        print_help();
                        exit(STATE_UNKNOWN);
@@ -206,8 +211,8 @@ int process_arguments(int argc, char **argv){
                default:
                        return ERROR;
                        break;
-                       }
-               }
+               }
+       }
 
        if(data_vals==NULL)
                return ERROR;
@@ -218,15 +223,18 @@ int process_arguments(int argc, char **argv){
 void
 print_help(void)
 {
-       print_revision(progname, revision);
+       print_revision(progname, NP_VERSION);
+       printf ("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n");
        printf(COPYRIGHT, copyright, email);
 
-       printf("%s\n", _("Host/Service Cluster Plugin for Nagios 2"));
+       printf(_("Host/Service Cluster Plugin for Nagios 2"));
+       printf("\n\n");
 
        print_usage();
 
-
+       printf("\n");
        printf("%s\n", _("Options:"));
+       printf(UT_EXTRA_OPTS);
        printf (" %s\n", "-s, --service");
        printf ("    %s\n", _("Check service cluster status"));
        printf (" %s\n", "-h, --host");
@@ -238,21 +246,24 @@ print_help(void)
        printf ("    %s\n", _("non-OK state in order to return a WARNING status level"));
        printf (" %s\n", "-c, --critical=THRESHOLD");
        printf ("    %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
-       printf ("    %s\n", _(" non-OK state in order to return a CRITICAL status level"));
+       printf ("    %s\n", _("non-OK state in order to return a CRITICAL status level"));
        printf (" %s\n", "-d, --data=LIST");
        printf ("    %s\n", _("The status codes of the hosts or services in the cluster, separated by"));
        printf ("    %s\n", _("commas"));
 
-       printf(_(UT_VERBOSE));
+       printf(UT_VERBOSE);
 
        printf("\n");
        printf("%s\n", _("Notes:"));
-       printf(" %s\n", _("See:"));
-       printf(" %s\n", _("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
-       printf(" %s\n", _("for THRESHOLD format and examples."));
+       printf(UT_THRESHOLDS_NOTES);
 
-       printf(_(UT_SUPPORT));
-       printf("\n");
+       printf ("\n");
+       printf ("%s\n", _("Examples:"));
+       printf (" %s\n", "check_cluster -s -d 2,0,2,0 -c @3:");
+       printf ("    %s\n", _("Will alert critical if there are 3 or more service data points in a non-OK") );
+       printf ("    %s\n", _("state.") );
+
+       printf(UT_SUPPORT);
 }
 
 
@@ -260,14 +271,9 @@ void
 print_usage(void)
 {
 
-       printf("\n");
-       printf(_("Usage:"));
+       printf("%s\n", _("Usage:"));
        printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname);
        printf("[-w threshold] [-c threshold] [-v] [--help]\n");
-       printf("\n");
 
 }
 
-#if 0
-#endif
-