solaris-fixes branch: Applied the swap-patch by Christophe Kalt.
[collectd.git] / src / ping.c
index fb2f8c1..91e0dbc 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -37,7 +37,7 @@ static char *file_template = "ping-%s.rrd";
 
 static char *ds_def[] = 
 {
-       "DS:ping:GAUGE:25:0:65535",
+       "DS:ping:GAUGE:"COLLECTD_HEARTBEAT":0:65535",
        NULL
 };
 static int ds_num = 1;
@@ -45,9 +45,10 @@ 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)
 {
@@ -56,23 +57,36 @@ 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)
+       {
+               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
        {
-               syslog (LOG_ERR, "ping: `ping_host_add' failed.\n");
                return (-1);
        }
 
@@ -117,7 +131,8 @@ static void ping_read (void)
 
        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;
        }