| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "commands.h" |
| 4 | #include "../stream-sender-internals.h" |
| 5 | #include "plugins.d/pluginsd_internals.h" |
| 6 | |
| 7 | static int send_host_labels_callback(const char *name, const char *value, RRDLABEL_SRC ls, void *data) { |
| 8 | BUFFER *wb = (BUFFER *)data; |
| 9 | buffer_sprintf(wb, PLUGINSD_KEYWORD_LABEL " \"%s\" = %u \"%s\"\n", name, (unsigned)ls, value); |
| 10 | return 1; |
| 11 | } |
| 12 | |
| 13 | void stream_send_host_labels(RRDHOST *host) { |
| 14 | if(unlikely(!rrdhost_can_stream_metadata_to_parent(host) |
| 15 | || !stream_has_capability(host->sender, STREAM_CAP_HLABELS))) |
| 16 | return; |
| 17 | |
| 18 | CLEAN_BUFFER *wb = buffer_create(0, NULL); |
| 19 | |
| 20 | rrdlabels_walkthrough_read(host->rrdlabels, send_host_labels_callback, wb); |
| 21 | buffer_sprintf(wb, PLUGINSD_KEYWORD_OVERWRITE " %s\n", "labels"); |
| 22 | |
| 23 | sender_commit_clean_buffer(host->sender, wb, STREAM_TRAFFIC_TYPE_METADATA); |
| 24 | } |