write_riemann: Add support for timeouts
authorGergely Nagy <algernon@madhouse-project.org>
Thu, 7 Apr 2016 06:59:08 +0000 (08:59 +0200)
committerGergely Nagy <algernon@madhouse-project.org>
Thu, 7 Apr 2016 06:59:08 +0000 (08:59 +0200)
Bump the riemann-c-client requirement to 1.8.0, which introduces
riemann_client_set_timeout(). With this in place, the plugin can now
accept the "Timeout" option, which specifies a timeout in seconds, for
all blocking operations (except TLS handshake).

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
configure.ac
src/write_riemann.c

index 09afe11..9cc9b55 100644 (file)
@@ -5231,7 +5231,7 @@ PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
                [with_libnotify="no (pkg-config doesn't know libnotify)"]
 )
 
-PKG_CHECK_MODULES([RIEMANN_C], [riemann-client >= 1.6.0],
+PKG_CHECK_MODULES([RIEMANN_C], [riemann-client >= 1.8.0],
  [with_riemann_c="yes"],
  [with_riemann_c="no (pbg-config doesn't know riemann-c-client)"])
 
index 3429976..2b68e88 100644 (file)
@@ -65,6 +65,7 @@ struct riemann_host {
        char                     *tls_ca_file;
        char                     *tls_cert_file;
        char                     *tls_key_file;
+       struct timeval timeout;
 };
 
 static char    **riemann_tags;
@@ -96,6 +97,15 @@ static int wrr_connect(struct riemann_host *host) /* {{{ */
                        node, port);
                return -1;
        }
+       if (host->timeout.tv_sec != 0) {
+               if (riemann_client_set_timeout(host->client, &host->timeout) != 0) {
+                       riemann_client_free(host->client);
+                       host->client = NULL;
+                       WARNING("write_riemann plugin: Unable to connect to Riemann at %s:%d",
+                               node, port);
+                       return -1;
+               }
+       }
        DEBUG("write_riemann plugin: got a successful connection for: %s:%d",
              node, port);
 
@@ -639,6 +649,8 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */
   host->ttl_factor = RIEMANN_TTL_FACTOR;
   host->client = NULL;
   host->client_type = RIEMANN_CLIENT_TCP;
+  host->timeout.tv_sec = 0;
+  host->timeout.tv_usec = 0;
 
   status = cf_util_get_string(ci, &host->name);
   if (status != 0) {
@@ -679,6 +691,10 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */
       status = cf_util_get_int(child, &host->batch_max);
       if (status != 0)
         break;
+    } else if (strcasecmp("Timeout", child->key) == 0) {
+      status = cf_util_get_int(child, (int *)&host->timeout.tv_sec);
+      if (status != 0)
+        break;
     } else if (strcasecmp("Port", child->key) == 0) {
       host->port = cf_util_get_port_number(child);
       if (host->port == -1) {