From 006597a12d28d9cd752b3eeb56dff3bc97049f4c Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Wed, 22 Apr 2009 00:28:53 +0200 Subject: Make C plugin output format configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The development guidelines¹ currently state that the plugin output should be in the format "SERVICE STATUS: Information text". However, the SERVICE and STATUS information is redundant, as the plugin caller (e.g., Nagios) should know which SERVICE is checked and the STATUS is returned via the plugin's exit code. After discussing² this issue on the development list, we decided to make the plugin output configurable at compile time (separately for "normal" and "verbose" output). ¹ http://nagiosplug.sf.net/developer-guidelines.html ² http://thread.gmane.org/gmane.network.nagios.plugins.devel/5155 Signed-off-by: Holger Weiss --- lib/utils_base.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/utils_base.h') diff --git a/lib/utils_base.h b/lib/utils_base.h index f40fdb0f..8d0b2124 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -37,6 +37,23 @@ int get_status(double, thresholds *); char *np_escaped_string (const char *); +void np_set_output(const char *, const char *, int, int); +int np_adjust_verbosity(int); +void np_debug(int, const char *, ...) + __attribute__((format(printf, 2, 3))); +void np_verbose(const char *, ...) + __attribute__((format(printf, 1, 2))); +void np_die(int, const char *, ...) + __attribute__((noreturn, format(printf, 2, 3))); + +#define np_verbatim(s) np_verbose("%s", s) +#define np_increase_verbosity(i) np_adjust_verbosity(i) +#define np_decrease_verbosity(i) np_adjust_verbosity(-i) +#define np_get_verbosity() np_adjust_verbosity(0) +#define np_set_verbosity(v) np_set_output(NULL, NULL, v, 0) +#define np_set_mynames(p, s) np_set_output(p, s, -2, 0) + +/* TODO: die() can be removed as soon as all plugins use np_die() instead. */ void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); /* Return codes for _set_thresholds */ @@ -64,4 +81,7 @@ char *np_extract_value(const char*, const char*, char); */ #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') +/* Given a numerical status, return a pointer to the according string. */ +const char *state_text(int); + #endif /* _UTILS_BASE_ */ -- cgit v1.2.3-74-g34f1