فهرست منبع

New Functions for timeout state added

abrist 11 سال پیش
والد
کامیت
a85cb3d745
3فایلهای تغییر یافته به همراه44 افزوده شده و 58 حذف شده
  1. 1 2
      plugins/check_nt.c
  2. 24 4
      plugins/netutils.c
  3. 19 52
      plugins/utils.c

+ 1 - 2
plugins/check_nt.c

@@ -615,8 +615,7 @@ int process_arguments(int argc, char **argv){
 				socket_timeout_state=STATE_UNKNOWN;
 				break;
 			case 't': /* timeout */
-				socket_timeout = parse_timeout_string(optarg,"socket");
-				printf("%d",socket_timeout);
+				socket_timeout = parse_socket_timeout_string(optarg);
 				if(socket_timeout<=0)
 					return ERROR;
 				break;

+ 24 - 4
plugins/netutils.c

@@ -53,13 +53,33 @@ socket_timeout_alarm_handler (int sig)
 	exit (socket_timeout_state);
 }
 
-void
-set_socket_timeout_state (char *state)
+int
+parse_socket_timeout_string (char *timeout_str)
 {
-	if ((socket_timeout_state = translate_state(state)) == ERROR)
-		usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); 
+        char *seperated_str;
+        int timeout_value;
+        if ( strstr(timeout_str, ":") == NULL) {
+                return atoi(timeout_str);
+        } else {
+                seperated_str = strtok(timeout_str, ":");
+                timeout_value = atoi(seperated_str);
+                seperated_str = strtok(NULL, ":");
+
+                if (seperated_str != NULL) {
+                        set_socket_timeout_state(seperated_str);
+                }
+
+                if (timeout_value != NULL) {
+                        return timeout_value;
+                }
+        }
 }
 
+void
+set_socket_timeout_state (char *state) {
+        if ((socket_timeout_state = translate_state(state)) == ERROR)
+                usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
+}
 
 /* connects to a host on a specified tcp port, sends a string, and gets a
 	 response. loops on select-recv until timeout or eof to get all of a

+ 19 - 52
plugins/utils.c

@@ -167,54 +167,32 @@ 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.
- *
- */
+void
+timeout_alarm_handler (int signo)
+{
+	if (signo == SIGALRM) {
+		printf (_("%s - Plugin timed out after %d seconds\n"),
+						state_text(timeout_state), timeout_interval);
+		exit (timeout_state);
+	}
+}
 
 int
-parse_timeout_string (char *tmout_str, char *tmout_type) 
+parse_timeout_string (char *timeout_str)
 {
 	char *seperated_str;
 	int timeout_value;
-	if ( strstr(tmout_str, ":") == NULL) {
-		return atoi(tmout_str);
+	if ( strstr(timeout_str, ":") == NULL) {
+		return atoi(timeout_str);
 	} else {
- 		seperated_str = strtok(tmout_str, ":");
-		timeout_value = atoi(seperated_str);	
+		seperated_str = strtok(timeout_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);
-			}
-			
+			set_timeout_state(seperated_str);
 		}
+
 		if (timeout_value != NULL) {
 			return timeout_value;
 		}
@@ -222,19 +200,8 @@ parse_timeout_string (char *tmout_str, char *tmout_type)
 }
 
 void
-timeout_alarm_handler (int signo)
-{
-	if (signo == SIGALRM) {
-		printf (_("%s - Plugin timed out after %d seconds\n"),
-						state_text(timeout_state), timeout_interval);
-		exit (timeout_state);
-	}
-}
-
-void
-set_timeout_state (char *state)
-{
-        if ((timeout_state = translate_state(state)) == ERROR)
+set_timeout_state (char *state) {
+	if ((timeout_state = translate_state(state)) == ERROR)
                 usage4 (_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
 }