Example #1
0
static int c_psql_config (oconfig_item_t *ci)
{
	static int have_def_config = 0;

	int i;

	if (0 == have_def_config) {
		oconfig_item_t *c;

		have_def_config = 1;

		c = oconfig_parse_file (C_PSQL_DEFAULT_CONF);
		if (NULL == c)
			log_err ("Failed to read default config ("C_PSQL_DEFAULT_CONF").");
		else
			c_psql_config (c);

		if (NULL == queries)
			log_err ("Default config ("C_PSQL_DEFAULT_CONF") did not define "
					"any queries - please check your installation.");
	}

	for (i = 0; i < ci->children_num; ++i) {
		oconfig_item_t *c = ci->children + i;

		if (0 == strcasecmp (c->key, "Query"))
			udb_query_create (&queries, &queries_num, c,
					/* callback = */ config_query_callback);
		else if (0 == strcasecmp (c->key, "Database"))
			c_psql_config_database (c);
		else
			log_warn ("Ignoring unknown config key \"%s\".", c->key);
	}
	return 0;
} /* c_psql_config */
static int
basic_aggregator_read_config_file_and_update_aggregator_definitions(char *filename) {
		oconfig_item_t *ci;
		int status = 0;
		int i;
		int nb_aggregators = 0;
		char *k;
		aggregator_definition_t *agg;

		ci = oconfig_parse_file (filename);
		if(NULL == ci) {
				WARNING (OUTPUT_PREFIX_STRING "Failed to read default config ('%s').", filename);
				return(-1);
		}

		/* Free the aggregator tree : it will be reconfigured from scratch from the file */
		if(NULL != aggregator) {
				while (c_avl_pick (aggregator, (void *)&k, (void *)&agg) == 0) {
						aggregator_definition_free(agg,1);
				}
				c_avl_destroy (aggregator);
		}
		aggregator = c_avl_create((void *) strcmp);
		if(NULL == aggregator) return (-1);

		/* Parse the configuration file */
		for (i = 0; i < ci->children_num; i++)
		{
				oconfig_item_t *child = ci->children + i;

				if (strcasecmp ("aggregator", child->key) == 0) {
						agg = basic_aggregator_config_aggregator (child);
						if(agg) {
								int r;
								r = c_avl_insert(aggregator, agg->resultvalue, agg);
								if(r != 0) {
										ERROR (OUTPUT_PREFIX_STRING "Could not insert aggregator '%s' in the list of aggregators (duplicate ?)",  agg->resultvalue);
										aggregator_definition_free(agg,1);
								} else {
										nb_aggregators++;
								}
						}
				} else if (strcasecmp ("database", child->key) == 0) {
						if ((child->values_num < 1) || (child->values[0].type != OCONFIG_TYPE_STRING)) {
								WARNING (OUTPUT_PREFIX_STRING "`database' needs 1 string arguments.");
								status = -1;
						} else {
								if (strcasecmp ("mysql", child->values[0].value.string) == 0) {
										/* Not implemented yet
										   basic_aggregator_config_mysql_database (child);
										   */
								} else if (strcasecmp ("postgresql", child->values[0].value.string) == 0) {

										/* Not supported yet */
								} else {
										WARNING (OUTPUT_PREFIX_STRING "'%s' is not a known type for `database'.", ci->values[0].value.string);
										status = -1;
								}
						}
				} else
						WARNING (OUTPUT_PREFIX_STRING "Option \"%s\" not allowed here.",
										child->key);
		}

		INFO(OUTPUT_PREFIX_STRING "Registered %d aggregators", nb_aggregators);
		return(status);
}