=head2 Plugin C<ovs_events>
The I<ovs_events> plugin monitors the link status of OVS connected interfaces,
-dispatches the values to collectd and send the notification whenever the link
+dispatches the values to collectd and sends the notification whenever the link
state change occurs. This plugin uses OVS DB to get a link state change
notification.
=item B<Address> I<node>
-The address of OVS DB server JSON-RPC interface used by the plugin. To enable
-the interface, OVS DB daemon should be running with '--remote=ptcp:' option.
-See L<ovsdb-server(1)> for more details. The option may be either network
-hostname, IPv4 numbers-and-dots notation or IPv6 hexadecimal string format.
-Defaults to 'localhost'.
+The address of the OVS DB server JSON-RPC interface used by the plugin. To
+enable the interface, OVS DB daemon should be running with '--remote=ptcp:'
+option. See L<ovsdb-server(1)> for more details. The option may be either
+network hostname, IPv4 numbers-and-dots notation or IPv6 hexadecimal string
+format. Defaults to 'localhost'.
=item B<Port> I<service>
=item B<Interfaces> [I<ifname> ...]
-List of interface names to be monitored by this plugin. If this option is missed
-or it's empty then all OVS connected interfaces on all bridges are monitored.
+List of interface names to be monitored by this plugin. If this option is not
+specified or is empty then all OVS connected interfaces on all bridges are
+monitored.
Default: empty (all interfaces on all bridges are monitored)
*/
static ovs_events_ctx_t ovs_events_ctx = {
.mutex = PTHREAD_MUTEX_INITIALIZER,
- .config = {.send_notification = 0, /* do not send notification */
- .ovs_db_node = "localhost", /* use default OVS DB node */
- .ovs_db_serv = "6640", /* use default OVS DB service */
- .ovs_db_unix = "", /* UNIX path empty by default */
- .ifaces = NULL},
- .ovs_db_select_params = NULL,
- .is_db_available = 0,
- .ovs_db = NULL};
+ .config = {.ovs_db_node = "localhost", /* use default OVS DB node */
+ .ovs_db_serv = "6640"} /* use default OVS DB service */
+};
/* This function is used only by "OVS_EVENTS_CTX_LOCK" define (see above).
* It always returns 1 when context is locked.
* "Transact" & "Select" section
*/
static char *ovs_events_get_select_params() {
- int ret = 0;
size_t buff_size = 0;
size_t buff_off = 0;
char *opt_buff = NULL;
- const char params_fmt[] = "[\"Open_vSwitch\"%s]";
- const char option_fmt[] = ",{\"op\":\"select\",\"table\":\"Interface\","
- "\"where\":[[\"name\",\"==\",\"%s\"]],"
- "\"columns\":[\"link_state\",\"external_ids\","
- "\"name\",\"_uuid\"]}";
- const char default_opt[] = ",{\"op\":\"select\",\"table\":\"Interface\","
- "\"where\":[],\"columns\":[\"link_state\","
- "\"external_ids\",\"name\",\"_uuid\"]}";
+ static const char params_fmt[] = "[\"Open_vSwitch\"%s]";
+ static const char option_fmt[] =
+ ",{\"op\":\"select\",\"table\":\"Interface\","
+ "\"where\":[[\"name\",\"==\",\"%s\"]],"
+ "\"columns\":[\"link_state\",\"external_ids\","
+ "\"name\",\"_uuid\"]}";
+ static const char default_opt[] =
+ ",{\"op\":\"select\",\"table\":\"Interface\","
+ "\"where\":[],\"columns\":[\"link_state\","
+ "\"external_ids\",\"name\",\"_uuid\"]}";
/* setup OVS DB interface condition */
for (ovs_events_iface_list_t *iface = ovs_events_ctx.config.ifaces; iface;
- iface = iface->next, buff_off += ret) {
+ iface = iface->next) {
/* allocate new buffer (format size + ifname len is good enough) */
- buff_size += (sizeof(option_fmt) + strlen(iface->name));
+ buff_size += sizeof(option_fmt) + strlen(iface->name);
char *new_buff = realloc(opt_buff, buff_size);
if (new_buff == NULL) {
sfree(opt_buff);
return NULL;
}
opt_buff = new_buff;
- ret = ssnprintf(opt_buff + buff_off, buff_size - buff_off, option_fmt,
- iface->name);
+ int ret = ssnprintf(opt_buff + buff_off, buff_size - buff_off, option_fmt,
+ iface->name);
if (ret < 0) {
sfree(opt_buff);
return NULL;
}
+ buff_off += ret;
}
/* if no interfaces are configured, use default params */
if (opt_buff == NULL)
- opt_buff = strdup(default_opt);
+ if ((opt_buff = strdup(default_opt)) == NULL)
+ return NULL;
/* allocate memory for OVS DB select params */
size_t params_size = sizeof(params_fmt) + strlen(opt_buff);
}
/* Dispatch OVS interface link status event to collectd */
-static void
-ovs_events_dispatch_notification(const ovs_events_iface_info_t *ifinfo) {
+static void ovs_events_dispatch_notification(const ovs_events_iface_info_t *ifinfo) {
const char *msg_link_status = NULL;
notification_t n = {
NOTIF_FAILURE, cdtime(), "", "", OVS_EVENTS_PLUGIN, "", "", "", NULL};
}
/* Dispatch OVS interface link status value to collectd */
-static void
-ovs_events_link_status_submit(const ovs_events_iface_info_t *ifinfo) {
+static void ovs_events_link_status_submit(const ovs_events_iface_info_t *ifinfo) {
value_list_t vl = VALUE_LIST_INIT;
meta_data_t *meta = NULL;
* to receive link status event(s).
*/
static void ovs_events_conn_initialize(ovs_db_t *pdb) {
- int ret = 0;
const char tb_name[] = "Interface";
const char *columns[] = {"_uuid", "external_ids", "name", "link_state", NULL};
/* register update link status event if needed */
if (ovs_events_ctx.config.send_notification) {
- ret = ovs_db_table_cb_register(pdb, tb_name, columns,
- ovs_events_table_update_cb, NULL,
- OVS_DB_TABLE_CB_FLAG_MODIFY);
+ int ret = ovs_db_table_cb_register(pdb, tb_name, columns,
+ ovs_events_table_update_cb, NULL,
+ OVS_DB_TABLE_CB_FLAG_MODIFY);
if (ret < 0) {
ERROR(OVS_EVENTS_PLUGIN ": register OVS DB update callback failed");
return;