diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2014-01-29 03:20:23 -0500 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2014-01-29 03:20:23 -0500 |
commit | 8fc9e5ac4b3a699f8d6b78471829692f0c92d5fa (patch) | |
tree | 4d630aa158d65602307723e9c7c6d41eca82b94d /lib | |
parent | 55f97c2021bf920b62148ea31fdf56d95572d944 (diff) | |
download | monitoring-plugins-8fc9e5ac4b3a699f8d6b78471829692f0c92d5fa.tar.gz |
Move negate' translate_state() to utils_base.h mp_translate_state()
Also use strcasecmp imported from gnulib for simplicity
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils_base.c | 17 | ||||
-rw-r--r-- | lib/utils_base.h | 13 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c index f5f75067..04c4b4f9 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -369,6 +369,23 @@ 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 mp_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 diff --git a/lib/utils_base.h b/lib/utils_base.h index b4bd92ee..04f6370c 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -79,6 +79,10 @@ 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); +/* mp_suid() returns true if the real and effective uids differs, such as when + * running a suid plugin */ +#define mp_suid() (getuid() != geteuid()) + /* * Extract the value from key/value pairs, or return NULL. The value returned * can be free()ed. @@ -93,6 +97,11 @@ char *np_extract_value(const char*, const char*, char); */ #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') +/* + * Read a string representing a state (ok, warning... or numeric: 0, 1) and + * return the corresponding NP_STATE or ERROR) + */ +int mp_translate_state (char *); void np_enable_state(char *, int); state_data *np_state_read(); @@ -102,8 +111,4 @@ void np_init(char *, int argc, char **argv); void np_set_args(int argc, char **argv); void np_cleanup(); -/* mp_suid() returns true if the real and effective uids differs, such as when - * running a suid plugin */ -#define mp_suid() (getuid() != geteuid()) - #endif /* _UTILS_BASE_ */ |