summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d664ba8)
raw | patch | inline | side by side (parent: d664ba8)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 22 Jul 2009 19:45:59 +0000 (21:45 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 8 Dec 2009 20:09:00 +0000 (21:09 +0100) |
As the name suggests, these options may be used to set the source address and
the outgoing device for ICMP_ECHO requests, just like oping's -I and -D
options.
the outgoing device for ICMP_ECHO requests, just like oping's -I and -D
options.
src/collectd.conf.pod | patch | blob | history | |
src/ping.c | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index d19a86902618b07fde8be6dee748d87876d6102a..163f0eb4c575f118a76b8134a157ab3d5026a226 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
Sets the Time-To-Live of generated ICMP packets.
+=item B<SourceAddress> I<host>
+
+Sets the source address to use. I<host> may either be a numerical network
+address or a network hostname.
+
+=item B<Device> I<name>
+
+Sets the outgoing network device to be used. I<name> has to specify an
+interface name (e.E<nbsp>g. C<eth0>). This might not be supported by all
+operating systems.
+
=back
=head2 Plugin C<postgresql>
diff --git a/src/ping.c b/src/ping.c
index de9c45bb38d822f4221065343bc1c7e494e37028..927838007a2cffc856640ab7d9fe4bfbbf08af80 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
# define NI_MAXHOST 1025
#endif
+#if defined(OPING_VERSION) && (OPING_VERSION >= 1003000)
+# define HAVE_OPING_1_3
+#endif
+
/*
* Private data types
*/
*/
static hostlist_t *hostlist_head = NULL;
+static char *ping_source = NULL;
+#ifdef HAVE_OPING_1_3
+static char *ping_device = NULL;
+#endif
static int ping_ttl = PING_DEF_TTL;
static double ping_interval = 1.0;
static double ping_timeout = 0.9;
static const char *config_keys[] =
{
"Host",
+ "SourceAddress",
+#ifdef HAVE_OPING_1_3
+ "Device",
+#endif
"TTL",
"Interval",
"Timeout"
return ((void *) -1);
}
+ if (ping_source != NULL)
+ if (ping_setopt (pingobj, PING_OPT_SOURCE, (void *) ping_source) != 0)
+ ERROR ("ping plugin: Failed to set source address: %s",
+ ping_get_error (pingobj));
+
+#ifdef HAVE_OPING_1_3
+ if (ping_device != NULL)
+ if (ping_setopt (pingobj, PING_OPT_DEVICE, (void *) ping_device) != 0)
+ ERROR ("ping plugin: Failed to set device: %s",
+ ping_get_error (pingobj));
+#endif
+
ping_setopt (pingobj, PING_OPT_TIMEOUT, (void *) &ping_timeout);
ping_setopt (pingobj, PING_OPT_TTL, (void *) &ping_ttl);
return (0);
} /* }}} int ping_init */
+static int config_set_string (const char *name, /* {{{ */
+ char **var, const char *value)
+{
+ char *tmp;
+
+ tmp = strdup (value);
+ if (tmp == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("ping plugin: Setting `%s' to `%s' failed: strdup failed: %s",
+ name, value, sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (1);
+ }
+
+ if (*var != NULL)
+ free (*var);
+ *var = tmp;
+ return (0);
+} /* }}} int config_set_string */
+
static int ping_config (const char *key, const char *value) /* {{{ */
{
if (strcasecmp (key, "Host") == 0)
hl->next = hostlist_head;
hostlist_head = hl;
}
+ else if (strcasecmp (key, "SourceAddress") == 0)
+ {
+ int status = config_set_string (key, &ping_source, value);
+ if (status != 0)
+ return (status);
+ }
+#ifdef HAVE_OPING_1_3
+ else if (strcasecmp (key, "Device") == 0)
+ {
+ int status = config_set_string (key, &ping_device, value);
+ if (status != 0)
+ return (status);
+ }
+#endif
else if (strcasecmp (key, "TTL") == 0)
{
int ttl = atoi (value);