/* 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;
{
"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)
{
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));
if (sd < 0)
{
- DEBUG ("Unable to open a socket");
+ DEBUG ("apcups plugin: Unable to open a socket");
freeaddrinfo (ai_return);
return (-1);
}
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) */
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) */
}
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);
*/
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,