From: Florian Forster Date: Thu, 18 Jun 2020 07:15:50 +0000 (+0200) Subject: common: Simplify notification_init_metric() so it compiles. X-Git-Tag: 6.0.0-rc0~144^2~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=088d15f5470bec6b6d30d9884957e5c3375a1741;p=thirdparty%2Fcollectd.git common: Simplify notification_init_metric() so it compiles. This function is not yet complete; a bunch of TODOs have been left in the code. --- 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,