summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3734b4e)
raw | patch | inline | side by side (parent: 3734b4e)
author | Florian Forster <octo@noris.net> | |
Tue, 13 Nov 2007 16:55:50 +0000 (16:55 +0000) | ||
committer | Florian Forster <octo@noris.net> | |
Tue, 13 Nov 2007 16:55:50 +0000 (16:55 +0000) |
So far the hostname as returned by `gethostname(2)' was used. This is not
practical for large setups.
To stay backwards compatible the option is disabled by default, but the sample
config file includes a line which sets this option so that (new) default
installations will have it enabled.
practical for large setups.
To stay backwards compatible the option is disabled by default, but the sample
config file includes a line which sets this option so that (new) default
installations will have it enabled.
src/collectd.c | patch | blob | history | |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/configfile.c | patch | blob | history |
diff --git a/src/collectd.c b/src/collectd.c
index 4e18fd6e2280edcce9b1190777c846bdfa11dd3f..70223b7dde98d58ac872a4b5a69efdfea83d447a 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
#include "collectd.h"
#include "common.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
#include "plugin.h"
#include "configfile.h"
#include "types_list.h"
loop++;
}
-static int init_global_variables (void)
+static int init_hostname (void)
{
const char *str;
+ struct addrinfo ai_hints;
+ struct addrinfo *ai_list;
+ struct addrinfo *ai_ptr;
+ int status;
+
str = global_option_get ("Hostname");
if (str != NULL)
{
strncpy (hostname_g, str, sizeof (hostname_g));
+ hostname_g[sizeof (hostname_g) - 1] = '\0';
+ return (0);
}
- else
+
+ if (gethostname (hostname_g, sizeof (hostname_g)) != 0)
{
- if (gethostname (hostname_g, sizeof (hostname_g)) != 0)
- {
- fprintf (stderr, "`gethostname' failed and no "
- "hostname was configured.\n");
- return (-1);
- }
+ fprintf (stderr, "`gethostname' failed and no "
+ "hostname was configured.\n");
+ return (-1);
+ }
+
+ str = global_option_get ("FQDNLookup");
+ if ((strcasecmp ("false", str) == 0)
+ || (strcasecmp ("no", str) == 0)
+ || (strcasecmp ("off", str) == 0))
+ return (0);
+
+ memset (&ai_hints, '\0', sizeof (ai_hints));
+ ai_hints.ai_flags = AI_CANONNAME;
+
+ status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list);
+ if (status != 0)
+ {
+ ERROR ("getaddrinfo failed.");
+ return (-1);
}
- DEBUG ("hostname_g = %s;", hostname_g);
+
+ for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ {
+ if (ai_ptr->ai_canonname == NULL)
+ continue;
+
+ strncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g));
+ hostname_g[sizeof (hostname_g) - 1] = '\0';
+ break;
+ }
+
+ freeaddrinfo (ai_list);
+ return (0);
+} /* int init_hostname */
+
+static int init_global_variables (void)
+{
+ const char *str;
str = global_option_get ("Interval");
if (str == NULL)
}
DEBUG ("interval_g = %i;", interval_g);
+ if (init_hostname () != 0)
+ return (-1);
+ DEBUG ("hostname_g = %s;", hostname_g);
+
return (0);
} /* int init_global_variables */
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 58de5258cb2b19ba1150531671c23c66b752bf27..61789990168c1e2b068e5355ef6e63867919fc10 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#
#Hostname "localhost"
+FQDNLookup true
#BaseDir "@prefix@/var/lib/@PACKAGE_NAME@"
#PIDFile "@prefix@/var/run/@PACKAGE_NAME@.pid"
#PluginDir "@prefix@/lib/@PACKAGE_NAME@"
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index da12f863a0b642627975a67325c0ee6091731cf3..d33b2806192c28c41de4fce028a23885d89b0cab 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
long time to read. Mostly those are plugin that do network-IO. Setting this to
a value higher than the number of plugins you've loaded is totally useless.
+=item B<Hostname> I<Name>
+
+Sets the hostname that identifies a host. If you omit this setting, the
+hostname will be determinded using the L<gethostname(2)> system call.
+
+=item B<FQDNLookup> B<true|false>
+
+If B<Hostname> is determined automatically this setting controls whether or not
+the daemon should try to figure out the "full qualified domain name", FQDN.
+This is done using a lookup of the name returned by C<gethostname>.
+
+Using this feature (i.E<nbsp>e. setting this option to B<true>) is recommended.
+However, to preserve backwards compatibility the default is set to B<false>.
+The sample config file that is installed with C<makeE<nbsp>install> includes a
+line with sets this option, though, so that default installations will have
+this setting enabled.
+
=back
=head1 PLUGIN OPTIONS
diff --git a/src/configfile.c b/src/configfile.c
index 0310ca8aff417f37036a737ee55043f5182bc955..a04a10d5d6dbb094b5a431457937434bf2f41255 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
static cf_global_option_t cf_global_options[] =
{
- {"BaseDir", NULL, PKGLOCALSTATEDIR},
- {"PIDFile", NULL, PIDFILE},
- {"Hostname", NULL, NULL},
- {"Interval", NULL, "10"},
+ {"BaseDir", NULL, PKGLOCALSTATEDIR},
+ {"PIDFile", NULL, PIDFILE},
+ {"Hostname", NULL, NULL},
+ {"FQDNLookup", NULL, "false"},
+ {"Interval", NULL, "10"},
{"ReadThreads", NULL, "5"},
- {"TypesDB", NULL, PLUGINDIR"/types.db"} /* FIXME: Configure path */
+ {"TypesDB", NULL, PLUGINDIR"/types.db"} /* FIXME: Configure path */
};
static int cf_global_options_num = STATIC_ARRAY_LEN (cf_global_options);
tmp[127] = '\0';
return (global_option_set (ci->key, tmp));
}
+ else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
+ {
+ if (ci->values[0].value.boolean)
+ return (global_option_set (ci->key, "true"));
+ else
+ return (global_option_set (ci->key, "false"));
+ }
return (-1);
} /* int dispatch_global_option */