Quellcode durchsuchen

Move negate' translate_state() to utils_base.h

Also changed to strcasecmp, may need additions from gnulib. - Thanks dermoth (https://github.com/monitoring-plugins/monitoring-plugins/commit/8fc9e5ac4b3a699f8d6b78471829692f0c92d5fa)
Spenser Reinhardt vor 12 Jahren
Ursprung
Commit
81a5a144e4
3 geänderte Dateien mit 22 neuen und 19 gelöschten Zeilen
  1. 16 0
      lib/utils_base.c
  2. 6 0
      lib/utils_base.h
  3. 0 19
      plugins/negate.c

+ 16 - 0
lib/utils_base.c

@@ -369,6 +369,22 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
 	return value;
 }
 
+/*
+ * Read a string representing a state (ok, warning... or numeric: 0, 1) and
+ * return the corresponding STATE_ value or ERROR)
+ */
+int translate_state (char *state_text) {
+       if (!strcasecmp(state_text,"OK") || !strcmp(state_text,"0"))
+               return STATE_OK;
+       if (!strcasecmp(state_text,"WARNING") || !strcmp(state_text,"1"))
+               return STATE_WARNING;
+       if (!strcasecmp(state_text,"CRITICAL") || !strcmp(state_text,"2"))
+               return STATE_CRITICAL;
+       if (!strcasecmp(state_text,"UNKNOWN") || !strcmp(state_text,"3"))
+               return STATE_UNKNOWN;
+       return ERROR;
+}
+
 /*
  * Returns a string to use as a keyname, based on an md5 hash of argv, thus
  * hopefully a unique key per service/plugin invocation. Use the extra-opts

+ 6 - 0
lib/utils_base.h

@@ -79,6 +79,12 @@ int np_check_if_root(void);
  * code from the above function, in case it's helpful for testing */
 int np_warn_if_not_root(void);
 
+/*
+ * Read a string representing a state (ok, warning... or numeric: 0, 1) and
+ * return the corresponding NP_STATE or ERROR)
+ */
+int translate_state (char *);
+
 /*
  * Extract the value from key/value pairs, or return NULL. The value returned
  * can be free()ed.

+ 0 - 19
plugins/negate.c

@@ -45,7 +45,6 @@ const char *email = "devel@nagios-plugins.org";
 
 static const char **process_arguments (int, char **);
 int validate_arguments (char **);
-int translate_state (char *);
 void print_help (void);
 void print_usage (void);
 int subst_text = FALSE;
@@ -218,24 +217,6 @@ validate_arguments (char **command_line)
 }
 
 
-int
-translate_state (char *state_text)
-{
-	char *temp_ptr;
-	for (temp_ptr = state_text; *temp_ptr; temp_ptr++) {
-		*temp_ptr = toupper(*temp_ptr);
-	}
-	if (!strcmp(state_text,"OK") || !strcmp(state_text,"0"))
-		return STATE_OK;
-	if (!strcmp(state_text,"WARNING") || !strcmp(state_text,"1"))
-		return STATE_WARNING;
-	if (!strcmp(state_text,"CRITICAL") || !strcmp(state_text,"2"))
-		return STATE_CRITICAL;
-	if (!strcmp(state_text,"UNKNOWN") || !strcmp(state_text,"3"))
-		return STATE_UNKNOWN;
-	return ERROR;
-}
-
 void
 print_help (void)
 {