@cryptotaxi247 / netdata-1 / commits / 0d6e37141

allow all configuration options to be set from the command line; #1991

Costa Tsaousis (ktsaou) committed Mar 23, 2017 at 01:00 UTC 0d6e3714113d50a5f197c9035cf1bd22d2259714
3 files changed +31 -3
src/appconfig.c
+2 -2
@@ -337,7 +337,7 @@ const char *appconfig_set_default(struct config *root, const char *section, cons
337 {
338 struct config_option *cv;
339
340 - debug(D_CONFIG, "request to set config in section '%s', name '%s', value '%s'", section, name, value);
340 + debug(D_CONFIG, "request to set default config in section '%s', name '%s', value '%s'", section, name, value);
341
342 struct section *co = appconfig_section_find(root, section);
343 if(!co) return appconfig_set(root, section, name, value);
@@ -558,7 +558,7 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
558 if(only_changed && !changed) continue;
559
560 if(!used) {
561 - buffer_sprintf(wb, "\n# node '%s' is not used.", co->name);
561 + buffer_sprintf(wb, "\n# section '%s' is not used.", co->name);
562 }
563
564 buffer_sprintf(wb, "\n[%s]\n", co->name);
src/appconfig.h
+1 -1
@@ -56,7 +56,7 @@ extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed
56 #define config_get_boolean(section, name, value) appconfig_get_boolean(&netdata_config, section, name, value)
57 #define config_get_boolean_ondemand(section, name, value) appconfig_get_boolean_ondemand(&netdata_config, section, name, value)
58
59 -#define config_set(section, name, default_value) appconfig_get(&netdata_config, section, name, default_value)
59 +#define config_set(section, name, default_value) appconfig_set(&netdata_config, section, name, default_value)
60 #define config_set_default(section, name, value) appconfig_set_default(&netdata_config, section, name, value)
61 #define config_set_number(section, name, value) appconfig_set_number(&netdata_config, section, name, value)
62 #define config_set_boolean(section, name, value) appconfig_set_boolean(&netdata_config, section, name, value)
src/main.c
+28
@@ -625,6 +625,7 @@ int main(int argc, char **argv) {
625 {
626 char* stacksize_string = "stacksize=";
627 char* debug_flags_string = "debug_flags=";
628 +
629 if(strcmp(optarg, "unittest") == 0) {
630 default_rrd_update_every = 1;
631 default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
@@ -691,9 +692,36 @@ int main(int argc, char **argv) {
692 config_set(CONFIG_SECTION_GLOBAL, "debug flags", optarg);
693 debug_flags = strtoull(optarg, NULL, 0);
694 }
695 + else if(strcmp(optarg, "set") == 0) {
696 + if(optind + 3 > argc) {
697 + fprintf(stderr, "%s", "\nUSAGE: -W set 'section' 'key' 'value'\n\n"
698 + " Overwrites settings of netdata.conf.\n"
699 + "\n"
700 + );
701 + exit(1);
702 + }
703 + const char *section = argv[optind];
704 + const char *key = argv[optind + 1];
705 + const char *value = argv[optind + 2];
706 + optind += 3;
707 +
708 + // set this one as the default
709 + // only if it is not already set in the config file
710 + // so the caller can use -c netdata.conf before or
711 + // after this parameter to prevent or allow overwriting
712 + // variables at netdata.conf
713 + config_set_default(section, key, value);
714 +
715 + // fprintf(stderr, "SET section '%s', key '%s', value '%s'\n", section, key, value);
716 + }
717 + else {
718 + fprintf(stderr, "Unknown -W parameter '%s'\n", optarg);
719 + help(1);
720 + }
721 }
722 break;
723 default: /* ? */
724 + fprintf(stderr, "Unknown parameter '%c'\n", opt);
725 help(1);
726 break;
727 }