]> arthur.barton.de Git - netdata.git/commitdiff
allow all configuration options to be set from the command line; #1991
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Wed, 22 Mar 2017 23:00:23 +0000 (01:00 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Wed, 22 Mar 2017 23:00:23 +0000 (01:00 +0200)
src/appconfig.c
src/appconfig.h
src/main.c

index 71ff4b75e255a36977685aa049e6d28d43da7691..ae92ad0454a16444aeff44443913e6d79c5a5dfa 100644 (file)
@@ -337,7 +337,7 @@ const char *appconfig_set_default(struct config *root, const char *section, cons
 {
     struct config_option *cv;
 
-    debug(D_CONFIG, "request to set config in section '%s', name '%s', value '%s'", section, name, value);
+    debug(D_CONFIG, "request to set default config in section '%s', name '%s', value '%s'", section, name, value);
 
     struct section *co = appconfig_section_find(root, section);
     if(!co) return appconfig_set(root, section, name, value);
@@ -558,7 +558,7 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
                 if(only_changed && !changed) continue;
 
                 if(!used) {
-                    buffer_sprintf(wb, "\n# node '%s' is not used.", co->name);
+                    buffer_sprintf(wb, "\n# section '%s' is not used.", co->name);
                 }
 
                 buffer_sprintf(wb, "\n[%s]\n", co->name);
index 45cc8cfd5215d18303abbb407091a58998db3379..81db5d9739882749bac7410cf378bfef154bc507 100644 (file)
@@ -56,7 +56,7 @@ extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed
 #define config_get_boolean(section, name, value) appconfig_get_boolean(&netdata_config, section, name, value)
 #define config_get_boolean_ondemand(section, name, value) appconfig_get_boolean_ondemand(&netdata_config, section, name, value)
 
-#define config_set(section, name, default_value) appconfig_get(&netdata_config, section, name, default_value)
+#define config_set(section, name, default_value) appconfig_set(&netdata_config, section, name, default_value)
 #define config_set_default(section, name, value) appconfig_set_default(&netdata_config, section, name, value)
 #define config_set_number(section, name, value) appconfig_set_number(&netdata_config, section, name, value)
 #define config_set_boolean(section, name, value) appconfig_set_boolean(&netdata_config, section, name, value)
index a72585e28377a1157bcae85459bc73176b14d8d3..c661f75999f2802d58b77566374ba4dae430c19b 100644 (file)
@@ -625,6 +625,7 @@ int main(int argc, char **argv) {
                     {
                         char* stacksize_string = "stacksize=";
                         char* debug_flags_string = "debug_flags=";
+
                         if(strcmp(optarg, "unittest") == 0) {
                             default_rrd_update_every = 1;
                             default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
@@ -691,9 +692,36 @@ int main(int argc, char **argv) {
                             config_set(CONFIG_SECTION_GLOBAL, "debug flags",  optarg);
                             debug_flags = strtoull(optarg, NULL, 0);
                         }
+                        else if(strcmp(optarg, "set") == 0) {
+                            if(optind + 3 > argc) {
+                                fprintf(stderr, "%s", "\nUSAGE: -W set 'section' 'key' 'value'\n\n"
+                                        " Overwrites settings of netdata.conf.\n"
+                                        "\n"
+                                );
+                                exit(1);
+                            }
+                            const char *section = argv[optind];
+                            const char *key = argv[optind + 1];
+                            const char *value = argv[optind + 2];
+                            optind += 3;
+
+                            // set this one as the default
+                            // only if it is not already set in the config file
+                            // so the caller can use -c netdata.conf before or
+                            // after this parameter to prevent or allow overwriting
+                            // variables at netdata.conf
+                            config_set_default(section, key,  value);
+
+                            // fprintf(stderr, "SET section '%s', key '%s', value '%s'\n", section, key, value);
+                        }
+                        else {
+                            fprintf(stderr, "Unknown -W parameter '%s'\n", optarg);
+                            help(1);
+                        }
                     }
                     break;
                 default: /* ? */
+                    fprintf(stderr, "Unknown parameter '%c'\n", opt);
                     help(1);
                     break;
             }