From 095343a8980eda2627455ed94f266e3d59dc527e Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 29 Sep 2010 18:21:13 +0200 Subject: [PATCH] src/utils_threshold.c: Cleanups. --- src/utils_threshold.c | 82 ++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 54 deletions(-) diff --git a/src/utils_threshold.c b/src/utils_threshold.c index 075af020..d831a355 100644 --- a/src/utils_threshold.c +++ b/src/utils_threshold.c @@ -614,31 +614,32 @@ int ut_build_message(char *out, size_t bufsize, const char *fmt, const data_set_t *ds, int ds_index, const value_list_t *vl, const gauge_t *values, const notification_t *n, const threshold_t *th) { - /* TODO: We could provide here a way to use meta information on thresholds * directly in the future. */ char msg[NOTIF_MAX_MSG_LEN]; - char temp[NOTIF_MAX_MSG_LEN]; - gauge_t *rates; int rates_failed; int i; sstrncpy (msg, fmt, sizeof (msg)); -#define REPLACE_FIELD(t,v) \ - if (subst_string (temp, sizeof (temp), msg, t, v) != NULL) \ - sstrncpy (msg, temp, sizeof (msg)); +#define REPLACE_FIELD(t,v) do { \ + char temp[NOTIF_MAX_MSG_LEN]; \ + if (subst_string (temp, sizeof (temp), msg, (t), (v)) != NULL) \ + sstrncpy (msg, temp, sizeof (msg)); \ +} while (0) - char ftoa_temp[NOTIF_MAX_MSG_LEN]; -#define FTOA(string,f) \ - memset(string,0x00,sizeof(string)); \ - snprintf(string, sizeof(string), "%f", f); +#define REPLACE_FIELD_F(t,f) do { \ + char f_str[64]; \ + ssnprintf (f_str, sizeof (f_str), "%g", (f)); \ + REPLACE_FIELD ((t), f_str); \ +} while (0) - char itoa_temp[NOTIF_MAX_MSG_LEN]; -#define ITOA(string,i) \ - memset(string,0x00,sizeof(string)); \ - snprintf(string, sizeof(string), "%i", i); +#define REPLACE_FIELD_I(t,i) do { \ + char i_str[64]; \ + ssnprintf (i_str, sizeof (i_str), "%i", (i)); \ + REPLACE_FIELD ((t), i_str); \ +} while (0) REPLACE_FIELD ("%{host}", n->host); REPLACE_FIELD ("%{plugin}", n->plugin); @@ -654,13 +655,11 @@ int ut_build_message(char *out, size_t bufsize, const char *fmt, /* This is the offending value, its equivalent to %{ds:value}, if * value is the data_source name. */ - FTOA(ftoa_temp,values[ds_index]) - REPLACE_FIELD ("%{value}", ftoa_temp); + REPLACE_FIELD_F ("%{value}", (double) values[ds_index]); } /* Now replace all %{ds: