- toksaveptr = NULL;
- tokptr = strtok_r (recvline, " :\t", &toksaveptr);
- while (tokptr != NULL)
- {
- char *key = tokptr;
- if ((tokptr = strtok_r (NULL, " :\t", &toksaveptr)) == NULL)
- continue;
-
- gauge_t value;
- if (strtogauge (tokptr, &value) != 0)
- continue;
-
- PRINT_VALUE (key, value);
-
- if (strcmp ("LINEV", key) == 0)
- apcups_detail->linev = value;
- else if (strcmp ("BATTV", key) == 0)
- apcups_detail->battv = value;
- else if (strcmp ("ITEMP", key) == 0)
- apcups_detail->itemp = value;
- else if (strcmp ("LOADPCT", key) == 0)
- apcups_detail->loadpct = value;
- else if (strcmp ("BCHARGE", key) == 0)
- apcups_detail->bcharge = value;
- else if (strcmp ("OUTPUTV", key) == 0)
- apcups_detail->outputv = value;
- 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) */
- }
- status = errno; /* save errno, net_shutdown() may re-set it. */
-
- if (close_socket)
- net_shutdown (&global_sockfd);
-
- if (n < 0)
- {
- char errbuf[1024];
- ERROR ("apcups plugin: Reading from socket failed: %s",
- sstrerror (status, errbuf, sizeof (errbuf)));
- return (-1);
- }
-
- return (0);
-}
-
-static int apcups_config (const char *key, const char *value)
-{
- if (strcasecmp (key, "host") == 0)
- {
- if (conf_host != NULL)
- {
- free (conf_host);
- conf_host = NULL;
- }
- if ((conf_host = strdup (value)) == NULL)
- return (1);
- }
- else if (strcasecmp (key, "Port") == 0)
- {
- int port_tmp = atoi (value);
- if (port_tmp < 1 || port_tmp > 65535)
- {
- WARNING ("apcups plugin: Invalid port: %i", port_tmp);
- return (1);
- }
- 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);
- }
- return (0);
+ toksaveptr = NULL;
+ tokptr = strtok_r(recvline, " :\t", &toksaveptr);
+ while (tokptr != NULL) {
+ char *key = tokptr;
+ if ((tokptr = strtok_r(NULL, " :\t", &toksaveptr)) == NULL)
+ continue;
+
+ gauge_t value;
+ if (strtogauge(tokptr, &value) != 0)
+ continue;
+
+ PRINT_VALUE(key, value);
+
+ if (strcmp("LINEV", key) == 0)
+ apcups_detail->linev = value;
+ else if (strcmp("BATTV", key) == 0)
+ apcups_detail->battv = value;
+ else if (strcmp("ITEMP", key) == 0)
+ apcups_detail->itemp = value;
+ else if (strcmp("LOADPCT", key) == 0)
+ apcups_detail->loadpct = value;
+ else if (strcmp("BCHARGE", key) == 0)
+ apcups_detail->bcharge = value;
+ else if (strcmp("OUTPUTV", key) == 0)
+ apcups_detail->outputv = value;
+ 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) */
+ }
+ status = errno; /* save errno, net_shutdown() may re-set it. */
+
+ if (!conf_persistent_conn)
+ net_shutdown(&global_sockfd);
+
+ if (n < 0) {
+ char errbuf[1024];
+ ERROR("apcups plugin: Reading from socket failed: %s",
+ sstrerror(status, errbuf, sizeof(errbuf)));
+ return (-1);
+ }
+
+ return (0);