projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
write_prometheus: add support for libmicrohttpd 0.9.45+
[collectd.git]
/
src
/
powerdns.c
diff --git
a/src/powerdns.c
b/src/powerdns.c
index
1050e7f
..
b5d4a32
100644
(file)
--- a/
src/powerdns.c
+++ b/
src/powerdns.c
@@
-25,9
+25,9
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_llist.h"
#include <sys/stat.h>
#include "utils_llist.h"
#include <sys/stat.h>
@@
-43,6
+43,7
@@
# define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
#endif
#define FUNC_ERROR(func) do { char errbuf[1024]; ERROR ("powerdns plugin: %s failed: %s", func, sstrerror (errno, errbuf, sizeof (errbuf))); } while (0)
# define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
#endif
#define FUNC_ERROR(func) do { char errbuf[1024]; ERROR ("powerdns plugin: %s failed: %s", func, sstrerror (errno, errbuf, sizeof (errbuf))); } while (0)
+#define SOCK_ERROR(func, sockpath) do { char errbuf[1024]; ERROR ("powerdns plugin: Socket `%s` %s failed: %s", sockpath, func, sstrerror (errno, errbuf, sizeof (errbuf))); } while (0)
#define SERVER_SOCKET LOCALSTATEDIR"/run/pdns.controlsocket"
#define SERVER_COMMAND "SHOW * \n"
#define SERVER_SOCKET LOCALSTATEDIR"/run/pdns.controlsocket"
#define SERVER_COMMAND "SHOW * \n"
@@
-50,7
+51,7
@@
#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 " \
#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\n"
+ "cache-misses questions
\n"
struct list_item_s;
typedef struct list_item_s list_item_t;
struct list_item_s;
typedef struct list_item_s list_item_t;
@@
-75,9
+76,9
@@
struct list_item_s
struct statname_lookup_s
{
struct statname_lookup_s
{
- char *name;
- char *type;
- char *type_instance;
+ c
onst c
har *name;
+ c
onst c
har *type;
+ c
onst c
har *type_instance;
};
typedef struct statname_lookup_s statname_lookup_t;
};
typedef struct statname_lookup_s statname_lookup_t;
@@
-143,9
+144,9
@@
uptime number of seconds process has been running (since 3.1.5)
user-msec number of CPU milliseconds spent in 'user' mode
}}} */
user-msec number of CPU milliseconds spent in 'user' mode
}}} */
-const char* const default_server_fields[] = /* {{{ */
+
static
const char* const default_server_fields[] = /* {{{ */
{
{
- "latency"
+ "latency"
,
"packetcache-hit",
"packetcache-miss",
"packetcache-size",
"packetcache-hit",
"packetcache-miss",
"packetcache-size",
@@
-158,9
+159,9
@@
const char* const default_server_fields[] = /* {{{ */
"udp-answers",
"udp-queries",
}; /* }}} */
"udp-answers",
"udp-queries",
}; /* }}} */
-int default_server_fields_num = STATIC_ARRAY_SIZE (default_server_fields);
+
static
int default_server_fields_num = STATIC_ARRAY_SIZE (default_server_fields);
-statname_lookup_t lookup_table[] = /* {{{ */
+stat
ic stat
name_lookup_t lookup_table[] = /* {{{ */
{
/*********************
* Server statistics *
{
/*********************
* Server statistics *
@@
-285,7
+286,7
@@
statname_lookup_t lookup_table[] = /* {{{ */
{"unexpected-packets", "dns_answer", "unexpected"},
{"uptime", "uptime", NULL}
}; /* }}} */
{"unexpected-packets", "dns_answer", "unexpected"},
{"uptime", "uptime", NULL}
}; /* }}} */
-int lookup_table_length = STATIC_ARRAY_SIZE (lookup_table);
+
static
int lookup_table_length = STATIC_ARRAY_SIZE (lookup_table);
static llist_t *list = NULL;
static llist_t *list = NULL;
@@
-300,10
+301,10
@@
static char *local_sockpath = NULL;
/* <https://doc.powerdns.com/md/recursor/stats/> */
static void submit (const char *plugin_instance, /* {{{ */
/* <https://doc.powerdns.com/md/recursor/stats/> */
static void submit (const char *plugin_instance, /* {{{ */
- const char *pdns_type, const char *value)
+ const char *pdns_type, const char *value
_str
)
{
value_list_t vl = VALUE_LIST_INIT;
{
value_list_t vl = VALUE_LIST_INIT;
- value_t value
s[1]
;
+ value_t value;
const char *type = NULL;
const char *type_instance = NULL;
const char *type = NULL;
const char *type_instance = NULL;
@@
-318,7
+319,7
@@
static void submit (const char *plugin_instance, /* {{{ */
if (i >= lookup_table_length)
{
INFO ("powerdns plugin: submit: Not found in lookup table: %s = %s;",
if (i >= lookup_table_length)
{
INFO ("powerdns plugin: submit: Not found in lookup table: %s = %s;",
- pdns_type, value);
+ pdns_type, value
_str
);
return;
}
return;
}
@@
-345,16
+346,15
@@
static void submit (const char *plugin_instance, /* {{{ */
return;
}
return;
}
- if (0 != parse_value (value
, &values[0]
, ds->ds[0].type))
+ if (0 != parse_value (value
_str, &value
, ds->ds[0].type))
{
ERROR ("powerdns plugin: Cannot convert `%s' "
{
ERROR ("powerdns plugin: Cannot convert `%s' "
- "to a number.", value);
+ "to a number.", value
_str
);
return;
}
return;
}
- vl.values =
values
;
+ vl.values =
&value
;
vl.values_len = 1;
vl.values_len = 1;
- sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "powerdns", sizeof (vl.plugin));
sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
sstrncpy (vl.plugin, "powerdns", sizeof (vl.plugin));
sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
@@
-375,9
+375,8
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
char *buffer = NULL;
size_t buffer_size = 0;
char *buffer = NULL;
size_t buffer_size = 0;
- struct sockaddr_un sa_unix;
+ struct sockaddr_un sa_unix
= { 0 }
;
- struct timeval stv_timeout;
cdtime_t cdt_timeout;
sd = socket (PF_UNIX, item->socktype, 0);
cdtime_t cdt_timeout;
sd = socket (PF_UNIX, item->socktype, 0);
@@
-387,7
+386,6
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
return (-1);
}
return (-1);
}
- memset (&sa_unix, 0, sizeof (sa_unix));
sa_unix.sun_family = AF_UNIX;
sstrncpy (sa_unix.sun_path,
(local_sockpath != NULL) ? local_sockpath : PDNS_LOCAL_SOCKPATH,
sa_unix.sun_family = AF_UNIX;
sstrncpy (sa_unix.sun_path,
(local_sockpath != NULL) ? local_sockpath : PDNS_LOCAL_SOCKPATH,
@@
-396,7
+394,7
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
status = unlink (sa_unix.sun_path);
if ((status != 0) && (errno != ENOENT))
{
status = unlink (sa_unix.sun_path);
if ((status != 0) && (errno != ENOENT))
{
-
FUNC_ERROR ("unlink"
);
+
SOCK_ERROR ("unlink", sa_unix.sun_path
);
close (sd);
return (-1);
}
close (sd);
return (-1);
}
@@
-408,7
+406,7
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
status = bind (sd, (struct sockaddr *) &sa_unix, sizeof (sa_unix));
if (status != 0)
{
status = bind (sd, (struct sockaddr *) &sa_unix, sizeof (sa_unix));
if (status != 0)
{
-
FUNC_ERROR ("bind"
);
+
SOCK_ERROR ("bind", sa_unix.sun_path
);
break;
}
break;
}
@@
-416,7
+414,7
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
status = chmod (sa_unix.sun_path, 0666);
if (status != 0)
{
status = chmod (sa_unix.sun_path, 0666);
if (status != 0)
{
-
FUNC_ERROR ("chmod"
);
+
SOCK_ERROR ("chmod", sa_unix.sun_path
);
break;
}
break;
}
@@
-424,12
+422,12
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
if (cdt_timeout < TIME_T_TO_CDTIME_T (2))
cdt_timeout = TIME_T_TO_CDTIME_T (2);
if (cdt_timeout < TIME_T_TO_CDTIME_T (2))
cdt_timeout = TIME_T_TO_CDTIME_T (2);
- CDTIME_T_TO_TIMEVAL (cdt_timeout, &stv_timeout);
-
-
status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO, &stv_timeout, sizeof (stv_timeout
));
+ status = setsockopt (sd, SOL_SOCKET, SO_RCVTIMEO,
+ &CDTIME_T_TO_TIMEVAL(cdt_timeout),
+
sizeof(struct timeval
));
if (status != 0)
{
if (status != 0)
{
-
FUNC_ERROR ("setsockopt"
);
+
SOCK_ERROR ("setsockopt", sa_unix.sun_path
);
break;
}
break;
}
@@
-437,21
+435,21
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
sizeof (item->sockaddr));
if (status != 0)
{
sizeof (item->sockaddr));
if (status != 0)
{
-
FUNC_ERROR ("connect"
);
+
SOCK_ERROR ("connect", sa_unix.sun_path
);
break;
}
status = send (sd, item->command, strlen (item->command), 0);
if (status < 0)
{
break;
}
status = send (sd, item->command, strlen (item->command), 0);
if (status < 0)
{
-
FUNC_ERROR ("send"
);
+
SOCK_ERROR ("send", sa_unix.sun_path
);
break;
}
status = recv (sd, temp, sizeof (temp), /* flags = */ 0);
if (status < 0)
{
break;
}
status = recv (sd, temp, sizeof (temp), /* flags = */ 0);
if (status < 0)
{
-
FUNC_ERROR ("recv"
);
+
SOCK_ERROR ("recv", sa_unix.sun_path
);
break;
}
buffer_size = status + 1;
break;
}
buffer_size = status + 1;
@@
-465,7
+463,7
@@
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
return (-1);
assert (buffer_size > 0);
return (-1);
assert (buffer_size > 0);
- buffer =
(char *)
malloc (buffer_size);
+ buffer = malloc (buffer_size);
if (buffer == NULL)
{
FUNC_ERROR ("malloc");
if (buffer == NULL)
{
FUNC_ERROR ("malloc");
@@
-514,7
+512,7
@@
static int powerdns_get_data_stream (list_item_t *item, /* {{{ */
sizeof (item->sockaddr));
if (status != 0)
{
sizeof (item->sockaddr));
if (status != 0)
{
-
FUNC_ERROR ("connect"
);
+
SOCK_ERROR ("connect", item->sockaddr.sun_path
);
close (sd);
return (-1);
}
close (sd);
return (-1);
}
@@
-524,7
+522,7
@@
static int powerdns_get_data_stream (list_item_t *item, /* {{{ */
/* flags = */ 0);
if (status < 0)
{
/* flags = */ 0);
if (status < 0)
{
-
FUNC_ERROR ("send"
);
+
SOCK_ERROR ("send", item->sockaddr.sun_path
);
close (sd);
return (-1);
}
close (sd);
return (-1);
}
@@
-536,13
+534,13
@@
static int powerdns_get_data_stream (list_item_t *item, /* {{{ */
status = recv (sd, temp, sizeof (temp), /* flags = */ 0);
if (status < 0)
{
status = recv (sd, temp, sizeof (temp), /* flags = */ 0);
if (status < 0)
{
-
FUNC_ERROR ("recv"
);
+
SOCK_ERROR ("recv", item->sockaddr.sun_path
);
break;
}
else if (status == 0)
break;
break;
}
else if (status == 0)
break;
- buffer_new =
(char *)
realloc (buffer, buffer_size + status + 1);
+ buffer_new = realloc (buffer, buffer_size + status + 1);
if (buffer_new == NULL)
{
FUNC_ERROR ("realloc");
if (buffer_new == NULL)
{
FUNC_ERROR ("realloc");
@@
-631,8
+629,6
@@
static int powerdns_read_server (list_item_t *item) /* {{{ */
saveptr = NULL;
while ((key = strtok_r (dummy, ",", &saveptr)) != NULL)
{
saveptr = NULL;
while ((key = strtok_r (dummy, ",", &saveptr)) != NULL)
{
- int i;
-
dummy = NULL;
value = strchr (key, '=');
dummy = NULL;
value = strchr (key, '=');
@@
-646,6
+642,7
@@
static int powerdns_read_server (list_item_t *item) /* {{{ */
continue;
/* Check if this item was requested. */
continue;
/* Check if this item was requested. */
+ int i;
for (i = 0; i < fields_num; i++)
if (strcasecmp (key, fields[i]) == 0)
break;
for (i = 0; i < fields_num; i++)
if (strcasecmp (key, fields[i]) == 0)
break;
@@
-781,7
+778,6
@@
static int powerdns_read_recursor (list_item_t *item) /* {{{ */
static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
oconfig_item_t *ci)
{
static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
oconfig_item_t *ci)
{
- int i;
char **temp;
if (ci->values_num < 1)
char **temp;
if (ci->values_num < 1)
@@
-791,7
+787,7
@@
static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
return (-1);
}
return (-1);
}
- for (i = 0; i < ci->values_num; i++)
+ for (i
nt i
= 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
WARNING ("powerdns plugin: Only string arguments are allowed to "
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
WARNING ("powerdns plugin: Only string arguments are allowed to "
@@
-799,7
+795,7
@@
static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
return (-1);
}
return (-1);
}
- temp =
(char **)
realloc (li->fields,
+ temp = realloc (li->fields,
sizeof (char *) * (li->fields_num + ci->values_num));
if (temp == NULL)
{
sizeof (char *) * (li->fields_num + ci->values_num));
if (temp == NULL)
{
@@
-808,7
+804,7
@@
static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
}
li->fields = temp;
}
li->fields = temp;
- for (i = 0; i < ci->values_num; i++)
+ for (i
nt i
= 0; i < ci->values_num; i++)
{
li->fields[li->fields_num] = strdup (ci->values[i].value.string);
if (li->fields[li->fields_num] == NULL)
{
li->fields[li->fields_num] = strdup (ci->values[i].value.string);
if (li->fields[li->fields_num] == NULL)
@@
-831,7
+827,6
@@
static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
list_item_t *item;
int status;
list_item_t *item;
int status;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
@@
-840,13
+835,12
@@
static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
return (-1);
}
return (-1);
}
- item =
(list_item_t *) malloc (sizeof (list_item_t
));
+ item =
calloc (1, sizeof (*item
));
if (item == NULL)
{
if (item == NULL)
{
- ERROR ("powerdns plugin:
m
alloc failed.");
+ ERROR ("powerdns plugin:
c
alloc failed.");
return (-1);
}
return (-1);
}
- memset (item, '\0', sizeof (list_item_t));
item->instance = strdup (ci->values[0].value.string);
if (item->instance == NULL)
item->instance = strdup (ci->values[0].value.string);
if (item->instance == NULL)
@@
-881,7
+875,7
@@
static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
}
status = 0;
}
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
oconfig_item_t *option = ci->children + i;
@@
-941,8
+935,6
@@
static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
static int powerdns_config (oconfig_item_t *ci) /* {{{ */
{
static int powerdns_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
DEBUG ("powerdns plugin: powerdns_config (ci = %p);", (void *) ci);
if (list == NULL)
DEBUG ("powerdns plugin: powerdns_config (ci = %p);", (void *) ci);
if (list == NULL)
@@
-956,7
+948,7
@@
static int powerdns_config (oconfig_item_t *ci) /* {{{ */
}
}
}
}
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
oconfig_item_t *option = ci->children + i;
@@
-989,9
+981,7
@@
static int powerdns_config (oconfig_item_t *ci) /* {{{ */
static int powerdns_read (void)
{
static int powerdns_read (void)
{
- llentry_t *e;
-
- for (e = llist_head (list); e != NULL; e = e->next)
+ for (llentry_t *e = llist_head (list); e != NULL; e = e->next)
{
list_item_t *item = e->value;
item->func (item);
{
list_item_t *item = e->value;
item->func (item);
@@
-1002,12
+992,10
@@
static int powerdns_read (void)
static int powerdns_shutdown (void)
{
static int powerdns_shutdown (void)
{
- llentry_t *e;
-
if (list == NULL)
return (0);
if (list == NULL)
return (0);
- for (e = llist_head (list); e != NULL; e = e->next)
+ for (
llentry_t *
e = llist_head (list); e != NULL; e = e->next)
{
list_item_t *item = (list_item_t *) e->value;
e->value = NULL;
{
list_item_t *item = (list_item_t *) e->value;
e->value = NULL;