ping plugin: Improved error and debug messages.
authorFlorian Forster <octo@huhu.verplant.org>
Mon, 16 Apr 2007 13:49:53 +0000 (15:49 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Mon, 16 Apr 2007 13:49:53 +0000 (15:49 +0200)
src/ping.c

index 89fecc8..eb716a4 100644 (file)
@@ -96,7 +96,9 @@ static void add_hosts (void)
                        }
                        else
                        {
-                               DEBUG ("ping plugin: Failed adding host `%s'", hl_this->host);
+                               WARNING ("ping plugin: Failed adding host "
+                                               "`%s': %s", hl_this->host,
+                                               ping_get_error (pingobj));
                                hl_this->wait_left = hl_this->wait_time;
                                hl_this->wait_time *= 2;
                                if (hl_this->wait_time > 86400)
@@ -130,8 +132,7 @@ static int ping_config (const char *key, const char *value)
        {
                if ((pingobj = ping_construct ()) == NULL)
                {
-                       ERROR ("ping: `ping_construct' failed: %s",
-                                       ping_get_error (pingobj));
+                       ERROR ("ping plugin: `ping_construct' failed.");
                        return (1);
                }
        }
@@ -217,7 +218,7 @@ static int ping_read (void)
 
        if (ping_send (pingobj) < 0)
        {
-               ERROR ("ping: `ping_send' failed: %s",
+               ERROR ("ping plugin: `ping_send' failed: %s",
                                ping_get_error (pingobj));
                return (-1);
        }
@@ -230,18 +231,31 @@ static int ping_read (void)
                buf_len = sizeof (host);
                if (ping_iterator_get_info (iter, PING_INFO_HOSTNAME,
                                        host, &buf_len))
+               {
+                       WARNING ("ping plugin: ping_iterator_get_info "
+                                       "(PING_INFO_HOSTNAME) failed.");
                        continue;
+               }
 
                buf_len = sizeof (latency);
                if (ping_iterator_get_info (iter, PING_INFO_LATENCY,
                                        &latency, &buf_len))
+               {
+                       WARNING ("ping plugin: ping_iterator_get_info (%s, "
+                                       "PING_INFO_LATENCY) failed.", host);
                        continue;
+               }
 
                DEBUG ("ping plugin: host = %s, latency = %f", host, latency);
                ping_submit (host, latency);
                number_of_hosts++;
        }
 
+       if ((number_of_hosts == 0) && (getuid != 0))
+       {
+               ERROR ("ping plugin: All hosts failed. Try starting collectd as root.");
+       }
+
        return (number_of_hosts == 0 ? -1 : 0);
 } /* int ping_read */