X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fpowerdns.c;h=3e7ebb339b6a044eb2bca7e64cc38d5127aa74c4;hb=79c87aeda9172e219a842e393c6499c8bf37662a;hp=b451073ff351b9c4831949c93d2ac1e70838e88a;hpb=7471e073bff7c9f2542bc1c8ce639b85c5498ba7;p=collectd.git diff --git a/src/powerdns.c b/src/powerdns.c index b451073f..3e7ebb33 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -45,10 +45,10 @@ #endif #define FUNC_ERROR(func) do { char errbuf[1024]; ERROR ("powerdns plugin: %s failed: %s", func, sstrerror (errno, errbuf, sizeof (errbuf))); } while (0) -#define SERVER_SOCKET "/var/run/pdns.controlsocket" +#define SERVER_SOCKET LOCALSTATEDIR"/run/pdns.controlsocket" #define SERVER_COMMAND "SHOW *" -#define RECURSOR_SOCKET "/var/run/pdns_recursor.controlsocket" +#define RECURSOR_SOCKET LOCALSTATEDIR"/run/pdns_recursor.controlsocket" #define RECURSOR_COMMAND "get noerror-answers nxdomain-answers " \ "servfail-answers sys-msec user-msec qa-latency cache-entries cache-hits " \ "cache-misses questions" @@ -164,13 +164,13 @@ statname_lookup_t lookup_table[] = /* {{{ */ {"latency", "latency", NULL}, /* Other stuff.. */ - {"corrupt-packets", "io_packets", "corrupt"}, + {"corrupt-packets", "ipt_packets", "corrupt"}, {"deferred-cache-inserts", "counter", "cache-deferred_insert"}, {"deferred-cache-lookup", "counter", "cache-deferred_lookup"}, {"qsize-a", "cache_size", "answers"}, {"qsize-q", "cache_size", "questions"}, - {"servfail-packets", "io_packets", "servfail"}, - {"timedout-packets", "io_packets", "timeout"}, + {"servfail-packets", "ipt_packets", "servfail"}, + {"timedout-packets", "ipt_packets", "timeout"}, {"udp4-answers", "dns_answer", "udp4"}, {"udp4-queries", "dns_question", "queries-udp4"}, {"udp6-answers", "dns_answer", "udp6"}, @@ -289,35 +289,15 @@ static void submit (const char *plugin_instance, /* {{{ */ return; } - if (ds->ds[0].type == DS_TYPE_GAUGE) + if (0 != parse_value (value, &values[0], ds->ds[0].type)) { - char *endptr = NULL; - - values[0].gauge = strtod (value, &endptr); - - if (endptr == value) - { - ERROR ("powerdns plugin: Cannot convert `%s' " - "to a floating point number.", value); - return; - } - } - else - { - char *endptr = NULL; - - values[0].counter = strtoll (value, &endptr, 0); - if (endptr == value) - { - ERROR ("powerdns plugin: Cannot convert `%s' " - "to an integer number.", value); - return; - } + ERROR ("powerdns plugin: Cannot convert `%s' " + "to a number.", value); + return; } vl.values = values; vl.values_len = 1; - vl.time = time (NULL); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "powerdns", sizeof (vl.plugin)); sstrncpy (vl.type, type, sizeof (vl.type)); @@ -381,6 +361,18 @@ static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */ break; } + struct timeval timeout; + timeout.tv_sec=2; + if (timeout.tv_sec < interval_g * 3 / 4) + timeout.tv_sec = interval_g * 3 / 4; + timeout.tv_usec=0; + status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof (timeout)); + if (status != 0) + { + FUNC_ERROR ("setsockopt"); + break; + } + status = connect (sd, (struct sockaddr *) &item->sockaddr, sizeof (item->sockaddr)); if (status != 0) @@ -912,11 +904,18 @@ static int powerdns_config (oconfig_item_t *ci) /* {{{ */ powerdns_config_add_server (option); else if (strcasecmp ("LocalSocket", option->key) == 0) { - char *temp = strdup (option->key); - if (temp == NULL) - return (1); - sfree (local_sockpath); - local_sockpath = temp; + if ((option->values_num != 1) || (option->values[0].type != OCONFIG_TYPE_STRING)) + { + WARNING ("powerdns plugin: `%s' needs exactly one string argument.", option->key); + } + else + { + char *temp = strdup (option->values[0].value.string); + if (temp == NULL) + return (1); + sfree (local_sockpath); + local_sockpath = temp; + } } else {