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);
/* 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:<template>} like target_notification does */
rates_failed = 0;
- rates = NULL;
for (i = 0; i < ds->ds_num; i++)
{
char template[DATA_MAX_NAME_LEN];
ssnprintf (template, sizeof (template), "%%{ds:%s}", ds->ds[i].name);
- if (ds->ds[i].type != DS_TYPE_GAUGE)
- {
- if ((rates == NULL) && (rates_failed == 0))
- {
- rates = uc_get_rate (ds, vl);
- if (rates == NULL)
- rates_failed = 1;
- }
- }
-
/* If this is a gauge value, use the current value. */
if (ds->ds[i].type == DS_TYPE_GAUGE)
ssnprintf (value_str, sizeof (value_str),
"%g", (double) vl->values[i].gauge);
/* If it's a counter, try to use the current rate. This may fail, if the
* value has been renamed. */
- else if (rates != NULL)
+ else if (values != NULL)
ssnprintf (value_str, sizeof (value_str),
- "%g", (double) rates[i]);
+ "%g", (double) values[i]);
/* Since we don't know any better, use the string `unknown'. */
else
sstrncpy (value_str, "unknown", sizeof (value_str));
REPLACE_FIELD (template, value_str);
}
- sfree (rates);
-
- if (th != NULL) {
- if ( !isnan(th->warning_min)) {
- FTOA(ftoa_temp,th->warning_min)
- REPLACE_FIELD ("%{warning_min}", ftoa_temp);
- }
- if ( !isnan(th->warning_max)) {
- FTOA(ftoa_temp,th->warning_max)
- REPLACE_FIELD ("%{warning_max}", ftoa_temp);
- }
- if ( !isnan(th->failure_min)) {
- FTOA(ftoa_temp,th->failure_min)
- REPLACE_FIELD ("%{failure_min}", ftoa_temp);
- }
- if ( !isnan(th->failure_max)) {
- FTOA(ftoa_temp,th->failure_max)
- REPLACE_FIELD ("%{failure_max}", ftoa_temp);
- }
- FTOA(ftoa_temp,th->hysteresis)
- REPLACE_FIELD ("%{hysteresis}", ftoa_temp);
-
- ITOA(itoa_temp,th->hits)
- REPLACE_FIELD ("%{hits}", itoa_temp);
+ if (th != NULL)
+ {
+ REPLACE_FIELD_F ("%{warning_min}", th->warning_min);
+ REPLACE_FIELD_F ("%{warning_max}", th->warning_max);
+ REPLACE_FIELD_F ("%{failure_min}", th->failure_min);
+ REPLACE_FIELD_F ("%{failure_max}", th->failure_max);
+ REPLACE_FIELD_F ("%{hysteresis}", th->hysteresis);
+ REPLACE_FIELD_I ("%{hits}", th->hits);
}
- return ssnprintf (out, bufsize, "%s", msg);
+ sstrncpy (out, msg, bufsize);
+ return (0);
} /* int ut_build_message */
/*