@cryptotaxi247 / netdata-1 / commits / d481e70f5

logs-management: Add prefix to chart names (#16514)

Dimitris P committed Nov 30, 2023 at 19:15 UTC d481e70f52f1f0922bece45ccabb72692691e4d6
2 files changed +21 -9
logsmanagement/defaults.h
+3
@@ -34,6 +34,9 @@
34
35 #define SD_JOURNAL_SEND_DEFAULT CONFIG_BOOLEAN_NO /**< Default value to enable (or not) submission of logs to the system journal (where applicable) **/
36
37 +#define LOGS_MANAG_CHARTNAME_SIZE 50 /**< Maximum size of log source chart names, including terminating '\0'. **/
38 +#define LOGS_MANAG_CHARTNAME_PREFIX "logs_manag_" /**< Prefix of top-level chart names, used also in function sources. **/
39 +
40 /* -------------------------------------------------------------------------- */
41
42
logsmanagement/logsmanag_config.c
+18 -9
@@ -563,8 +563,17 @@ static void config_section_init(uv_loop_t *main_loop,
563 * Check if config_section->name is valid and if so, use it as chartname.
564 * ------------------------------------------------------------------------- */
565 if(config_section->name && *config_section->name){
566 - p_file_info->chartname = strdupz(config_section->name);
567 - netdata_fix_chart_id((char *) p_file_info->chartname);
566 + char tmp[LOGS_MANAG_CHARTNAME_SIZE] = {0};
567 +
568 + snprintfz(tmp, sizeof(tmp), "%s%s", LOGS_MANAG_CHARTNAME_PREFIX, config_section->name);
569 +
570 + netdata_fix_chart_id(tmp);
571 +
572 + for(char *ch = (char *) tmp; *ch; ch++)
573 + *ch = *ch == '.' ? '_' : *ch; // Convert dots to underscores
574 +
575 + p_file_info->chartname = strdupz(tmp);
576 +
577 collector_info("[%s]: Initializing config loading", p_file_info->chartname);
578 } else {
579 collector_error("Invalid logs management config section.");
@@ -650,21 +659,21 @@ static void config_section_init(uv_loop_t *main_loop,
659
660 switch(p_file_info->log_type){
661 case FLB_TAIL:
653 - if(!strcasecmp(p_file_info->chartname, "Netdata_daemon.log")){
662 + if(!strcasecmp(p_file_info->chartname, LOGS_MANAG_CHARTNAME_PREFIX "netdata_daemon_log")){
663 char path[FILENAME_MAX + 1];
664 snprintfz(path, FILENAME_MAX, "%s/daemon.log", get_log_dir());
665 if(access(path, R_OK)) {
657 - collector_error("[%s]: 'Netdata_daemon.log' path (%s) invalid, unknown or needs permissions",
666 + collector_error("[%s]: 'Netdata daemon.log' path (%s) invalid, unknown or needs permissions",
667 p_file_info->chartname, path);
668 return p_file_info_destroy(p_file_info);
669 } else p_file_info->filename = strdupz(path);
661 - } else if(!strcasecmp(p_file_info->chartname, "Netdata_fluentbit.log")){
670 + } else if(!strcasecmp(p_file_info->chartname, LOGS_MANAG_CHARTNAME_PREFIX "fluentbit_log")){
671 if(access(p_flb_srvc_config->log_path, R_OK)){
663 - collector_error("[%s]: Netdata_fluentbit.log path (%s) invalid, unknown or needs permissions",
672 + collector_error("[%s]: Netdata fluentbit.log path (%s) invalid, unknown or needs permissions",
673 p_file_info->chartname, p_flb_srvc_config->log_path);
674 return p_file_info_destroy(p_file_info);
675 } else p_file_info->filename = strdupz(p_flb_srvc_config->log_path);
667 - } else if(!strcasecmp(p_file_info->chartname, "Auth.log_tail")){
676 + } else if(!strcasecmp(p_file_info->chartname, LOGS_MANAG_CHARTNAME_PREFIX "auth_log_tail")){
677 const char * const auth_path_default[] = {
678 "/var/log/auth.log",
679 NULL
@@ -690,7 +699,7 @@ static void config_section_init(uv_loop_t *main_loop,
699 }
700 break;
701 case FLB_WEB_LOG:
693 - if(!strcasecmp(p_file_info->chartname, "Apache_access.log")){
702 + if(!strcasecmp(p_file_info->chartname, LOGS_MANAG_CHARTNAME_PREFIX "apache_access_log")){
703 const char * const apache_access_path_default[] = {
704 "/var/log/apache/access.log",
705 "/var/log/apache2/access.log",
@@ -705,7 +714,7 @@ static void config_section_init(uv_loop_t *main_loop,
714 collector_error("[%s]: Apache access.log path invalid, unknown or needs permissions", p_file_info->chartname);
715 return p_file_info_destroy(p_file_info);
716 } else p_file_info->filename = strdupz(apache_access_path_default[i]);
708 - } else if(!strcasecmp(p_file_info->chartname, "Nginx_access.log")){
717 + } else if(!strcasecmp(p_file_info->chartname, LOGS_MANAG_CHARTNAME_PREFIX "nginx_access_log")){
718 const char * const nginx_access_path_default[] = {
719 "/var/log/nginx/access.log",
720 NULL