/**
* collectd - src/ping.c
- * Copyright (C) 2005 Florian octo Forster
+ * Copyright (C) 2005,2006 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
static char *ds_def[] =
{
- "DS:ping:GAUGE:25:0:65535",
+ "DS:ping:GAUGE:"COLLECTD_HEARTBEAT":0:65535",
NULL
};
static int ds_num = 1;
static char *config_keys[] =
{
"Host",
+ "TTL",
NULL
};
-static int config_keys_num = 1;
+static int config_keys_num = 2;
static void ping_init (void)
{
static int ping_config (char *key, char *value)
{
- if (strcasecmp (key, "host"))
- {
- return (-1);
- }
-
if (pingobj == NULL)
{
if ((pingobj = ping_construct ()) == NULL)
{
- syslog (LOG_ERR, "ping: `ping_construct' failed.\n");
- return (-1);
+ syslog (LOG_ERR, "ping: `ping_construct' failed: %s",
+ ping_get_error (pingobj));
+ return (1);
}
}
- if (ping_host_add (pingobj, value) < 0)
+ if (strcasecmp (key, "host") == 0)
{
- syslog (LOG_WARNING, "ping: `ping_host_add' failed.\n");
+ if (ping_host_add (pingobj, value) < 0)
+ {
+ syslog (LOG_WARNING, "ping: `ping_host_add' failed: %s",
+ ping_get_error (pingobj));
+ return (1);
+ }
+ }
+ else if (strcasecmp (key, "ttl") == 0)
+ {
+ int ttl = atoi (value);
+ if (ping_setopt (pingobj, PING_DEF_TIMEOUT, (void *) &ttl))
+ {
+ syslog (LOG_WARNING, "ping: liboping did not accept the TTL value %i", ttl);
+ return (1);
+ }
+ }
+ else
+ {
+ return (-1);
}
return (0);
if (ping_send (pingobj) < 0)
{
- syslog (LOG_ERR, "ping: `ping_send' failed.");
+ syslog (LOG_ERR, "ping: `ping_send' failed: %s",
+ ping_get_error (pingobj));
return;
}