From: Florian Forster Date: Wed, 20 Feb 2013 08:31:12 +0000 (+0100) Subject: snort plugin: Assert that the configured "type" has only one data source. X-Git-Tag: collectd-5.3.0~26^2~10 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b4d7785d1c3d8ee532a8e955cf534801fa1093c2;p=collectd.git snort plugin: Assert that the configured "type" has only one data source. Also uses the utility function from configfile.h to read the metric definition's name. --- diff --git a/src/snort.c b/src/snort.c index 20825822..bf804f70 100644 --- a/src/snort.c +++ b/src/snort.c @@ -257,19 +257,15 @@ static int snort_config_add_metric(oconfig_item_t *ci){ int status = 0; int i; - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)){ - WARNING("snort plugin: The `Metric' config option needs exactly one string argument."); - return (-1); - } - md = (metric_definition_t *)malloc(sizeof(*md)); if (md == NULL) return (-1); memset(md, 0, sizeof(*md)); - md->name = strdup(ci->values[0].value.string); - if (md->name == NULL){ - free(md); + md->name = NULL; + status = cf_util_get_string (ci, &md->name); + if (status != 0) { + sfree (md); return (-1); } @@ -312,9 +308,17 @@ static int snort_config_add_metric(oconfig_item_t *ci){ /* Retrieve the data source type from the types db. */ ds = plugin_get_ds(md->type); if (ds == NULL){ - WARNING("snort plugin: `Type' must be defined in `types.db'."); + ERROR ("snort plugin: Failed to look up type \"%s\". " + "It may not be defined in the types.db file. " + "Please read the types.db(5) manual page for more details.", + md->type); snort_metric_definition_destroy(md); return (-1); + } else if (ds->ds_num != 1) { + ERROR ("snort plugin: The type \"%s\" has %i data sources. " + "Only types with a single data soure are supported.", + ds->type, ds->ds_num); + return (-1); } else { md->data_source_type = ds->ds->type; }