From 088d15f5470bec6b6d30d9884957e5c3375a1741 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 18 Jun 2020 09:15:50 +0200 Subject: [PATCH] common: Simplify notification_init_metric() so it compiles. This function is not yet complete; a bunch of TODOs have been left in the code. --- src/utils/common/common.c | 50 +++++++++++---------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/src/utils/common/common.c b/src/utils/common/common.c index f47715835..802d57cf0 100644 --- a/src/utils/common/common.c +++ b/src/utils/common/common.c @@ -1236,45 +1236,23 @@ int notification_init(notification_t *n, int severity, const char *message, } /* int notification_init */ int notification_init_metric(notification_t *n, int severity, - const char *message, const metric_t *metric_p) { - int status = -1; - if ((metric_p == NULL) || (metric_p->identity == NULL) || - (metric_p->identity->name == NULL) || (metric_p->ds == NULL)) { - return status; - } - char *name_p = strdup(metric_p->identity->name); - if (name_p == NULL) { - return status; + char const *message, metric_t const *m) { + if ((n == NULL) || (message == NULL) || (m == NULL)) { + return EINVAL; } - char *save_p = NULL; - char *plugin_p = strtok_r(name_p, "/", &save_p); - char *host_p = NULL; - char *plugin_instance = NULL; - char *type_instance = NULL; - char *key_p = NULL; - status = identity_get_label(metric_p->identity, "_host", &key_p, &host_p); - if (status) { - sfree(name_p); - return status; - } - status = identity_get_label(metric_p->identity, "plugin_instance", &key_p, - &plugin_instance); - if (status) { - sfree(name_p); - return status; - } - status = identity_get_label(metric_p->identity, "type_instance", &key_p, - &type_instance); - if (status) { - sfree(name_p); - return status; - } + (*n) = (notification_t){ + /* TODO(octo): add "identity" to the notification_t type. */ + /* .identity = identity_clone(m->identity), */ + .severity = severity, + .time = m->time, + /* TODO(octo): change the type of the "meta" field to "meta_data_t". */ + /* .meta = meta_data_clone(m->meta), */ + }; - status = notification_init(n, severity, message, host_p, plugin_p, - plugin_instance, metric_p->type, type_instance); - sfree(name_p); - return status; + sstrncpy(n->message, message, sizeof(n->message)); + + return 0; } int walk_directory(const char *dir, dirwalk_callback_f callback, -- 2.47.2