#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 */
#
#Hostname "localhost"
+FQDNLookup true
#BaseDir "@prefix@/var/lib/@PACKAGE_NAME@"
#PIDFile "@prefix@/var/run/@PACKAGE_NAME@.pid"
#PluginDir "@prefix@/lib/@PACKAGE_NAME@"
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
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 */