abrist hace 11 años
padre
commit
9d0ca0e3a5
Se han modificado 2 ficheros con 57 adiciones y 4 borrados
  1. 3 4
      plugins/check_nt.c
  2. 54 0
      plugins/utils.c

+ 3 - 4
plugins/check_nt.c

@@ -544,7 +544,7 @@ int process_arguments(int argc, char **argv){
 	}
 
 	while (1) {
-		c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:uZ:",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;
@@ -615,11 +615,10 @@ int process_arguments(int argc, char **argv){
 				socket_timeout_state=STATE_UNKNOWN;
 				break;
 			case 't': /* timeout */
-				socket_timeout=atoi(optarg);
+				socket_timeout = parse_timeout_string(optarg,"socket");
+				printf("%d",socket_timeout);
 				if(socket_timeout<=0)
 					return ERROR;
-			case 'Z':
-				set_socket_timeout_state(optarg);
 				break;
 			}
 

+ 54 - 0
plugins/utils.c

@@ -167,6 +167,60 @@ state_text (int result)
 	}
 }
 
+/* New timeout sytax:
+ * -t <timeout>:<state>
+ * Will exit with <state> when timeout occurs
+ * parse_timeout_string(<optarg>, <timeout type>)
+ * Supported timeout types:
+ *
+ * plugin: Plugin timeout (utils.c)
+ * socket: Socket timeout (netutils.c)
+ * runcmd: Command timeout (runcmd.c)
+ *
+ * Make sure that the timeout type matches the ALARM
+ * and the include.
+ *
+ */
+
+int
+parse_timeout_string (char *tmout_str, char *tmout_type) 
+{
+	char *seperated_str;
+	int timeout_value;
+	if ( strstr(tmout_str, ":") == NULL) {
+		return atoi(tmout_str);
+	} else {
+ 		seperated_str = strtok(tmout_str, ":");
+		timeout_value = atoi(seperated_str);	
+		seperated_str = strtok(NULL, ":");
+		
+		printf("%s",tmout_type);
+		int test = strncmp(tmout_type,"socket",7);
+		printf("%d",test);
+		if (seperated_str != NULL) {
+			if (strncmp(tmout_type,"plugin",7) == 0)
+				set_timeout_state(seperated_str);
+#ifdef _NETUTILS_H_ 
+			else if (strncmp(tmout_type,"socket",7) == 0) {
+				set_socket_timeout_state(seperated_str);
+			}
+#endif
+#ifdef NAGIOSPLUG_RUNCMD_H 
+			else if (strncmp(tmout_type,"runcmd",6) == 0)
+				set_runcmd_timeout_state(seperated_str);
+#endif
+			else {
+				printf("Error: parse_timeout_string(<optarg>,<timeout_type>) expects plugin,socket, or runcmd for <timeout_type>");
+				exit (3);
+			}
+			
+		}
+		if (timeout_value != NULL) {
+			return timeout_value;
+		}
+	}
+}
+
 void
 timeout_alarm_handler (int signo)
 {