X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fapcups.c;h=281bf9803bdd6e6a84086b152f14b623961337b7;hb=142fb2ea490118e62f34df41f907ef1e58fb0be4;hp=4fbbde63aad113dcbefdbc2db47e545ca3b5c241;hpb=5131a49ad0584aa22282aacf72b6e4ca75356bae;p=collectd.git diff --git a/src/apcups.c b/src/apcups.c index 4fbbde63..281bf980 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -21,7 +21,7 @@ * * Authors: * Anthony Gialluca - * Florian octo Forster + * Florian octo Forster **/ #include "collectd.h" @@ -70,6 +70,8 @@ struct apc_detail_s /* Default values for contacting daemon */ static char *conf_host = NULL; static int conf_port = NISPORT; +/* Defaults to false for backwards compatibility. */ +static _Bool conf_report_seconds = 0; static int global_sockfd = -1; @@ -81,9 +83,9 @@ static const char *config_keys[] = { "Host", "Port", - NULL + "ReportSeconds" }; -static int config_keys_num = 2; +static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static int net_shutdown (int *fd) { @@ -137,7 +139,7 @@ static int net_open (char *host, int port) if (status != 0) { char errbuf[1024]; - INFO ("getaddrinfo failed: %s", + INFO ("apcups plugin: getaddrinfo failed: %s", (status == EAI_SYSTEM) ? sstrerror (errno, errbuf, sizeof (errbuf)) : gai_strerror (status)); @@ -156,7 +158,7 @@ static int net_open (char *host, int port) if (sd < 0) { - DEBUG ("Unable to open a socket"); + DEBUG ("apcups plugin: Unable to open a socket"); freeaddrinfo (ai_return); return (-1); } @@ -168,13 +170,13 @@ static int net_open (char *host, int port) if (status != 0) /* `connect(2)' failed */ { char errbuf[1024]; - INFO ("connect failed: %s", + INFO ("apcups plugin: connect failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); close (sd); return (-1); } - DEBUG ("Done opening a socket %i", sd); + DEBUG ("apcups plugin: Done opening a socket %i", sd); return (sd); } /* int net_open (char *host, char *service, int port) */ @@ -360,7 +362,13 @@ static int apc_query_server (char *host, int port, else if (strcmp ("LINEFREQ", key) == 0) apcups_detail->linefreq = value; else if (strcmp ("TIMELEFT", key) == 0) + { + /* Convert minutes to seconds if requested by + * the user. */ + if (conf_report_seconds) + value *= 60.0; apcups_detail->timeleft = value; + } tokptr = strtok_r (NULL, ":", &toksaveptr); } /* while (tokptr != NULL) */ @@ -403,6 +411,13 @@ static int apcups_config (const char *key, const char *value) } conf_port = port_tmp; } + else if (strcasecmp (key, "ReportSeconds") == 0) + { + if (IS_TRUE (value)) + conf_report_seconds = 1; + else + conf_report_seconds = 0; + } else { return (-1); @@ -450,7 +465,7 @@ static int apcups_read (void) apcups_detail.battv = -1.0; apcups_detail.loadpct = -1.0; apcups_detail.bcharge = -1.0; - apcups_detail.timeleft = -1.0; + apcups_detail.timeleft = NAN; apcups_detail.itemp = -300.0; apcups_detail.linefreq = -1.0; @@ -465,7 +480,7 @@ static int apcups_read (void) */ if (status != 0) { - DEBUG ("apc_query_server (%s, %i) = %i", + DEBUG ("apcups plugin: apc_query_server (%s, %i) = %i", conf_host == NULL ? APCUPS_DEFAULT_HOST : conf_host,