-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);
+static int apcups_config(oconfig_item_t *ci) {
+ bool persistent_conn_set = false;
+
+ for (int i = 0; i < ci->children_num; i++) {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp(child->key, "Host") == 0)
+ cf_util_get_string(child, &conf_node);
+ else if (strcasecmp(child->key, "Port") == 0)
+ cf_util_get_service(child, &conf_service);
+ else if (strcasecmp(child->key, "ReportSeconds") == 0)
+ cf_util_get_boolean(child, &conf_report_seconds);
+ else if (strcasecmp(child->key, "PersistentConnection") == 0) {
+ cf_util_get_boolean(child, &conf_persistent_conn);
+ persistent_conn_set = true;
+ } else
+ ERROR("apcups plugin: Unknown config option \"%s\".", child->key);
+ }
+
+ if (!persistent_conn_set) {
+ double interval = CDTIME_T_TO_DOUBLE(plugin_get_interval());
+ if (interval > APCUPS_SERVER_TIMEOUT) {
+ NOTICE("apcups plugin: Plugin poll interval set to %.3f seconds. "
+ "Apcupsd NIS socket timeout is %.3f seconds, "
+ "PersistentConnection disabled by default.",
+ interval, APCUPS_SERVER_TIMEOUT);
+ conf_persistent_conn = false;
+ }
+ }
+
+ return 0;
+} /* int apcups_config */
+
+static void apc_submit_generic(const char *type, const char *type_inst,
+ gauge_t value) {
+ if (isnan(value))
+ return;
+
+ value_list_t vl = VALUE_LIST_INIT;
+ vl.values = &(value_t){.gauge = value};
+ vl.values_len = 1;
+ sstrncpy(vl.plugin, "apcups", sizeof(vl.plugin));
+ sstrncpy(vl.type, type, sizeof(vl.type));
+ sstrncpy(vl.type_instance, type_inst, sizeof(vl.type_instance));
+
+ plugin_dispatch_values(&vl);