static int rc_config(oconfig_item_t *ci) { for (int i = 0; i < ci->children_num; i++) { oconfig_item_t const *child = ci->children + i; const char *key = child->key; int status = 0; if (strcasecmp("DataDir", key) == 0) { status = cf_util_get_string(child, &datadir); if (status == 0) { int len = strlen(datadir); while ((len > 0) && (datadir[len - 1] == '/')) { len--; datadir[len] = 0; } if (len <= 0) sfree(datadir); } } else if (strcasecmp("DaemonAddress", key) == 0) status = cf_util_get_string(child, &daemon_address); else if (strcasecmp("CreateFiles", key) == 0) status = cf_util_get_boolean(child, &config_create_files); else if (strcasecmp("CreateFilesAsync", key) == 0) status = cf_util_get_boolean(child, &rrdcreate_config.async); else if (strcasecmp("CollectStatistics", key) == 0) status = cf_util_get_boolean(child, &config_collect_stats); else if (strcasecmp("StepSize", key) == 0) { int tmp = -1; status = rc_config_get_int_positive(child, &tmp); if (status == 0) rrdcreate_config.stepsize = (unsigned long)tmp; } else if (strcasecmp("HeartBeat", key) == 0) status = rc_config_get_int_positive(child, &rrdcreate_config.heartbeat); else if (strcasecmp("RRARows", key) == 0) status = rc_config_get_int_positive(child, &rrdcreate_config.rrarows); else if (strcasecmp("RRATimespan", key) == 0) { int tmp = -1; status = rc_config_get_int_positive(child, &tmp); if (status == 0) status = rc_config_add_timespan(tmp); } else if (strcasecmp("XFF", key) == 0) status = rc_config_get_xff(child, &rrdcreate_config.xff); else { WARNING("rrdcached plugin: Ignoring invalid option %s.", key); continue; } if (status != 0) WARNING("rrdcached plugin: Handling the \"%s\" option failed.", key); } if (daemon_address != NULL) { plugin_register_write("rrdcached", rc_write, /* user_data = */ NULL); plugin_register_flush("rrdcached", rc_flush, /* user_data = */ NULL); } return 0; } /* int rc_config */
static int dpdk_events_link_status_config(dpdk_events_ctx_t *ec, oconfig_item_t *ci) { ec->config.link_status.enabled = 1; DEBUG(DPDK_EVENTS_PLUGIN ": Subscribed for Link Status Events."); for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("EnabledPortMask", child->key) == 0) { if (cf_util_get_int(child, (int *)&ec->config.link_status.enabled_port_mask)) return -1; DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:Enabled Port Mask 0x%X", ec->config.link_status.enabled_port_mask); } else if (strcasecmp("SendEventsOnUpdate", child->key) == 0) { if (cf_util_get_boolean(child, &ec->config.link_status.send_updated)) return -1; DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:SendEventsOnUpdate %d", ec->config.link_status.send_updated); } else if (strcasecmp("SendNotification", child->key) == 0) { if (cf_util_get_boolean(child, &ec->config.link_status.notify)) return -1; DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:SendNotification %d", ec->config.link_status.notify); } else if (strcasecmp("PortName", child->key) != 0) { ERROR(DPDK_EVENTS_PLUGIN ": unrecognized configuration option %s.", child->key); return -1; } } int port_num = 0; /* parse port names after EnabledPortMask was parsed */ for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("PortName", child->key) == 0) { while (!(ec->config.link_status.enabled_port_mask & (1 << port_num))) port_num++; if (cf_util_get_string_buffer( child, ec->config.link_status.port_name[port_num], sizeof(ec->config.link_status.port_name[port_num]))) { return -1; } DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:Port %d Name: %s", port_num, ec->config.link_status.port_name[port_num]); port_num++; } } return 0; }
static int memory_config(oconfig_item_t *ci) /* {{{ */ { for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("ValuesAbsolute", child->key) == 0) cf_util_get_boolean(child, &values_absolute); else if (strcasecmp("ValuesPercentage", child->key) == 0) cf_util_get_boolean(child, &values_percentage); else ERROR("memory plugin: Invalid configuration option: " "\"%s\".", child->key); } return 0; } /* }}} int memory_config */
static int statsd_config_node (statsd_config_t *conf, oconfig_item_t *ci) { int i; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) cf_util_get_string (child, &conf->host); else if (strcasecmp ("Port", child->key) == 0) cf_util_get_service (child, &conf->service); else if (strcasecmp ("DeleteCounters", child->key) == 0) cf_util_get_boolean (child, &conf->delete_counters); else if (strcasecmp ("DeleteTimers", child->key) == 0) cf_util_get_boolean (child, &conf->delete_timers); else if (strcasecmp ("DeleteGauges", child->key) == 0) cf_util_get_boolean (child, &conf->delete_gauges); else if (strcasecmp ("DeleteSets", child->key) == 0) cf_util_get_boolean (child, &conf->delete_sets); else if (strcasecmp ("TimerLower", child->key) == 0) cf_util_get_boolean (child, &conf->timer_lower); else if (strcasecmp ("TimerUpper", child->key) == 0) cf_util_get_boolean (child, &conf->timer_upper); else if (strcasecmp ("TimerSum", child->key) == 0) cf_util_get_boolean (child, &conf->timer_sum); else if (strcasecmp ("TimerCount", child->key) == 0) cf_util_get_boolean (child, &conf->timer_count); else if (strcasecmp ("LeaveMetricsNameASIS", child->key) == 0) cf_util_get_boolean (child, &conf->leave_metrics_name_asis); else if (strcasecmp ("GlobalPrefix", child->key) == 0) cf_util_get_string (child, &conf->global_prefix); else if (strcasecmp ("CounterPrefix", child->key) == 0) cf_util_get_string (child, &conf->counter_prefix); else if (strcasecmp ("TimerPrefix", child->key) == 0) cf_util_get_string (child, &conf->timer_prefix); else if (strcasecmp ("GaugePrefix", child->key) == 0) cf_util_get_string (child, &conf->gauge_prefix); else if (strcasecmp ("SetPrefix", child->key) == 0) cf_util_get_string (child, &conf->set_prefix); else if (strcasecmp ("GlobalPostfix", child->key) == 0) cf_util_get_string (child, &conf->global_postfix); else if (strcasecmp ("TimerPercentile", child->key) == 0) statsd_config_timer_percentile (conf, child); else ERROR ("statsd plugin: The \"%s\" config option is not valid.", child->key); } return (0); }
static int dpdk_events_keep_alive_config(dpdk_events_ctx_t *ec, oconfig_item_t *ci) { ec->config.keep_alive.enabled = 1; DEBUG(DPDK_EVENTS_PLUGIN ": Subscribed for Keep Alive Events."); for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("SendEventsOnUpdate", child->key) == 0) { if (cf_util_get_boolean(child, &ec->config.keep_alive.send_updated)) return -1; DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:SendEventsOnUpdate %d", ec->config.keep_alive.send_updated); } else if (strcasecmp("LCoreMask", child->key) == 0) { char lcore_mask[DATA_MAX_NAME_LEN]; if (cf_util_get_string_buffer(child, lcore_mask, sizeof(lcore_mask))) return -1; ec->config.keep_alive.lcore_mask = str_to_uint128(lcore_mask, strlen(lcore_mask)); DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:LCoreMask 0x%" PRIX64 "%" PRIX64 "", ec->config.keep_alive.lcore_mask.high, ec->config.keep_alive.lcore_mask.low); } else if (strcasecmp("KeepAliveShmName", child->key) == 0) { if (cf_util_get_string_buffer(child, ec->config.keep_alive.shm_name, sizeof(ec->config.keep_alive.shm_name))) return -1; DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:KeepAliveShmName %s", ec->config.keep_alive.shm_name); } else if (strcasecmp("SendNotification", child->key) == 0) { if (cf_util_get_boolean(child, &ec->config.keep_alive.notify)) return -1; DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:SendNotification %d", ec->config.keep_alive.notify); } else { ERROR(DPDK_EVENTS_PLUGIN ": unrecognized configuration option %s.", child->key); return -1; } } return 0; }
static int battery_config(oconfig_item_t *ci) { for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("ValuesPercentage", child->key) == 0) cf_util_get_boolean(child, &report_percent); else if (strcasecmp("ReportDegraded", child->key) == 0) cf_util_get_boolean(child, &report_degraded); else if (strcasecmp("QueryStateFS", child->key) == 0) cf_util_get_boolean(child, &query_statefs); else WARNING("battery plugin: Ignoring unknown " "configuration option \"%s\".", child->key); } return (0); } /* }}} int battery_config */
static int swap_config(oconfig_item_t *ci) /* {{{ */ { for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("ReportBytes", child->key) == 0) #if KERNEL_LINUX cf_util_get_boolean(child, &report_bytes); #else WARNING("swap plugin: The \"ReportBytes\" option " "is only valid under Linux. " "The option is going to be ignored."); #endif else if (strcasecmp("ReportByDevice", child->key) == 0) #if SWAP_HAVE_REPORT_BY_DEVICE cf_util_get_boolean(child, &report_by_device); #else WARNING("swap plugin: The \"ReportByDevice\" option " "is not supported on this platform. " "The option is going to be ignored."); #endif /* SWAP_HAVE_REPORT_BY_DEVICE */ else if (strcasecmp("ValuesAbsolute", child->key) == 0)
static int apcups_config (oconfig_item_t *ci) { int i; _Bool persistent_conn_set = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp (child->key, "Host") == 0) cf_util_get_string (child, &conf_node); else if (strcasecmp (child->key, "Port") == 0) cf_util_get_service (child, &conf_service); else if (strcasecmp (child->key, "ReportSeconds") == 0) cf_util_get_boolean (child, &conf_report_seconds); else if (strcasecmp (child->key, "PersistentConnection") == 0) { cf_util_get_boolean (child, &conf_persistent_conn); persistent_conn_set = 1; } else ERROR ("apcups plugin: Unknown config option \"%s\".", child->key); } if (!persistent_conn_set) { double interval = CDTIME_T_TO_DOUBLE(plugin_get_interval()); if (interval > APCUPS_SERVER_TIMEOUT) { NOTICE ("apcups plugin: Plugin poll interval set to %.3f seconds. " "Apcupsd NIS socket timeout is %.3f seconds, " "PersistentConnection disabled by default.", interval, APCUPS_SERVER_TIMEOUT); conf_persistent_conn = 0; } } return (0); } /* int apcups_config */
static int statsd_config (oconfig_item_t *ci) /* {{{ */ { int i; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) cf_util_get_string (child, &conf_node); else if (strcasecmp ("Port", child->key) == 0) cf_util_get_service (child, &conf_service); else if (strcasecmp ("DeleteCounters", child->key) == 0) cf_util_get_boolean (child, &conf_delete_counters); else if (strcasecmp ("DeleteTimers", child->key) == 0) cf_util_get_boolean (child, &conf_delete_timers); else if (strcasecmp ("DeleteGauges", child->key) == 0) cf_util_get_boolean (child, &conf_delete_gauges); else if (strcasecmp ("DeleteSets", child->key) == 0) cf_util_get_boolean (child, &conf_delete_sets); else if (strcasecmp ("CounterSum", child->key) == 0) cf_util_get_boolean (child, &conf_counter_sum); else if (strcasecmp ("TimerLower", child->key) == 0) cf_util_get_boolean (child, &conf_timer_lower); else if (strcasecmp ("TimerUpper", child->key) == 0) cf_util_get_boolean (child, &conf_timer_upper); else if (strcasecmp ("TimerSum", child->key) == 0) cf_util_get_boolean (child, &conf_timer_sum); else if (strcasecmp ("TimerCount", child->key) == 0) cf_util_get_boolean (child, &conf_timer_count); else if (strcasecmp ("TimerPercentile", child->key) == 0) statsd_config_timer_percentile (child); else ERROR ("statsd plugin: The \"%s\" config option is not valid.", child->key); } return (0); } /* }}} int statsd_config */
static int ethstat_config(oconfig_item_t *ci) /* {{{ */ { for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Interface", child->key) == 0) ethstat_add_interface(child); else if (strcasecmp("Map", child->key) == 0) ethstat_add_map(child); else if (strcasecmp("MappedOnly", child->key) == 0) (void)cf_util_get_boolean(child, &collect_mapped_only); else WARNING("ethstat plugin: The config option \"%s\" is unknown.", child->key); } return 0; } /* }}} */
/* * Public API */ curl_stats_t *curl_stats_from_config (oconfig_item_t *ci) { curl_stats_t *s; int i; if (ci == NULL) return NULL; s = calloc (1, sizeof (*s)); if (s == NULL) return NULL; for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; size_t field; _Bool enabled = 0; for (field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field) { if (! strcasecmp (c->key, field_specs[field].config_key)) break; if (! strcasecmp (c->key, field_specs[field].name)) break; } if (field >= STATIC_ARRAY_SIZE (field_specs)) { ERROR ("curl stats: Unknown field name %s", c->key); free (s); return NULL; } if (cf_util_get_boolean (c, &enabled) != 0) { free (s); return NULL; } if (enabled) enable_field (s, field_specs[field].offset); } return s; } /* curl_stats_from_config */
static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{ */ { int status; int i; struct kafka_topic_context *tctx; char *key; char *val; char callback_name[DATA_MAX_NAME_LEN]; char errbuf[1024]; user_data_t ud; oconfig_item_t *child; rd_kafka_conf_res_t ret; if ((tctx = calloc(1, sizeof (*tctx))) == NULL) { ERROR ("write_kafka plugin: calloc failed."); return; } tctx->escape_char = '.'; tctx->store_rates = 1; rd_kafka_conf_set_log_cb(conf, kafka_log); if ((tctx->kafka = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errbuf, sizeof(errbuf))) == NULL) { sfree(tctx); ERROR("write_kafka plugin: cannot create kafka handle."); return; } conf = NULL; if ((tctx->conf = rd_kafka_topic_conf_new()) == NULL) { rd_kafka_destroy(tctx->kafka); sfree(tctx); ERROR ("write_kafka plugin: cannot create topic configuration."); return; } if (ci->values_num != 1) { WARNING("kafka topic name needed."); goto errout; } if (ci->values[0].type != OCONFIG_TYPE_STRING) { WARNING("kafka topic needs a string argument."); goto errout; } if ((tctx->topic_name = strdup(ci->values[0].value.string)) == NULL) { ERROR("write_kafka plugin: cannot copy topic name."); goto errout; } for (i = 0; i < ci->children_num; i++) { /* * The code here could be simplified but makes room * for easy adding of new options later on. */ child = &ci->children[i]; status = 0; if (strcasecmp ("Property", child->key) == 0) { if (child->values_num != 2) { WARNING("kafka properties need both a key and a value."); goto errout; } if (child->values[0].type != OCONFIG_TYPE_STRING || child->values[1].type != OCONFIG_TYPE_STRING) { WARNING("kafka properties needs string arguments."); goto errout; } key = child->values[0].value.string; val = child->values[0].value.string; ret = rd_kafka_topic_conf_set(tctx->conf,key, val, errbuf, sizeof(errbuf)); if (ret != RD_KAFKA_CONF_OK) { WARNING("cannot set kafka topic property %s to %s: %s.", key, val, errbuf); goto errout; } } else if (strcasecmp ("Key", child->key) == 0) { char *tmp_buf = NULL; status = cf_util_get_string(child, &tmp_buf); if (status != 0) { WARNING("write_kafka plugin: invalid key supplied"); break; } if (strcasecmp(tmp_buf, "Random") != 0) { tctx->has_key = 1; tctx->key = crc32_buffer((u_char *)tmp_buf, strlen(tmp_buf)); } sfree(tmp_buf); } else if (strcasecmp ("Format", child->key) == 0) { status = cf_util_get_string(child, &key); if (status != 0) goto errout; assert(key != NULL); if (strcasecmp(key, "Command") == 0) { tctx->format = KAFKA_FORMAT_COMMAND; } else if (strcasecmp(key, "Graphite") == 0) { tctx->format = KAFKA_FORMAT_GRAPHITE; } else if (strcasecmp(key, "Json") == 0) { tctx->format = KAFKA_FORMAT_JSON; } else { WARNING ("write_kafka plugin: Invalid format string: %s", key); } sfree(key); } else if (strcasecmp ("StoreRates", child->key) == 0) { status = cf_util_get_boolean (child, &tctx->store_rates); (void) cf_util_get_flag (child, &tctx->graphite_flags, GRAPHITE_STORE_RATES); } else if (strcasecmp ("GraphiteSeparateInstances", child->key) == 0) { status = cf_util_get_flag (child, &tctx->graphite_flags, GRAPHITE_SEPARATE_INSTANCES); } else if (strcasecmp ("GraphiteAlwaysAppendDS", child->key) == 0) { status = cf_util_get_flag (child, &tctx->graphite_flags, GRAPHITE_ALWAYS_APPEND_DS); } else if (strcasecmp ("GraphitePrefix", child->key) == 0) { status = cf_util_get_string (child, &tctx->prefix); } else if (strcasecmp ("GraphitePostfix", child->key) == 0) { status = cf_util_get_string (child, &tctx->postfix); } else if (strcasecmp ("GraphiteEscapeChar", child->key) == 0) { char *tmp_buff = NULL; status = cf_util_get_string (child, &tmp_buff); if (strlen (tmp_buff) > 1) WARNING ("write_kafka plugin: The option \"GraphiteEscapeChar\" handles " "only one character. Others will be ignored."); tctx->escape_char = tmp_buff[0]; sfree (tmp_buff); } else { WARNING ("write_kafka plugin: Invalid directive: %s.", child->key); } if (status != 0) break; } rd_kafka_topic_conf_set_partitioner_cb(tctx->conf, kafka_partition); rd_kafka_topic_conf_set_opaque(tctx->conf, tctx); if ((tctx->topic = rd_kafka_topic_new(tctx->kafka, tctx->topic_name, tctx->conf)) == NULL) { ERROR("write_kafka plugin: cannot create topic."); goto errout; } tctx->conf = NULL; ssnprintf(callback_name, sizeof(callback_name), "write_kafka/%s", tctx->topic_name); ud.data = tctx; ud.free_func = kafka_topic_context_free; status = plugin_register_write (callback_name, kafka_write, &ud); if (status != 0) { WARNING ("write_kafka plugin: plugin_register_write (\"%s\") " "failed with status %i.", callback_name, status); goto errout; } return; errout: if (conf != NULL) rd_kafka_conf_destroy(conf); if (tctx->kafka != NULL) rd_kafka_destroy(tctx->kafka); if (tctx->topic != NULL) rd_kafka_topic_destroy(tctx->topic); if (tctx->topic_name != NULL) free(tctx->topic_name); if (tctx->conf != NULL) rd_kafka_topic_conf_destroy(tctx->conf); sfree(tctx); } /* }}} int kafka_config_topic */
static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ { cx_t *db; int status = 0; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl_xml plugin: The `URL' block " "needs exactly one string argument."); return (-1); } db = (cx_t *) malloc (sizeof (*db)); if (db == NULL) { ERROR ("curl_xml plugin: malloc failed."); return (-1); } memset (db, 0, sizeof (*db)); db->timeout = -1; if (strcasecmp ("URL", ci->key) == 0) { status = cf_util_get_string (ci, &db->url); if (status != 0) { sfree (db); return (status); } } else { ERROR ("curl_xml plugin: cx_config: " "Invalid key: %s", ci->key); cx_free (db); return (-1); } /* Fill the `cx_t' structure.. */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Instance", child->key) == 0) status = cf_util_get_string (child, &db->instance); else if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &db->host); else if (strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &db->user); else if (strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &db->pass); else if (strcasecmp ("Digest", child->key) == 0) status = cf_util_get_boolean (child, &db->digest); else if (strcasecmp ("VerifyPeer", child->key) == 0) status = cf_util_get_boolean (child, &db->verify_peer); else if (strcasecmp ("VerifyHost", child->key) == 0) status = cf_util_get_boolean (child, &db->verify_host); else if (strcasecmp ("CACert", child->key) == 0) status = cf_util_get_string (child, &db->cacert); else if (strcasecmp ("xpath", child->key) == 0) status = cx_config_add_xpath (db, child); else if (strcasecmp ("Header", child->key) == 0) status = cx_config_append_string ("Header", &db->headers, child); else if (strcasecmp ("Post", child->key) == 0) status = cf_util_get_string (child, &db->post_body); else if (strcasecmp ("Namespace", child->key) == 0) status = cx_config_add_namespace (db, child); else if (strcasecmp ("Timeout", child->key) == 0) status = cf_util_get_int (child, &db->timeout); else { WARNING ("curl_xml plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } if (status == 0) { if (db->list == NULL) { WARNING ("curl_xml plugin: No (valid) `Key' block " "within `URL' block `%s'.", db->url); status = -1; } if (status == 0) status = cx_init_curl (db); } /* If all went well, register this database for reading */ if (status == 0) { user_data_t ud; char *cb_name; if (db->instance == NULL) db->instance = strdup("default"); DEBUG ("curl_xml plugin: Registering new read callback: %s", db->instance); memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = cx_free; cb_name = ssnprintf_alloc ("curl_xml-%s-%s", db->instance, db->url); plugin_register_complex_read (/* group = */ "curl_xml", cb_name, cx_read, /* interval = */ 0, &ud); sfree (cb_name); } else { cx_free (db); return (-1); } return (0); } /* }}} int cx_config_add_url */
static int mr_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mr_match_t *m; int status; int i; m = (mr_match_t *) malloc (sizeof (*m)); if (m == NULL) { log_err ("mr_create: malloc failed."); return (-ENOMEM); } memset (m, 0, sizeof (*m)); m->invert = 0; status = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if ((strcasecmp ("Host", child->key) == 0) || (strcasecmp ("Hostname", child->key) == 0)) status = mr_config_add_regex (&m->host, child); else if (strcasecmp ("Plugin", child->key) == 0) status = mr_config_add_regex (&m->plugin, child); else if (strcasecmp ("PluginInstance", child->key) == 0) status = mr_config_add_regex (&m->plugin_instance, child); else if (strcasecmp ("Type", child->key) == 0) status = mr_config_add_regex (&m->type, child); else if (strcasecmp ("TypeInstance", child->key) == 0) status = mr_config_add_regex (&m->type_instance, child); else if (strcasecmp ("Invert", child->key) == 0) status = cf_util_get_boolean(child, &m->invert); else { log_err ("The `%s' configuration option is not understood and " "will be ignored.", child->key); status = 0; } if (status != 0) break; } /* Additional sanity-checking */ while (status == 0) { if ((m->host == NULL) && (m->plugin == NULL) && (m->plugin_instance == NULL) && (m->type == NULL) && (m->type_instance == NULL)) { log_err ("No (valid) regular expressions have been configured. " "This match will be ignored."); status = -1; } break; } if (status != 0) { mr_free_match (m); return (status); } *user_data = m; return (0); } /* }}} int mr_create */
static int riemann_config_node(oconfig_item_t *ci) { struct riemann_host *host = NULL; int status = 0; int i; oconfig_item_t *child; char callback_name[DATA_MAX_NAME_LEN]; user_data_t ud; if ((host = calloc(1, sizeof (*host))) == NULL) { ERROR ("write_riemann plugin: calloc failed."); return ENOMEM; } pthread_mutex_init (&host->lock, NULL); host->reference_count = 1; host->node = NULL; host->service = NULL; host->store_rates = 1; host->always_append_ds = 0; host->use_tcp = 0; status = cf_util_get_string (ci, &host->name); if (status != 0) { WARNING("write_riemann plugin: Required host name is missing."); riemann_free (host); return -1; } for (i = 0; i < ci->children_num; i++) { /* * The code here could be simplified but makes room * for easy adding of new options later on. */ child = &ci->children[i]; status = 0; if (strcasecmp ("Host", child->key) == 0) { status = cf_util_get_string (child, &host->node); if (status != 0) break; } else if (strcasecmp ("Port", child->key) == 0) { status = cf_util_get_service (child, &host->service); if (status != 0) { ERROR ("write_riemann plugin: Invalid argument " "configured for the \"Port\" " "option."); break; } } else if (strcasecmp ("Protocol", child->key) == 0) { char tmp[16]; status = cf_util_get_string_buffer (child, tmp, sizeof (tmp)); if (status != 0) { ERROR ("write_riemann plugin: cf_util_get_" "string_buffer failed with " "status %i.", status); break; } if (strcasecmp ("UDP", tmp) == 0) host->use_tcp = 0; else if (strcasecmp ("TCP", tmp) == 0) host->use_tcp = 1; else WARNING ("write_riemann plugin: The value " "\"%s\" is not valid for the " "\"Protocol\" option. Use " "either \"UDP\" or \"TCP\".", tmp); } else if (strcasecmp ("StoreRates", child->key) == 0) { status = cf_util_get_boolean (child, &host->store_rates); if (status != 0) break; } else if (strcasecmp ("AlwaysAppendDS", child->key) == 0) { status = cf_util_get_boolean (child, &host->always_append_ds); if (status != 0) break; } else { WARNING("write_riemann plugin: ignoring unknown config " "option: \"%s\"", child->key); } } if (status != 0) { riemann_free (host); return status; } ssnprintf (callback_name, sizeof (callback_name), "write_riemann/%s", host->name); ud.data = host; ud.free_func = riemann_free; pthread_mutex_lock (&host->lock); status = plugin_register_write (callback_name, riemann_write, &ud); if (status != 0) WARNING ("write_riemann plugin: plugin_register_write (\"%s\") " "failed with status %i.", callback_name, status); else /* success */ host->reference_count++; status = plugin_register_notification (callback_name, riemann_notification, &ud); if (status != 0) WARNING ("write_riemann plugin: plugin_register_notification (\"%s\") " "failed with status %i.", callback_name, status); else /* success */ host->reference_count++; if (host->reference_count <= 1) { /* Both callbacks failed => free memory. * We need to unlock here, because riemann_free() will lock. * This is not a race condition, because we're the only one * holding a reference. */ pthread_mutex_unlock (&host->lock); riemann_free (host); return (-1); } host->reference_count--; pthread_mutex_unlock (&host->lock); return status; }
static int csnmp_config_add_data (oconfig_item_t *ci) { data_definition_t *dd; int status = 0; int i; dd = (data_definition_t *) malloc (sizeof (data_definition_t)); if (dd == NULL) return (-1); memset (dd, '\0', sizeof (data_definition_t)); status = cf_util_get_string(ci, &dd->name); if (status != 0) { free (dd); return (-1); } dd->scale = 1.0; dd->shift = 0.0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; if (strcasecmp ("Type", option->key) == 0) status = cf_util_get_string(option, &dd->type); else if (strcasecmp ("Table", option->key) == 0) status = cf_util_get_boolean(option, &dd->is_table); else if (strcasecmp ("Instance", option->key) == 0) status = csnmp_config_add_data_instance (dd, option); else if (strcasecmp ("InstancePrefix", option->key) == 0) status = csnmp_config_add_data_instance_prefix (dd, option); else if (strcasecmp ("Values", option->key) == 0) status = csnmp_config_add_data_values (dd, option); else if (strcasecmp ("Shift", option->key) == 0) status = cf_util_get_double(option, &dd->shift); else if (strcasecmp ("Scale", option->key) == 0) status = cf_util_get_double(option, &dd->scale); else if (strcasecmp ("Ignore", option->key) == 0) status = csnmp_config_add_data_blacklist(dd, option); else if (strcasecmp ("InvertMatch", option->key) == 0) status = csnmp_config_add_data_blacklist_match_inverted(dd, option); else { WARNING ("snmp plugin: Option `%s' not allowed here.", option->key); status = -1; } if (status != 0) break; } /* for (ci->children) */ while (status == 0) { if (dd->type == NULL) { WARNING ("snmp plugin: `Type' not given for data `%s'", dd->name); status = -1; break; } if (dd->values == NULL) { WARNING ("snmp plugin: No `Value' given for data `%s'", dd->name); status = -1; break; } break; } /* while (status == 0) */ if (status != 0) { sfree (dd->name); sfree (dd->instance_prefix); sfree (dd->values); sfree (dd->ignores); sfree (dd); return (-1); } DEBUG ("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = %zu }", dd->name, dd->type, (dd->is_table != 0) ? "true" : "false", dd->values_len); if (data_head == NULL) data_head = dd; else { data_definition_t *last; last = data_head; while (last->next != NULL) last = last->next; last->next = dd; } return (0); } /* int csnmp_config_add_data */
static int wm_config_node (oconfig_item_t *ci) /* {{{ */ { wm_node_t *node; int status; node = calloc (1, sizeof (*node)); if (node == NULL) return (ENOMEM); mongo_init (node->conn); node->host = NULL; node->store_rates = 1; pthread_mutex_init (&node->lock, /* attr = */ NULL); status = cf_util_get_string_buffer (ci, node->name, sizeof (node->name)); if (status != 0) { sfree (node); return (status); } for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &node->host); else if (strcasecmp ("Port", child->key) == 0) { status = cf_util_get_port_number (child); if (status > 0) { node->port = status; status = 0; } } else if (strcasecmp ("Timeout", child->key) == 0) status = cf_util_get_int (child, &node->timeout); else if (strcasecmp ("StoreRates", child->key) == 0) status = cf_util_get_boolean (child, &node->store_rates); else if (strcasecmp ("Database", child->key) == 0) status = cf_util_get_string (child, &node->db); else if (strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &node->user); else if (strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &node->passwd); else WARNING ("write_mongodb plugin: Ignoring unknown config option \"%s\".", child->key); if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ if ((node->db != NULL) || (node->user != NULL) || (node->passwd != NULL)) { if ((node->db == NULL) || (node->user == NULL) || (node->passwd == NULL)) { WARNING ("write_mongodb plugin: Authentication requires the " "\"Database\", \"User\" and \"Password\" options to be specified, " "but at last one of them is missing. Authentication will NOT be " "used."); sfree (node->db); sfree (node->user); sfree (node->passwd); } } if (status == 0) { char cb_name[DATA_MAX_NAME_LEN]; user_data_t ud; ssnprintf (cb_name, sizeof (cb_name), "write_mongodb/%s", node->name); ud.data = node; ud.free_func = wm_config_free; status = plugin_register_write (cb_name, wm_write, &ud); INFO ("write_mongodb plugin: registered write plugin %s %d",cb_name,status); } if (status != 0) wm_config_free (node); return (status); } /* }}} int wm_config_node */
static int cc_config_add_page (oconfig_item_t *ci) /* {{{ */ { web_page_t *page; int status; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl plugin: `Page' blocks need exactly one string argument."); return (-1); } page = calloc (1, sizeof (*page)); if (page == NULL) { ERROR ("curl plugin: calloc failed."); return (-1); } page->url = NULL; page->user = NULL; page->pass = NULL; page->digest = 0; page->verify_peer = 1; page->verify_host = 1; page->response_time = 0; page->response_code = 0; page->timeout = -1; page->instance = strdup (ci->values[0].value.string); if (page->instance == NULL) { ERROR ("curl plugin: strdup failed."); sfree (page); return (-1); } /* Process all children */ status = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("URL", child->key) == 0) status = cf_util_get_string (child, &page->url); else if (strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &page->user); else if (strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &page->pass); else if (strcasecmp ("Digest", child->key) == 0) status = cf_util_get_boolean (child, &page->digest); else if (strcasecmp ("VerifyPeer", child->key) == 0) status = cf_util_get_boolean (child, &page->verify_peer); else if (strcasecmp ("VerifyHost", child->key) == 0) status = cf_util_get_boolean (child, &page->verify_host); else if (strcasecmp ("MeasureResponseTime", child->key) == 0) status = cf_util_get_boolean (child, &page->response_time); else if (strcasecmp ("MeasureResponseCode", child->key) == 0) status = cf_util_get_boolean (child, &page->response_code); else if (strcasecmp ("CACert", child->key) == 0) status = cf_util_get_string (child, &page->cacert); else if (strcasecmp ("Match", child->key) == 0) /* Be liberal with failing matches => don't set `status'. */ cc_config_add_match (page, child); else if (strcasecmp ("Header", child->key) == 0) status = cc_config_append_string ("Header", &page->headers, child); else if (strcasecmp ("Post", child->key) == 0) status = cf_util_get_string (child, &page->post_body); else if (strcasecmp ("Timeout", child->key) == 0) status = cf_util_get_int (child, &page->timeout); else { WARNING ("curl plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ /* Additionial sanity checks and libCURL initialization. */ while (status == 0) { if (page->url == NULL) { WARNING ("curl plugin: `URL' missing in `Page' block."); status = -1; } if (page->matches == NULL && !page->response_time && !page->response_code) { assert (page->instance != NULL); WARNING ("curl plugin: No (valid) `Match' block " "or MeasureResponseTime or MeasureResponseCode within " "`Page' block `%s'.", page->instance); status = -1; } if (status == 0) status = cc_page_init_curl (page); break; } /* while (status == 0) */ if (status != 0) { cc_web_page_free (page); return (status); } /* Add the new page to the linked list */ if (pages_g == NULL) pages_g = page; else { web_page_t *prev; prev = pages_g; while (prev->next != NULL) prev = prev->next; prev->next = page; } return (0); } /* }}} int cc_config_add_page */
static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ { cj_t *db; int status = 0; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl_json plugin: The `URL' block " "needs exactly one string argument."); return (-1); } db = (cj_t *) malloc (sizeof (*db)); if (db == NULL) { ERROR ("curl_json plugin: malloc failed."); return (-1); } memset (db, 0, sizeof (*db)); if (strcasecmp ("URL", ci->key) == 0) status = cf_util_get_string (ci, &db->url); else if (strcasecmp ("Sock", ci->key) == 0) status = cf_util_get_string (ci, &db->sock); else { ERROR ("curl_json plugin: cj_config: " "Invalid key: %s", ci->key); return (-1); } if (status != 0) { sfree (db); return (status); } /* Fill the `cj_t' structure.. */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Instance", child->key) == 0) status = cf_util_get_string (child, &db->instance); else if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &db->host); else if (db->url && strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &db->user); else if (db->url && strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &db->pass); else if (strcasecmp ("Digest", child->key) == 0) status = cf_util_get_boolean (child, &db->digest); else if (db->url && strcasecmp ("VerifyPeer", child->key) == 0) status = cf_util_get_boolean (child, &db->verify_peer); else if (db->url && strcasecmp ("VerifyHost", child->key) == 0) status = cf_util_get_boolean (child, &db->verify_host); else if (db->url && strcasecmp ("CACert", child->key) == 0) status = cf_util_get_string (child, &db->cacert); else if (db->url && strcasecmp ("Header", child->key) == 0) status = cj_config_append_string ("Header", &db->headers, child); else if (db->url && strcasecmp ("Post", child->key) == 0) status = cf_util_get_string (child, &db->post_body); else if (strcasecmp ("Key", child->key) == 0) status = cj_config_add_key (db, child); else if (strcasecmp ("Interval", child->key) == 0) status = cf_util_get_cdtime(child, &db->interval); else { WARNING ("curl_json plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } if (status == 0) { if (db->tree == NULL) { WARNING ("curl_json plugin: No (valid) `Key' block within `%s' \"`%s'\".", db->url ? "URL" : "Sock", db->url ? db->url : db->sock); status = -1; } if (status == 0 && db->url) status = cj_init_curl (db); } /* If all went well, register this database for reading */ if (status == 0) { user_data_t ud; char *cb_name; struct timespec interval = { 0, 0 }; CDTIME_T_TO_TIMESPEC (db->interval, &interval); if (db->instance == NULL) db->instance = strdup("default"); DEBUG ("curl_json plugin: Registering new read callback: %s", db->instance); memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = cj_free; cb_name = ssnprintf_alloc ("curl_json-%s-%s", db->instance, db->url ? db->url : db->sock); plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read, /* interval = */ (db->interval > 0) ? &interval : NULL, &ud); sfree (cb_name); } else { cj_free (db); return (-1); } return (0); }
/* Configuration handling functiions * <Plugin memcached> * <Instance "instance_name"> * Host foo.zomg.com * Port "1234" * </Instance> * </Plugin> */ static int config_add_instance(oconfig_item_t *ci) { memcached_t *st; int i; int status = 0; /* Disable automatic generation of default instance in the init callback. */ memcached_have_instances = 1; st = malloc (sizeof (*st)); if (st == NULL) { ERROR ("memcached plugin: malloc failed."); return (-1); } memset (st, 0, sizeof (*st)); st->name = NULL; st->socket = NULL; st->host = NULL; st->port = NULL; st->use_global_hostn = MEMCACHED_DEF_G_HOSTN; if (strcasecmp (ci->key, "Plugin") == 0) /* default instance */ st->name = sstrdup ("__legacy__"); else /* <Instance /> block */ status = cf_util_get_string (ci, &st->name); 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 ("Socket", child->key) == 0) status = cf_util_get_string (child, &st->socket); else if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &st->host); else if (strcasecmp ("Port", child->key) == 0) status = cf_util_get_service (child, &st->port); else if (strcasecmp ("UseGlobalHostname", child->key) == 0) status = cf_util_get_boolean (child, &st->use_global_hostn); else { WARNING ("memcached plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } if (status == 0) status = memcached_add_read_callback (st); if (status != 0) { memcached_free(st); return (-1); } return (0); }
/* Configuration handling functions {{{ * * <Plugin mysql> * <Database "plugin_instance1"> * Host "localhost" * Port 22000 * ... * </Database> * </Plugin> */ static int mysql_config_database (oconfig_item_t *ci) /* {{{ */ { mysql_database_t *db; int status = 0; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("mysql plugin: The `Database' block " "needs exactly one string argument."); return (-1); } db = (mysql_database_t *) malloc (sizeof (*db)); if (db == NULL) { ERROR ("mysql plugin: malloc failed."); return (-1); } memset (db, 0, sizeof (*db)); /* initialize all the pointers */ db->host = NULL; db->user = NULL; db->pass = NULL; db->database = NULL; db->socket = NULL; db->con = NULL; /* trigger a notification, if it's not running */ db->slave_io_running = 1; db->slave_sql_running = 1; status = cf_util_get_string (ci, &db->instance); if (status != 0) { sfree (db); return (status); } assert (db->instance != NULL); /* Fill the `mysql_database_t' structure.. */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &db->host); else if (strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &db->user); else if (strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &db->pass); else if (strcasecmp ("Port", child->key) == 0) { status = cf_util_get_port_number (child); if (status > 0) { db->port = status; status = 0; } } else if (strcasecmp ("Socket", child->key) == 0) status = cf_util_get_string (child, &db->socket); else if (strcasecmp ("Database", child->key) == 0) status = cf_util_get_string (child, &db->database); else if (strcasecmp ("MasterStats", child->key) == 0) status = cf_util_get_boolean (child, &db->master_stats); else if (strcasecmp ("SlaveStats", child->key) == 0) status = cf_util_get_boolean (child, &db->slave_stats); else if (strcasecmp ("SlaveNotifications", child->key) == 0) status = cf_util_get_boolean (child, &db->slave_notif); else { WARNING ("mysql plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } /* If all went well, register this database for reading */ if (status == 0) { user_data_t ud; char cb_name[DATA_MAX_NAME_LEN]; DEBUG ("mysql plugin: Registering new read callback: %s", (db->database != NULL) ? db->database : "<default>"); memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = mysql_database_free; if (db->instance != NULL) ssnprintf (cb_name, sizeof (cb_name), "mysql-%s", db->instance); else sstrncpy (cb_name, "mysql", sizeof (cb_name)); plugin_register_complex_read (/* group = */ NULL, cb_name, mysql_read, /* interval = */ NULL, &ud); } else { mysql_database_free (db); return (-1); } return (0); } /* }}} int mysql_config_database */
static int varnish_config_instance (const oconfig_item_t *ci) /* {{{ */ { user_config_t *conf; user_data_t ud; char callback_name[DATA_MAX_NAME_LEN]; int i; conf = malloc (sizeof (*conf)); if (conf == NULL) return (ENOMEM); memset (conf, 0, sizeof (*conf)); conf->instance = NULL; varnish_config_apply_default (conf); if (ci->values_num == 1) { int status; status = cf_util_get_string (ci, &conf->instance); if (status != 0) { sfree (conf); return (status); } assert (conf->instance != NULL); if (strcmp ("localhost", conf->instance) == 0) { sfree (conf->instance); conf->instance = NULL; } } else if (ci->values_num > 1) { WARNING ("Varnish plugin: \"Instance\" blocks accept only " "one argument."); return (EINVAL); } for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("CollectCache", child->key) == 0) cf_util_get_boolean (child, &conf->collect_cache); else if (strcasecmp ("CollectConnections", child->key) == 0) cf_util_get_boolean (child, &conf->collect_connections); else if (strcasecmp ("CollectESI", child->key) == 0) cf_util_get_boolean (child, &conf->collect_esi); #ifdef HAVE_VARNISH_V3 else if (strcasecmp ("CollectDirectorDNS", child->key) == 0) cf_util_get_boolean (child, &conf->collect_dirdns); #endif else if (strcasecmp ("CollectBackend", child->key) == 0) cf_util_get_boolean (child, &conf->collect_backend); else if (strcasecmp ("CollectFetch", child->key) == 0) cf_util_get_boolean (child, &conf->collect_fetch); else if (strcasecmp ("CollectHCB", child->key) == 0) cf_util_get_boolean (child, &conf->collect_hcb); else if (strcasecmp ("CollectObjects", child->key) == 0) cf_util_get_boolean (child, &conf->collect_objects); #if HAVE_VARNISH_V2 else if (strcasecmp ("CollectPurge", child->key) == 0) cf_util_get_boolean (child, &conf->collect_purge); #else else if (strcasecmp ("CollectBan", child->key) == 0) cf_util_get_boolean (child, &conf->collect_ban); #endif else if (strcasecmp ("CollectSession", child->key) == 0) cf_util_get_boolean (child, &conf->collect_session); else if (strcasecmp ("CollectSHM", child->key) == 0) cf_util_get_boolean (child, &conf->collect_shm); else if (strcasecmp ("CollectSMS", child->key) == 0) cf_util_get_boolean (child, &conf->collect_sms); #if HAVE_VARNISH_V2 else if (strcasecmp ("CollectSMA", child->key) == 0) cf_util_get_boolean (child, &conf->collect_sma); else if (strcasecmp ("CollectSM", child->key) == 0) cf_util_get_boolean (child, &conf->collect_sm); #endif else if (strcasecmp ("CollectStruct", child->key) == 0) cf_util_get_boolean (child, &conf->collect_struct); else if (strcasecmp ("CollectTotals", child->key) == 0) cf_util_get_boolean (child, &conf->collect_totals); #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 else if (strcasecmp ("CollectUptime", child->key) == 0) cf_util_get_boolean (child, &conf->collect_uptime); #endif else if (strcasecmp ("CollectVCL", child->key) == 0) cf_util_get_boolean (child, &conf->collect_vcl); else if (strcasecmp ("CollectWorkers", child->key) == 0) cf_util_get_boolean (child, &conf->collect_workers); #if HAVE_VARNISH_V4 else if (strcasecmp ("CollectVSM", child->key) == 0) cf_util_get_boolean (child, &conf->collect_vsm); #endif else { WARNING ("Varnish plugin: Ignoring unknown " "configuration option: \"%s\". Did " "you forget to add an <Instance /> " "block around the configuration?", child->key); } } if (!conf->collect_cache && !conf->collect_connections && !conf->collect_esi && !conf->collect_backend #ifdef HAVE_VARNISH_V3 && !conf->collect_dirdns #endif && !conf->collect_fetch && !conf->collect_hcb && !conf->collect_objects #if HAVE_VARNISH_V2 && !conf->collect_purge #else && !conf->collect_ban #endif && !conf->collect_session && !conf->collect_shm && !conf->collect_sms #if HAVE_VARNISH_V2 && !conf->collect_sma && !conf->collect_sm #endif && !conf->collect_struct && !conf->collect_totals #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4 && !conf->collect_uptime #endif && !conf->collect_vcl && !conf->collect_workers #if HAVE_VARNISH_V4 && !conf->collect_vsm #endif ) { WARNING ("Varnish plugin: No metric has been configured for " "instance \"%s\". Disabling this instance.", (conf->instance == NULL) ? "localhost" : conf->instance); return (EINVAL); } ssnprintf (callback_name, sizeof (callback_name), "varnish/%s", (conf->instance == NULL) ? "localhost" : conf->instance); ud.data = conf; ud.free_func = varnish_config_free; plugin_register_complex_read (/* group = */ "varnish", /* name = */ callback_name, /* callback = */ varnish_read, /* interval = */ 0, /* user data = */ &ud); have_instance = 1; return (0); } /* }}} int varnish_config_instance */
static int wm_config_node (oconfig_item_t *ci) /* {{{ */ { wm_node_t *node; int status; int i; node = malloc (sizeof (*node)); if (node == NULL) return (ENOMEM); memset (node, 0, sizeof (*node)); mongo_init (node->conn); node->host = NULL; node->store_rates = 1; pthread_mutex_init (&node->lock, /* attr = */ NULL); status = cf_util_get_string_buffer (ci, node->name, sizeof (node->name)); if (status != 0) { sfree (node); return (status); } for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &node->host); else if (strcasecmp ("Port", child->key) == 0) { status = cf_util_get_port_number (child); if (status > 0) { node->port = status; status = 0; } } else if (strcasecmp ("Timeout", child->key) == 0) status = cf_util_get_int (child, &node->timeout); else if (strcasecmp ("StoreRates", child->key) == 0) status = cf_util_get_boolean (child, &node->store_rates); else WARNING ("write_mongodb plugin: Ignoring unknown config option \"%s\".", child->key); if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ if (status == 0) { char cb_name[DATA_MAX_NAME_LEN]; user_data_t ud; ssnprintf (cb_name, sizeof (cb_name), "write_mongodb/%s", node->name); ud.data = node; ud.free_func = wm_config_free; status = plugin_register_write (cb_name, wm_write, &ud); INFO ("write_mongodb plugin: registered write plugin %s %d",cb_name,status); } if (status != 0) wm_config_free (node); return (status); } /* }}} int wm_config_node */
/* Configuration handling functiions * <Plugin apache> * <Instance "instance_name"> * URL ... * </Instance> * URL ... * </Plugin> */ static int config_add (oconfig_item_t *ci) { apache_t *st; int i; int status; st = malloc (sizeof (*st)); if (st == NULL) { ERROR ("apache plugin: malloc failed."); return (-1); } memset (st, 0, sizeof (*st)); status = cf_util_get_string (ci, &st->name); 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 = cf_util_get_string (child, &st->url); else if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &st->host); else if (strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &st->user); else if (strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &st->pass); else if (strcasecmp ("VerifyPeer", child->key) == 0) status = cf_util_get_boolean (child, &st->verify_peer); else if (strcasecmp ("VerifyHost", child->key) == 0) status = cf_util_get_boolean (child, &st->verify_host); else if (strcasecmp ("CACert", child->key) == 0) status = cf_util_get_string (child, &st->cacert); else if (strcasecmp ("Server", child->key) == 0) status = cf_util_get_string (child, &st->server); 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 */
static int camqp_config_connection (oconfig_item_t *ci, /* {{{ */ _Bool publish) { camqp_config_t *conf; int status; int i; conf = malloc (sizeof (*conf)); if (conf == NULL) { ERROR ("amqp plugin: malloc failed."); return (ENOMEM); } /* Initialize "conf" {{{ */ memset (conf, 0, sizeof (*conf)); conf->publish = publish; conf->name = NULL; conf->format = CAMQP_FORMAT_COMMAND; conf->host = NULL; conf->port = 5672; conf->vhost = NULL; conf->user = NULL; conf->password = NULL; conf->exchange = NULL; conf->routing_key = NULL; /* publish only */ conf->delivery_mode = CAMQP_DM_VOLATILE; conf->store_rates = 0; /* publish & graphite only */ conf->prefix = NULL; conf->postfix = NULL; conf->escape_char = '_'; /* subscribe only */ conf->exchange_type = NULL; conf->queue = NULL; /* general */ conf->connection = NULL; pthread_mutex_init (&conf->lock, /* attr = */ NULL); /* }}} */ status = cf_util_get_string (ci, &conf->name); if (status != 0) { sfree (conf); return (status); } for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &conf->host); else if (strcasecmp ("Port", child->key) == 0) { status = cf_util_get_port_number (child); if (status > 0) { conf->port = status; status = 0; } } else if (strcasecmp ("VHost", child->key) == 0) status = cf_util_get_string (child, &conf->vhost); else if (strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &conf->user); else if (strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &conf->password); else if (strcasecmp ("Exchange", child->key) == 0) status = cf_util_get_string (child, &conf->exchange); else if ((strcasecmp ("ExchangeType", child->key) == 0) && !publish) status = cf_util_get_string (child, &conf->exchange_type); else if ((strcasecmp ("Queue", child->key) == 0) && !publish) status = cf_util_get_string (child, &conf->queue); else if (strcasecmp ("RoutingKey", child->key) == 0) status = cf_util_get_string (child, &conf->routing_key); else if ((strcasecmp ("Persistent", child->key) == 0) && publish) { _Bool tmp = 0; status = cf_util_get_boolean (child, &tmp); if (tmp) conf->delivery_mode = CAMQP_DM_PERSISTENT; else conf->delivery_mode = CAMQP_DM_VOLATILE; } else if ((strcasecmp ("StoreRates", child->key) == 0) && publish) status = cf_util_get_boolean (child, &conf->store_rates); else if ((strcasecmp ("Format", child->key) == 0) && publish) status = camqp_config_set_format (child, conf); else if ((strcasecmp ("GraphitePrefix", child->key) == 0) && publish) status = cf_util_get_string (child, &conf->prefix); else if ((strcasecmp ("GraphitePostfix", child->key) == 0) && publish) status = cf_util_get_string (child, &conf->postfix); else if ((strcasecmp ("GraphiteEscapeChar", child->key) == 0) && publish) { char *tmp_buff = NULL; status = cf_util_get_string (child, &tmp_buff); if (strlen (tmp_buff) > 1) WARNING ("amqp plugin: The option \"GraphiteEscapeChar\" handles " "only one character. Others will be ignored."); conf->escape_char = tmp_buff[0]; sfree (tmp_buff); } else WARNING ("amqp plugin: Ignoring unknown " "configuration option \"%s\".", child->key); if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ if ((status == 0) && (conf->exchange == NULL)) { if (conf->exchange_type != NULL) WARNING ("amqp plugin: The option \"ExchangeType\" was given " "without the \"Exchange\" option. It will be ignored."); if (!publish && (conf->routing_key != NULL)) WARNING ("amqp plugin: The option \"RoutingKey\" was given " "without the \"Exchange\" option. It will be ignored."); } if (status != 0) { camqp_config_free (conf); return (status); } if (conf->exchange != NULL) { DEBUG ("amqp plugin: camqp_config_connection: exchange = %s;", conf->exchange); } if (publish) { char cbname[128]; user_data_t ud = { conf, camqp_config_free }; ssnprintf (cbname, sizeof (cbname), "amqp/%s", conf->name); status = plugin_register_write (cbname, camqp_write, &ud); if (status != 0) { camqp_config_free (conf); return (status); } } else { status = camqp_subscribe_init (conf); if (status != 0) { camqp_config_free (conf); return (status); } } return (0); } /* }}} int camqp_config_connection */
static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */ { if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("curl_xml plugin: The `URL' block " "needs exactly one string argument."); return -1; } cx_t *db = calloc(1, sizeof(*db)); if (db == NULL) { ERROR("curl_xml plugin: calloc failed."); return -1; } db->instance = strdup("default"); if (db->instance == NULL) { ERROR("curl_xml plugin: strdup failed."); sfree(db); return -1; } db->xpath_list = llist_create(); if (db->xpath_list == NULL) { ERROR("curl_xml plugin: list creation failed."); sfree(db->instance); sfree(db); return -1; } db->timeout = -1; int status = cf_util_get_string(ci, &db->url); if (status != 0) { llist_destroy(db->xpath_list); sfree(db->instance); sfree(db); return status; } /* Fill the `cx_t' structure.. */ for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Instance", child->key) == 0) status = cf_util_get_string(child, &db->instance); else if (strcasecmp("Plugin", child->key) == 0) status = cf_util_get_string(child, &db->plugin_name); else if (strcasecmp("Host", child->key) == 0) status = cf_util_get_string(child, &db->host); else if (strcasecmp("User", child->key) == 0) status = cf_util_get_string(child, &db->user); else if (strcasecmp("Password", child->key) == 0) status = cf_util_get_string(child, &db->pass); else if (strcasecmp("Digest", child->key) == 0) status = cf_util_get_boolean(child, &db->digest); else if (strcasecmp("VerifyPeer", child->key) == 0) status = cf_util_get_boolean(child, &db->verify_peer); else if (strcasecmp("VerifyHost", child->key) == 0) status = cf_util_get_boolean(child, &db->verify_host); else if (strcasecmp("CACert", child->key) == 0) status = cf_util_get_string(child, &db->cacert); else if (strcasecmp("xpath", child->key) == 0) status = cx_config_add_xpath(db, child); else if (strcasecmp("Header", child->key) == 0) status = cx_config_append_string("Header", &db->headers, child); else if (strcasecmp("Post", child->key) == 0) status = cf_util_get_string(child, &db->post_body); else if (strcasecmp("Namespace", child->key) == 0) status = cx_config_add_namespace(db, child); else if (strcasecmp("Timeout", child->key) == 0) status = cf_util_get_int(child, &db->timeout); else if (strcasecmp("Statistics", child->key) == 0) { db->stats = curl_stats_from_config(child); if (db->stats == NULL) status = -1; } else { WARNING("curl_xml plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } if (status != 0) { cx_free(db); return status; } if (llist_size(db->xpath_list) == 0) { WARNING("curl_xml plugin: No `xpath' block within `URL' block `%s'.", db->url); cx_free(db); return -1; } if (cx_init_curl(db) != 0) { cx_free(db); return -1; } /* If all went well, register this database for reading */ DEBUG("curl_xml plugin: Registering new read callback: %s", db->instance); char *cb_name = ssnprintf_alloc("curl_xml-%s-%s", db->instance, db->url); plugin_register_complex_read(/* group = */ "curl_xml", cb_name, cx_read, /* interval = */ 0, &(user_data_t){ .data = db, .free_func = cx_free, });
static int wr_config_node (oconfig_item_t *ci) /* {{{ */ { wr_node_t *node; int timeout; int status; int i; node = calloc (1, sizeof (*node)); if (node == NULL) return (ENOMEM); node->host = NULL; node->port = 0; node->timeout.tv_sec = 0; node->timeout.tv_usec = 1000; node->conn = NULL; node->prefix = NULL; node->database = 0; node->max_set_size = -1; node->store_rates = 1; pthread_mutex_init (&node->lock, /* attr = */ NULL); status = cf_util_get_string_buffer (ci, node->name, sizeof (node->name)); if (status != 0) { sfree (node); return (status); } for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &node->host); else if (strcasecmp ("Port", child->key) == 0) { status = cf_util_get_port_number (child); if (status > 0) { node->port = status; status = 0; } } else if (strcasecmp ("Timeout", child->key) == 0) { status = cf_util_get_int (child, &timeout); if (status == 0) node->timeout.tv_usec = timeout; } else if (strcasecmp ("Prefix", child->key) == 0) { status = cf_util_get_string (child, &node->prefix); } else if (strcasecmp ("Database", child->key) == 0) { status = cf_util_get_int (child, &node->database); } else if (strcasecmp ("MaxSetSize", child->key) == 0) { status = cf_util_get_int (child, &node->max_set_size); } else if (strcasecmp ("StoreRates", child->key) == 0) { status = cf_util_get_boolean (child, &node->store_rates); } else WARNING ("write_redis plugin: Ignoring unknown config option \"%s\".", child->key); if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ if (status == 0) { char cb_name[DATA_MAX_NAME_LEN]; user_data_t ud; ssnprintf (cb_name, sizeof (cb_name), "write_redis/%s", node->name); ud.data = node; ud.free_func = wr_config_free; status = plugin_register_write (cb_name, wr_write, &ud); } if (status != 0) wr_config_free (node); return (status); } /* }}} int wr_config_node */
static int camqp_config_connection(oconfig_item_t *ci, /* {{{ */ bool publish) { camqp_config_t *conf; int status; conf = calloc(1, sizeof(*conf)); if (conf == NULL) { ERROR("amqp plugin: calloc failed."); return ENOMEM; } /* Initialize "conf" {{{ */ conf->publish = publish; conf->name = NULL; conf->format = CAMQP_FORMAT_COMMAND; conf->host = NULL; conf->port = 5672; conf->vhost = NULL; conf->user = NULL; conf->password = NULL; conf->exchange = NULL; conf->routing_key = NULL; conf->connection_retry_delay = 0; /* publish only */ conf->delivery_mode = CAMQP_DM_VOLATILE; conf->store_rates = false; conf->graphite_flags = 0; /* publish & graphite only */ conf->prefix = NULL; conf->postfix = NULL; conf->escape_char = '_'; /* subscribe only */ conf->exchange_type = NULL; conf->queue = NULL; conf->queue_durable = false; conf->queue_auto_delete = true; /* general */ conf->connection = NULL; pthread_mutex_init(&conf->lock, /* attr = */ NULL); /* }}} */ status = cf_util_get_string(ci, &conf->name); if (status != 0) { sfree(conf); return status; } for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Host", child->key) == 0) status = cf_util_get_string(child, &conf->host); else if (strcasecmp("Port", child->key) == 0) { status = cf_util_get_port_number(child); if (status > 0) { conf->port = status; status = 0; } } else if (strcasecmp("VHost", child->key) == 0) status = cf_util_get_string(child, &conf->vhost); else if (strcasecmp("User", child->key) == 0) status = cf_util_get_string(child, &conf->user); else if (strcasecmp("Password", child->key) == 0) status = cf_util_get_string(child, &conf->password); else if (strcasecmp("Exchange", child->key) == 0) status = cf_util_get_string(child, &conf->exchange); else if (strcasecmp("ExchangeType", child->key) == 0) status = cf_util_get_string(child, &conf->exchange_type); else if ((strcasecmp("Queue", child->key) == 0) && !publish) status = cf_util_get_string(child, &conf->queue); else if ((strcasecmp("QueueDurable", child->key) == 0) && !publish) status = cf_util_get_boolean(child, &conf->queue_durable); else if ((strcasecmp("QueueAutoDelete", child->key) == 0) && !publish) status = cf_util_get_boolean(child, &conf->queue_auto_delete); else if (strcasecmp("RoutingKey", child->key) == 0) status = cf_util_get_string(child, &conf->routing_key); else if ((strcasecmp("Persistent", child->key) == 0) && publish) { bool tmp = 0; status = cf_util_get_boolean(child, &tmp); if (tmp) conf->delivery_mode = CAMQP_DM_PERSISTENT; else conf->delivery_mode = CAMQP_DM_VOLATILE; } else if ((strcasecmp("StoreRates", child->key) == 0) && publish) { status = cf_util_get_boolean(child, &conf->store_rates); (void)cf_util_get_flag(child, &conf->graphite_flags, GRAPHITE_STORE_RATES); } else if ((strcasecmp("Format", child->key) == 0) && publish) status = camqp_config_set_format(child, conf); else if ((strcasecmp("GraphiteSeparateInstances", child->key) == 0) && publish) status = cf_util_get_flag(child, &conf->graphite_flags, GRAPHITE_SEPARATE_INSTANCES); else if ((strcasecmp("GraphiteAlwaysAppendDS", child->key) == 0) && publish) status = cf_util_get_flag(child, &conf->graphite_flags, GRAPHITE_ALWAYS_APPEND_DS); else if ((strcasecmp("GraphitePreserveSeparator", child->key) == 0) && publish) status = cf_util_get_flag(child, &conf->graphite_flags, GRAPHITE_PRESERVE_SEPARATOR); else if ((strcasecmp("GraphitePrefix", child->key) == 0) && publish) status = cf_util_get_string(child, &conf->prefix); else if ((strcasecmp("GraphitePostfix", child->key) == 0) && publish) status = cf_util_get_string(child, &conf->postfix); else if ((strcasecmp("GraphiteEscapeChar", child->key) == 0) && publish) { char *tmp_buff = NULL; status = cf_util_get_string(child, &tmp_buff); if (strlen(tmp_buff) > 1) WARNING("amqp plugin: The option \"GraphiteEscapeChar\" handles " "only one character. Others will be ignored."); conf->escape_char = tmp_buff[0]; sfree(tmp_buff); } else if (strcasecmp("ConnectionRetryDelay", child->key) == 0) status = cf_util_get_int(child, &conf->connection_retry_delay); else WARNING("amqp plugin: Ignoring unknown " "configuration option \"%s\".", child->key); if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ if ((status == 0) && (conf->exchange == NULL)) { if (conf->exchange_type != NULL) WARNING("amqp plugin: The option \"ExchangeType\" was given " "without the \"Exchange\" option. It will be ignored."); if (!publish && (conf->routing_key != NULL)) WARNING("amqp plugin: The option \"RoutingKey\" was given " "without the \"Exchange\" option. It will be ignored."); } if (status != 0) { camqp_config_free(conf); return status; } if (conf->exchange != NULL) { DEBUG("amqp plugin: camqp_config_connection: exchange = %s;", conf->exchange); } if (publish) { char cbname[128]; snprintf(cbname, sizeof(cbname), "amqp/%s", conf->name); status = plugin_register_write(cbname, camqp_write, &(user_data_t){ .data = conf, .free_func = camqp_config_free, }); if (status != 0) { camqp_config_free(conf); return status; } } else {