X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fovs_events.c;h=8c2cd12cb296f8ac3fc22ada9a6b2b8d266b0f9e;hb=64b8150edec2271bb110f36e70915fdd87d9cac2;hp=20af0c26893678c0f0f77425e09b36eb048f8218;hpb=bc40bd520a41f8b4b61ba1b2a629d01c768d0c6f;p=collectd.git diff --git a/src/ovs_events.c b/src/ovs_events.c index 20af0c26..8c2cd12c 100644 --- a/src/ovs_events.c +++ b/src/ovs_events.c @@ -90,6 +90,9 @@ static ovs_events_ctx_t ovs_events_ctx = { .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 +227,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 = 1; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("SendNotification", child->key) == 0) { @@ -260,12 +264,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); } @@ -465,7 +485,7 @@ static void ovs_events_table_update_cb(yajl_val jupdates) { return; } /* go through all row updates */ - for (int row_index = 0; row_index < YAJL_GET_OBJECT(jupdate)->len; + for (size_t row_index = 0; row_index < YAJL_GET_OBJECT(jupdate)->len; ++row_index) { jrow_update = YAJL_GET_OBJECT(jupdate)->values[row_index]; @@ -512,14 +532,14 @@ static void ovs_events_poll_result_cb(yajl_val jresult, yajl_val jerror) { /* go through all rows and get interface info */ jvalues = YAJL_GET_ARRAY(jresult)->values; - for (int i = 0; i < YAJL_GET_ARRAY(jresult)->len; i++) { + for (size_t i = 0; i < YAJL_GET_ARRAY(jresult)->len; i++) { jvalue = ovs_utils_get_value_by_key(jvalues[i], "rows"); if (jvalue == NULL || !YAJL_IS_ARRAY(jvalue)) { ERROR(OVS_EVENTS_PLUGIN "invalid data (array of rows is expected)"); return; } /* get interfaces info */ - for (int j = 0; j < YAJL_GET_ARRAY(jvalue)->len; j++) { + for (size_t j = 0; j < YAJL_GET_ARRAY(jvalue)->len; j++) { if (ovs_events_get_iface_info(YAJL_GET_ARRAY(jvalue)->values[j], &ifinfo) < 0) { ERROR(OVS_EVENTS_PLUGIN @@ -633,7 +653,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); }