src/ntpd.c: Format refclock name and unit ID with %s-%u
[collectd.git] / src / ntpd.c
index 9d716ad..3e2b4ea 100644 (file)
@@ -278,9 +278,7 @@ static int ntpd_config (const char *key, const char *value)
        }
        else if (strcasecmp (key, "ReverseLookups") == 0)
        {
-               if ((strcasecmp (value, "True") == 0)
-                               || (strcasecmp (value, "Yes") == 0)
-                               || (strcasecmp (value, "On") == 0))
+               if (IS_TRUE (value))
                        do_reverse_lookups = 1;
                else
                        do_reverse_lookups = 0;
@@ -786,15 +784,15 @@ static int ntpd_read (void)
                        0, 0, NULL, /* request data */
                        &ik_num, &ik_size, (char **) ((void *) &ik), /* response data */
                        sizeof (struct info_kernel));
-
        if (status != 0)
        {
-               DEBUG ("ntpd_do_query failed with status %i", status);
-               return (-1);
+               ERROR ("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i", status);
+               return (status);
        }
-       if ((ik == NULL) || (ik_num == 0) || (ik_size == 0))
+       else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0))
        {
-               DEBUG ("ntpd_do_query returned: ik = %p; ik_num = %i; ik_size = %i;",
+               ERROR ("ntpd plugin: ntpd_do_query returned unexpected data. "
+                               "(ik = %p; ik_num = %i; ik_size = %i)",
                                (void *) ik, ik_num, ik_size);
                return (-1);
        }
@@ -822,12 +820,13 @@ static int ntpd_read (void)
                        sizeof (struct info_peer_summary));
        if (status != 0)
        {
-               DEBUG ("ntpd_do_query failed with status %i", status);
-               return (-1);
+               ERROR ("ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i", status);
+               return (status);
        }
-       if ((ps == NULL) || (ps_num == 0) || (ps_size == 0))
+       else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0))
        {
-               DEBUG ("ntpd_do_query returned: ps = %p; ps_num = %i; ps_size = %i;",
+               ERROR ("ntpd plugin: ntpd_do_query returned unexpected data. "
+                               "(ps = %p; ps_num = %i; ps_size = %i)",
                                (void *) ps, ps_num, ps_size);
                return (-1);
        }
@@ -858,8 +857,11 @@ static int ntpd_read (void)
 
                        if (refclock_id < refclock_names_num)
                        {
-                               sstrncpy (peername, refclock_names[refclock_id],
-                                               sizeof (peername));
+                               /* The unit number is in the lowest byte. */
+                               ssnprintf (peername, sizeof (peername),
+                                               "%s-%u",
+                                               refclock_names[refclock_id],
+                                               ntohl (ptr->srcadr) & 0xFF);
                        }
                        else
                        {