static int config_add (oconfig_item_t *ci) { apache_t *st; int i; int status; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("apache plugin: The `%s' config option " "needs exactly one string argument.", ci->key); return (-1); } st = (apache_t *) malloc (sizeof (*st)); if (st == NULL) { ERROR ("apache plugin: malloc failed."); return (-1); } memset (st, 0, sizeof (*st)); status = config_set_string (&st->name, ci); if (status != 0) { sfree (st); return (status); } assert (st->name != NULL); for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("URL", child->key) == 0) status = config_set_string (&st->url, child); else if (strcasecmp ("Host", child->key) == 0) status = config_set_string (&st->host, child); else if (strcasecmp ("User", child->key) == 0) status = config_set_string (&st->user, child); else if (strcasecmp ("Password", child->key) == 0) status = config_set_string (&st->pass, child); else if (strcasecmp ("VerifyPeer", child->key) == 0) status = config_set_boolean (&st->verify_peer, child); else if (strcasecmp ("VerifyHost", child->key) == 0) status = config_set_boolean (&st->verify_host, child); else if (strcasecmp ("CACert", child->key) == 0) status = config_set_string (&st->cacert, child); else if (strcasecmp ("Server", child->key) == 0) status = config_set_string (&st->server, child); else { WARNING ("apache plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } /* Check if struct is complete.. */ if ((status == 0) && (st->url == NULL)) { ERROR ("apache plugin: Instance `%s': " "No URL has been configured.", st->name); status = -1; } if (status == 0) { user_data_t ud; char callback_name[3*DATA_MAX_NAME_LEN]; memset (&ud, 0, sizeof (ud)); ud.data = st; ud.free_func = (void *) apache_free; memset (callback_name, 0, sizeof (callback_name)); ssnprintf (callback_name, sizeof (callback_name), "apache/%s/%s", (st->host != NULL) ? st->host : hostname_g, (st->name != NULL) ? st->name : "default"), status = plugin_register_complex_read (/* group = */ NULL, /* name = */ callback_name, /* callback = */ apache_read_host, /* interval = */ NULL, /* user_data = */ &ud); } if (status != 0) { apache_free(st); return (-1); } return (0); } /* int config_add */
int registry_init(void) { char filename[FILENAME_MAX + 1]; // registry enabled? if(web_server_mode != WEB_SERVER_MODE_NONE) { registry.enabled = config_get_boolean(CONFIG_SECTION_REGISTRY, "enabled", 0); } else { info("Registry is disabled - use the central netdata"); config_set_boolean(CONFIG_SECTION_REGISTRY, "enabled", 0); registry.enabled = 0; } // pathnames snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir); registry.pathname = config_get(CONFIG_SECTION_REGISTRY, "registry db directory", filename); if(mkdir(registry.pathname, 0770) == -1 && errno != EEXIST) fatal("Cannot create directory '%s'.", registry.pathname); // filenames snprintfz(filename, FILENAME_MAX, "%s/netdata.public.unique.id", registry.pathname); registry.machine_guid_filename = config_get(CONFIG_SECTION_REGISTRY, "netdata unique id file", filename); snprintfz(filename, FILENAME_MAX, "%s/registry.db", registry.pathname); registry.db_filename = config_get(CONFIG_SECTION_REGISTRY, "registry db file", filename); snprintfz(filename, FILENAME_MAX, "%s/registry-log.db", registry.pathname); registry.log_filename = config_get(CONFIG_SECTION_REGISTRY, "registry log file", filename); // configuration options registry.save_registry_every_entries = (unsigned long long)config_get_number(CONFIG_SECTION_REGISTRY, "registry save db every new entries", 1000000); registry.persons_expiration = config_get_number(CONFIG_SECTION_REGISTRY, "registry expire idle persons days", 365) * 86400; registry.registry_domain = config_get(CONFIG_SECTION_REGISTRY, "registry domain", ""); registry.registry_to_announce = config_get(CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io"); registry.hostname = config_get(CONFIG_SECTION_REGISTRY, "registry hostname", netdata_configured_hostname); registry.verify_cookies_redirects = config_get_boolean(CONFIG_SECTION_REGISTRY, "verify browser cookies support", 1); setenv("NETDATA_REGISTRY_HOSTNAME", registry.hostname, 1); setenv("NETDATA_REGISTRY_URL", registry.registry_to_announce, 1); registry.max_url_length = (size_t)config_get_number(CONFIG_SECTION_REGISTRY, "max URL length", 1024); if(registry.max_url_length < 10) { registry.max_url_length = 10; config_set_number(CONFIG_SECTION_REGISTRY, "max URL length", (long long)registry.max_url_length); } registry.max_name_length = (size_t)config_get_number(CONFIG_SECTION_REGISTRY, "max URL name length", 50); if(registry.max_name_length < 10) { registry.max_name_length = 10; config_set_number(CONFIG_SECTION_REGISTRY, "max URL name length", (long long)registry.max_name_length); } // initialize entries counters registry.persons_count = 0; registry.machines_count = 0; registry.usages_count = 0; registry.urls_count = 0; registry.persons_urls_count = 0; registry.machines_urls_count = 0; // initialize memory counters registry.persons_memory = 0; registry.machines_memory = 0; registry.urls_memory = 0; registry.persons_urls_memory = 0; registry.machines_urls_memory = 0; // initialize locks netdata_mutex_init(®istry.lock); // create dictionaries registry.persons = dictionary_create(DICTIONARY_FLAGS); registry.machines = dictionary_create(DICTIONARY_FLAGS); avl_init(®istry.registry_urls_root_index, registry_url_compare); // load the registry database if(registry.enabled) { registry_log_open(); registry_db_load(); registry_log_load(); if(unlikely(registry_db_should_be_saved())) registry_db_save(); } return 0; }
void command_process(char *command_line) { VideoCircularBuffer *vcb = &video_circular_buffer; Command *cmd; char command[64], args[128], buf[32], *path; int i, n; if (!command_line || *command_line == '\0') return; n = sscanf(command_line, "%63s %[^\n]", command, args); if (n < 1 || command[0] == '#') return; for (cmd = NULL, i = 0; i < COMMAND_SIZE; cmd = NULL, ++i) { cmd = &commands[i]; if (!strcmp(command, cmd->name)) { if (cmd->n_args != n - 1) { log_printf("Wrong number of args for command: %s\n", command); return; } break; } } if (!cmd) { if ( !config_set_option(command, args, FALSE) && !mmalcam_config_parameter_set(command, args, TRUE) ) log_printf("Bad command: [%s] [%s]\n", command, args); return; } if (cmd->code != display_cmd) log_printf("command_process: %s\n", command_line); if (cmd->code < display_cmd && !display_is_default()) { display_set_default(); return; } switch (cmd->code) { case record: pthread_mutex_lock(&vcb->mutex); if (config_boolean_value(args) == TRUE) { if (vcb->pause) vcb->pause = FALSE; else { if (vcb->state == VCB_STATE_MOTION_RECORD) video_record_stop(vcb); video_record_start(vcb, VCB_STATE_MANUAL_RECORD_START); } } else video_record_stop(vcb); pthread_mutex_unlock(&vcb->mutex); break; case record_pause: /* Can pause manual record only. Because of event_gap/capture | times, I'm not even sure what it would mean to pause a | motion record. */ pthread_mutex_lock(&vcb->mutex); if (vcb->state == VCB_STATE_MANUAL_RECORD) vcb->pause = vcb->pause ? FALSE : TRUE; else vcb->pause = FALSE; pthread_mutex_unlock(&vcb->mutex); break; case still: snprintf(buf, sizeof(buf), "%d", pikrellcam.still_sequence); path = media_pathname(pikrellcam.still_dir, pikrellcam.still_filename, 'N', buf, '\0', NULL); pikrellcam.still_sequence += 1; still_capture(path); free(path); break; case tl_start: if ((n = atoi(args)) < 1) n = 0; time_lapse.activated = TRUE; time_lapse.on_hold = FALSE; if (!time_lapse.event && n > 0) { time_lapse.sequence = 0; ++time_lapse.series; time_lapse.event = event_add("timelapse", pikrellcam.t_now, n, timelapse_capture, NULL); } else if (n > 0) /* Change the period */ { time_lapse.event->time += (n - time_lapse.period); time_lapse.event->period = n; } if (n > 0) time_lapse.period = n; /* n == 0 just sets on_hold FALSE */ config_timelapse_save_status(); break; case tl_hold: config_set_boolean(&time_lapse.on_hold, args); config_timelapse_save_status(); break; case tl_end: if (time_lapse.activated) { event_remove(time_lapse.event); time_lapse.event = NULL; time_lapse.activated = FALSE; time_lapse.on_hold = FALSE; config_timelapse_save_status(); exec_no_wait(pikrellcam.on_timelapse_end_cmd, NULL); } break; case tl_inform_convert: if (!strcmp(args, "done")) { event_remove(time_lapse.inform_event); dup_string(&time_lapse.convert_name, ""); time_lapse.convert_size = 0; } else { dup_string(&time_lapse.convert_name, args); time_lapse.inform_event = event_add("tl_inform_convert", pikrellcam.t_now, 5, timelapse_inform_convert, NULL); } break; case tl_show_status: config_set_boolean(&time_lapse.show_status, args); break; case display_cmd: display_command(args); break; case motion_cmd: motion_command(args); break; case motion_enable: n = motion_frame.motion_enable; config_set_boolean(&motion_frame.motion_enable, args); if (n && !motion_frame.motion_enable) { pthread_mutex_lock(&vcb->mutex); if (vcb->state == VCB_STATE_MOTION_RECORD) video_record_stop(vcb); pthread_mutex_unlock(&vcb->mutex); } break; case save_config: config_save(pikrellcam.config_file); break; case quit: config_timelapse_save_status(); if (pikrellcam.config_modified) config_save(pikrellcam.config_file); display_quit(); exit(0); break; default: log_printf("command in table with no action!\n"); break; } }