@cryptotaxi247 / netdata-1 / commits / 6faecab51

Enconde slave fields (#8216)

* stream_encode: Enconde slave This commit encodes the messages before to send them from master to slave * stream_encode: Remove comma This commit changes the comma to semi-colon to bring a pattern to code

thiagoftsm committed Mar 12, 2020 at 14:23 UTC 6faecab5150af3e14802199c2255924a83151fc4
2 files changed +49 -7
libnetdata/url/url.c
+5 -2
@@ -31,8 +31,11 @@ char *url_encode(char *str) {
31 else if (*str == ' ')
32 *pbuf++ = '+';
33
34 - else
35 - *pbuf++ = '%', *pbuf++ = to_hex(*str >> 4), *pbuf++ = to_hex(*str & 15);
34 + else{
35 + *pbuf++ = '%';
36 + *pbuf++ = to_hex(*str >> 4);
37 + *pbuf++ = to_hex(*str & 15);
38 + }
39
40 str++;
41 }
streaming/rrdpush.c
+44 -5
@@ -35,6 +35,14 @@ typedef enum {
35 RRDPUSH_MULTIPLE_CONNECTIONS_DENY_NEW
36 } RRDPUSH_MULTIPLE_CONNECTIONS_STRATEGY;
37
38 +typedef struct {
39 + char *os_name;
40 + char *os_id;
41 + char *os_version;
42 + char *kernel_name;
43 + char *kernel_version;
44 +} stream_encoded_t;
45 +
46 static struct config stream_config = {
47 .sections = NULL,
48 .mutex = NETDATA_MUTEX_INITIALIZER,
@@ -502,6 +510,33 @@ static inline void rrdpush_set_flags_to_newest_stream(RRDHOST *host) {
510 host->labels_flag &= ~LABEL_FLAG_STOP_STREAM;
511 }
512
513 +void rrdpush_encode_variable(stream_encoded_t *se, RRDHOST *host)
514 +{
515 + se->os_name = (host->system_info->host_os_name)?url_encode(host->system_info->host_os_name):"";
516 + se->os_id = (host->system_info->host_os_id)?url_encode(host->system_info->host_os_id):"";
517 + se->os_version = (host->system_info->host_os_version)?url_encode(host->system_info->host_os_version):"";
518 + se->kernel_name = (host->system_info->kernel_name)?url_encode(host->system_info->kernel_name):"";
519 + se->kernel_version = (host->system_info->kernel_version)?url_encode(host->system_info->kernel_version):"";
520 +}
521 +
522 +void rrdpush_clean_encoded(stream_encoded_t *se)
523 +{
524 + if (se->os_name)
525 + freez(se->os_name);
526 +
527 + if (se->os_id)
528 + freez(se->os_id);
529 +
530 + if (se->os_version)
531 + freez(se->os_version);
532 +
533 + if (se->kernel_name)
534 + freez(se->kernel_name);
535 +
536 + if (se->kernel_version)
537 + freez(se->kernel_version);
538 +}
539 +
540 //called from client side
541 static int rrdpush_sender_thread_connect_to_master(RRDHOST *host, int default_port, int timeout, size_t *reconnects_counter, char *connected_to, size_t connected_to_size) {
542 struct timeval tv = {
@@ -563,6 +598,9 @@ static int rrdpush_sender_thread_connect_to_master(RRDHOST *host, int default_po
598 /* TODO: During the implementation of #7265 switch the set of variables to HOST_* and CONTAINER_* if the
599 version negotiation resulted in a high enough version.
600 */
601 + stream_encoded_t se;
602 + rrdpush_encode_variable(&se, host);
603 +
604 #define HTTP_HEADER_SIZE 8192
605 char http[HTTP_HEADER_SIZE + 1];
606 int eol = snprintfz(http, HTTP_HEADER_SIZE,
@@ -603,14 +641,14 @@ static int rrdpush_sender_thread_connect_to_master(RRDHOST *host, int default_po
641 , host->timezone
642 , (host->tags) ? host->tags : ""
643 , STREAMING_PROTOCOL_CURRENT_VERSION
606 - , (host->system_info->host_os_name) ? host->system_info->host_os_name : ""
607 - , (host->system_info->host_os_id) ? host->system_info->host_os_id : ""
644 + , se.os_name
645 + , se.os_id
646 , (host->system_info->host_os_id_like) ? host->system_info->host_os_id_like : ""
609 - , (host->system_info->host_os_version) ? host->system_info->host_os_version : ""
647 + , se.os_version
648 , (host->system_info->host_os_version_id) ? host->system_info->host_os_version_id : ""
649 , (host->system_info->host_os_detection) ? host->system_info->host_os_detection : ""
612 - , (host->system_info->kernel_name) ? host->system_info->kernel_name : ""
613 - , (host->system_info->kernel_version) ? host->system_info->kernel_version : ""
650 + , se.kernel_name
651 + , se.kernel_version
652 , (host->system_info->architecture) ? host->system_info->architecture : ""
653 , (host->system_info->virtualization) ? host->system_info->virtualization : ""
654 , (host->system_info->virt_detection) ? host->system_info->virt_detection : ""
@@ -631,6 +669,7 @@ static int rrdpush_sender_thread_connect_to_master(RRDHOST *host, int default_po
669 , host->program_version
670 );
671 http[eol] = 0x00;
672 + rrdpush_clean_encoded(&se);
673
674 #ifdef ENABLE_HTTPS
675 if (!host->ssl.flags) {