Code

check_host: Allocate a large-enough buffer for the host table.
[nagiosplug.git] / plugins / check_nt.c
index 48bdcccdac9bb0a221226df4ce5ec41eb1908e60..60806bb399fb1f6df5be62faf7d0b4c3e2574a85 100644 (file)
@@ -203,7 +203,12 @@ int main(int argc, char **argv){
                uphours = (uptime % 86400) / 3600;
                upminutes = ((uptime % 86400) % 3600) / 60;
                asprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes);
-               return_code=STATE_OK;
+               if (check_critical_value==TRUE && uptime <= critical_value)
+                       return_code=STATE_CRITICAL;
+               else if (check_warning_value==TRUE && uptime <= warning_value)
+                       return_code=STATE_WARNING;
+               else
+                       return_code=STATE_OK;
                break;
 
        case CHECK_USEDDISKSPACE:
@@ -480,6 +485,7 @@ int process_arguments(int argc, char **argv){
                {"params",   required_argument,0,'l'},
                {"secret",   required_argument,0,'s'},
                {"display",  required_argument,0,'d'},
+               {"unknown-timeout", no_argument, 0, 'u'},
                {"version",  no_argument,      0,'V'},
                {"help",     no_argument,      0,'h'},
                {0,0,0,0}
@@ -506,7 +512,7 @@ int process_arguments(int argc, char **argv){
        }
 
        while (1) {
-               c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",longopts,&option);
+               c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:u",longopts,&option);
 
                if (c==-1||c==EOF||c==1)
                        break;
@@ -521,7 +527,6 @@ int process_arguments(int argc, char **argv){
                                print_revision(progname, NP_VERSION);
                                exit(STATE_OK);
                        case 'H': /* hostname */
-                               if (server_address)     free(server_address);
                                server_address = optarg;
                                break;
                        case 's': /* password */
@@ -574,6 +579,9 @@ int process_arguments(int argc, char **argv){
                                if (!strcmp(optarg,"SHOWALL"))
                                        show_all = TRUE;
                                break;
+                       case 'u':
+                               socket_timeout_state=STATE_UNKNOWN;
+                               break;
                        case 't': /* timeout */
                                socket_timeout=atoi(optarg);
                                if(socket_timeout<=0)
@@ -581,6 +589,8 @@ int process_arguments(int argc, char **argv){
                        }
 
        }
+       if (server_address == NULL)
+               usage4 (_("You must provide a server address or host name"));
 
        if (vars_to_check==CHECK_NONE)
                return ERROR;
@@ -650,8 +660,8 @@ void print_help(void)
 
        print_usage();
 
-       printf (_(UT_HELP_VRSN));
-       printf (_(UT_EXTRA_OPTS));
+       printf (UT_HELP_VRSN);
+       printf (UT_EXTRA_OPTS);
 
        printf ("%s\n", _("Options:"));
        printf (" %s\n", "-H, --hostname=HOST");
@@ -671,6 +681,8 @@ void print_help(void)
        printf ("   %s", _("Parameters passed to specified check (see below)"));
        printf (" %s\n", "-d, --display={SHOWALL}");
        printf ("   %s", _("Display options (currently only SHOWALL works)"));
+       printf (" %s\n", "-u, --unknown-timeout");
+       printf ("   %s", _("Return UNKNOWN on timeouts"));
        printf ("%d)\n", DEFAULT_SOCKET_TIMEOUT);
        printf (" %s\n", "-h, --help");
        printf ("   %s\n", _("Print this help screen"));
@@ -741,19 +753,16 @@ void print_help(void)
        printf ("   %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
        printf ("   %s\n", _("One fix for this is to change the port to something else on check_nt "));
        printf ("   %s\n", _("and on the client service it\'s connecting to."));
-#ifdef NP_EXTRA_OPTS
-       printf (" -%s", _(UT_EXTRA_OPTS_NOTES));
-#endif
 
-       printf (_(UT_SUPPORT));
+       printf (UT_SUPPORT);
 }
 
 
 
 void print_usage(void)
 {
-       printf (_("Usage:"));
+       printf ("%s\n", _("Usage:"));
        printf ("%s -H host -v variable [-p port] [-w warning] [-c critical]\n",progname);
-       printf ("[-l params] [-d SHOWALL] [-t timeout]\n");
+       printf ("[-l params] [-d SHOWALL] [-u] [-t timeout]\n");
 }