X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fovs_events.c;h=d372b87ab2b9e0ff023b3e07abd1d3f18feaae7a;hb=1d429f78567323c11f00e9f6e5ea1765e7c5c8c7;hp=c77bde4a436eb3a079321f78541c33a3ce3f3bab;hpb=f1a8429a57361b11d7c4faca5f78dd12831f9377;p=collectd.git diff --git a/src/ovs_events.c b/src/ovs_events.c index c77bde4a..d372b87a 100644 --- a/src/ovs_events.c +++ b/src/ovs_events.c @@ -86,10 +86,14 @@ typedef struct ovs_events_ctx_s ovs_events_ctx_t; */ static ovs_events_ctx_t ovs_events_ctx = { .mutex = PTHREAD_MUTEX_INITIALIZER, - .config = {.ovs_db_node = "localhost", /* use default OVS DB node */ + .config = {.send_notification = 1, /* send notification by default */ + .ovs_db_node = "localhost", /* use default OVS DB node */ .ovs_db_serv = "6640"} /* use default OVS DB service */ }; +/* Forward declaration */ +static int ovs_events_plugin_read(user_data_t *u); + /* This function is used only by "OVS_EVENTS_CTX_LOCK" define (see above). * It always returns 1 when context is locked. */ @@ -224,6 +228,7 @@ static int ovs_events_config_get_interfaces(const oconfig_item_t *ci) { * in allocated memory. Returns negative value in case of error. */ static int ovs_events_plugin_config(oconfig_item_t *ci) { + _Bool dispatch_values = 0; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("SendNotification", child->key) == 0) { @@ -260,12 +265,28 @@ static int ovs_events_plugin_config(oconfig_item_t *ci) { ovs_events_config_free(); return (-1); } + } else if (strcasecmp("DispatchValues", child->key) == 0) { + if (cf_util_get_boolean(child, &dispatch_values) != 0) { + ovs_events_config_free(); + return (-1); + } } else { ERROR(OVS_EVENTS_PLUGIN ": option '%s' is not allowed here", child->key); ovs_events_config_free(); return (-1); } } + /* Check and warn about invalid configuration */ + if (!ovs_events_ctx.config.send_notification && !dispatch_values) { + WARNING(OVS_EVENTS_PLUGIN ": send notification and dispatch values " + "options are disabled. No information will be dispatched by the " + "plugin. Please check your configuration"); + } + /* Dispatch link status values if configured */ + if (dispatch_values) + return plugin_register_complex_read(NULL, OVS_EVENTS_PLUGIN, + ovs_events_plugin_read, 0, NULL); + return (0); } @@ -633,7 +654,5 @@ static int ovs_events_plugin_shutdown(void) { void module_register(void) { plugin_register_complex_config(OVS_EVENTS_PLUGIN, ovs_events_plugin_config); plugin_register_init(OVS_EVENTS_PLUGIN, ovs_events_plugin_init); - plugin_register_complex_read(NULL, OVS_EVENTS_PLUGIN, ovs_events_plugin_read, - 0, NULL); plugin_register_shutdown(OVS_EVENTS_PLUGIN, ovs_events_plugin_shutdown); }