/**
- * collectd - src/named.c
+ * collectd - src/dns.c
* Copyright (C) 2006 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
# include <sys/poll.h>
#endif
-#define MODULE_NAME "named"
+#define MODULE_NAME "dns"
#if HAVE_LIBPCAP
# define NAMED_HAVE_CONFIG 1
};
typedef struct counter_list_s counter_list_t;
-static char *qtype_file = "named/qtype-%s.rrd";
-static char *opcode_file = "named/opcode-%s.rrd";
-static char *rcode_file = "named/rcode-%s.rrd";
+static char *qtype_file = "dns/qtype-%s.rrd";
+static char *opcode_file = "dns/opcode-%s.rrd";
+static char *rcode_file = "dns/rcode-%s.rrd";
static char *qtype_ds_def[] =
{
if (swrite (fd, (const void *) &values_num, sizeof (values_num)) != 0)
{
DBG ("Writing to fd failed: %s", strerror (errno));
- syslog (LOG_ERR, "named plugin: Writing to fd failed: %s",
+ syslog (LOG_ERR, "dns plugin: Writing to fd failed: %s",
strerror (errno));
return (-1);
}
if (swrite (fd, (const void *) values, 2 * sizeof (int) * values_num) != 0)
{
DBG ("Writing to pipe failed: %s", strerror (errno));
- syslog (LOG_ERR, "named plugin: Writing to pipe failed: %s",
+ syslog (LOG_ERR, "dns plugin: Writing to pipe failed: %s",
strerror (errno));
return (-1);
}
return (values_num);
}
#if NAMED_HAVE_CONFIG
-static int named_config (char *key, char *value)
+static int dns_config (char *key, char *value)
{
#if HAVE_LIBPCAP
if (strcasecmp (key, "Interface") == 0)
}
#endif /* NAMED_HAVE_CONFIG */
-static void named_child_callback (const rfc1035_header_t *dns)
+static void dns_child_callback (const rfc1035_header_t *dns)
{
if (dns->qr == 0)
{
counter_list_add (&opcode_list, dns->opcode, 1);
}
-static void named_child_loop (void)
+static void dns_child_loop (void)
{
pcap_t *pcap_obj;
char pcap_error[PCAP_ERRBUF_SIZE];
pcap_error);
if (pcap_obj == NULL)
{
- syslog (LOG_ERR, "named plugin: Opening interface `%s' failed: %s",
+ syslog (LOG_ERR, "dns plugin: Opening interface `%s' failed: %s",
(pcap_device != NULL) ? pcap_device : "any",
pcap_error);
close (pipe_fd);
if (pcap_compile (pcap_obj, &fp, "udp port 53", 1, 0) < 0)
{
DBG ("pcap_compile failed");
- syslog (LOG_ERR, "named plugin: pcap_compile failed");
+ syslog (LOG_ERR, "dns plugin: pcap_compile failed");
close (pipe_fd);
pipe_fd = -1;
return;
if (pcap_setfilter (pcap_obj, &fp) < 0)
{
DBG ("pcap_setfilter failed");
- syslog (LOG_ERR, "named plugin: pcap_setfilter failed");
+ syslog (LOG_ERR, "dns plugin: pcap_setfilter failed");
close (pipe_fd);
pipe_fd = -1;
return;
DBG ("PCAP object created.");
dnstop_set_pcap_obj (pcap_obj);
- dnstop_set_callback (named_child_callback);
+ dnstop_set_callback (dns_child_callback);
/* Set up pipe end */
poll_fds[0].fd = pipe_fd;
if (status < 0)
{
- syslog (LOG_ERR, "named plugin: poll(2) failed: %s",
+ syslog (LOG_ERR, "dns plugin: poll(2) failed: %s",
strerror (errno));
break;
}
if (poll_fds[0].revents & (POLLERR | POLLHUP | POLLNVAL))
{
DBG ("Pipe closed. Exiting.");
- syslog (LOG_NOTICE, "named plugin: Pipe closed. Exiting.");
+ syslog (LOG_NOTICE, "dns plugin: Pipe closed. Exiting.");
break;
}
else if (poll_fds[0].revents & POLLOUT)
if (poll_fds[1].revents & (POLLERR | POLLHUP | POLLNVAL))
{
DBG ("pcap-device closed. Exiting.");
- syslog (LOG_ERR, "named plugin: pcap-device closed. Exiting.");
+ syslog (LOG_ERR, "dns plugin: pcap-device closed. Exiting.");
break;
}
else if (poll_fds[1].revents & (POLLIN | POLLPRI))
if (status < 0)
{
DBG ("pcap_dispatch failed: %s", pcap_geterr (pcap_obj));
- syslog (LOG_ERR, "named plugin: pcap_dispatch failed: %s",
+ syslog (LOG_ERR, "dns plugin: pcap_dispatch failed: %s",
pcap_geterr (pcap_obj));
break;
}
close (pipe_fd);
pipe_fd = -1;
pcap_close (pcap_obj);
-} /* static void named_child_loop (void) */
+} /* static void dns_child_loop (void) */
-static void named_init (void)
+static void dns_init (void)
{
#if HAVE_LIBPCAP
int pipe_fds[2];
if (pipe (pipe_fds) != 0)
{
- syslog (LOG_ERR, "named plugin: pipe(2) failed: %s",
+ syslog (LOG_ERR, "dns plugin: pipe(2) failed: %s",
strerror (errno));
return;
}
pid_child = fork ();
if (pid_child < 0)
{
- syslog (LOG_ERR, "named plugin: fork(2) failed: %s",
+ syslog (LOG_ERR, "dns plugin: fork(2) failed: %s",
strerror (errno));
close (pipe_fds[0]);
close (pipe_fds[1]);
pipe_fd = pipe_fds[1];
close (pipe_fds[0]);
- named_child_loop ();
+ dns_child_loop ();
exit (0);
}
if ((status < 1) || (status >= 32))
return;
- plugin_submit ("named_qtype", inst, buffer);
+ plugin_submit ("dns_qtype", inst, buffer);
}
static void rcode_submit (int rcode, unsigned int counter)
if ((status < 1) || (status >= 32))
return;
- plugin_submit ("named_rcode", inst, buffer);
+ plugin_submit ("dns_rcode", inst, buffer);
}
static void opcode_submit (int opcode, unsigned int counter)
if ((status < 1) || (status >= 32))
return;
- plugin_submit ("named_opcode", inst, buffer);
+ plugin_submit ("dns_opcode", inst, buffer);
}
#if NAMED_HAVE_READ
-static unsigned int named_read_array (unsigned int *values)
+static unsigned int dns_read_array (unsigned int *values)
{
unsigned int values_num;
{
DBG ("Reading from the pipe failed: %s",
strerror (errno));
- syslog (LOG_ERR, "named plugin: Reading from the pipe failed: %s",
+ syslog (LOG_ERR, "dns plugin: Reading from the pipe failed: %s",
strerror (errno));
pipe_fd = -1;
return (0);
{
DBG ("Reading from the pipe failed: %s",
strerror (errno));
- syslog (LOG_ERR, "named plugin: Reading from the pipe failed: %s",
+ syslog (LOG_ERR, "dns plugin: Reading from the pipe failed: %s",
strerror (errno));
pipe_fd = -1;
return (0);
return (values_num);
}
-static void named_read (void)
+static void dns_read (void)
{
unsigned int values[2 * T_MAX];
unsigned int values_num;
if (pipe_fd < 0)
return;
- values_num = named_read_array (values);
+ values_num = dns_read_array (values);
for (i = 0; i < values_num; i++)
{
DBG ("qtype = %u; counter = %u;", values[2 * i], values[(2 * i) + 1]);
qtype_submit (values[2 * i], values[(2 * i) + 1]);
}
- values_num = named_read_array (values);
+ values_num = dns_read_array (values);
for (i = 0; i < values_num; i++)
{
DBG ("opcode = %u; counter = %u;", values[2 * i], values[(2 * i) + 1]);
opcode_submit (values[2 * i], values[(2 * i) + 1]);
}
- values_num = named_read_array (values);
+ values_num = dns_read_array (values);
for (i = 0; i < values_num; i++)
{
DBG ("rcode = %u; counter = %u;", values[2 * i], values[(2 * i) + 1]);
}
}
#else /* if !NAMED_HAVE_READ */
-# define named_read NULL
+# define dns_read NULL
#endif
void module_register (void)
{
- plugin_register (MODULE_NAME, named_init, named_read, NULL);
- plugin_register ("named_qtype", NULL, NULL, qtype_write);
- plugin_register ("named_rcode", NULL, NULL, rcode_write);
- plugin_register ("named_opcode", NULL, NULL, opcode_write);
- cf_register (MODULE_NAME, named_config, config_keys, config_keys_num);
+ plugin_register (MODULE_NAME, dns_init, dns_read, NULL);
+ plugin_register ("dns_qtype", NULL, NULL, qtype_write);
+ plugin_register ("dns_rcode", NULL, NULL, rcode_write);
+ plugin_register ("dns_opcode", NULL, NULL, opcode_write);
+ cf_register (MODULE_NAME, dns_config, config_keys, config_keys_num);
}
#undef MODULE_NAME