X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fapcups.c;h=cd64426afa01e42125f3b210b7e39dc40f991c12;hb=4c3b690f915df7b56170cee189096949adedefe5;hp=9117bdaea02f641e12a28d3d0be76c3d1393b4f6;hpb=6e318b5f03c2cc8ec0c6262498f4b62e59c8b505;p=collectd.git diff --git a/src/apcups.c b/src/apcups.c index 9117bdae..cd64426a 100644 --- a/src/apcups.c +++ b/src/apcups.c @@ -208,6 +208,7 @@ static int net_open (char *host, char *service, int port) if (status != 0) /* `connect(2)' failed */ { DBG ("connect failed: %s", strerror (errno)); + close (sd); return (-1); } @@ -300,7 +301,7 @@ static int apc_query_server (char *host, int port, double value; static int sockfd = -1; - static unsigned int complain = 0; + static complain_t compl; #if APCMAIN # define PRINT_VALUE(name, val) printf(" Found property: name = %s; value = %f;\n", name, val) @@ -312,19 +313,14 @@ static int apc_query_server (char *host, int port, { if ((sockfd = net_open (host, NULL, port)) < 0) { - /* Complain once every six hours. */ - int complain_step = 21600 / atoi (COLLECTD_STEP); - - if ((complain % complain_step) == 0) - syslog (LOG_ERR, "apcups plugin: Connecting to the apcupsd failed."); - complain++; - + plugin_complain (LOG_ERR, &compl, "apcups plugin: " + "Connecting to the apcupsd failed."); return (-1); } - else if (complain > 1) + else { - syslog (LOG_NOTICE, "apcups plugin: Connection re-established to the apcupsd."); - complain = 0; + plugin_relief (LOG_NOTICE, &compl, "apcups plugin: " + "Connection re-established to the apcupsd."); } }