%attr(0444,root,root) %{_mandir}/man1/*
%attr(0444,root,root) %{_mandir}/man5/*
%attr(0444,root,root) %{_libdir}/%{name}/apple_sensors.so*
+%attr(0444,root,root) %{_libdir}/%{name}/apcups.so*
%attr(0444,root,root) %{_libdir}/%{name}/battery.so*
%attr(0444,root,root) %{_libdir}/%{name}/cpu.so*
%attr(0444,root,root) %{_libdir}/%{name}/cpufreq.so*
#include "plugin.h" /* plugin_register, plugin_submit */
#include "configfile.h" /* cf_register */
#include "utils_debug.h"
+#include <errno.h>
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#if HAVE_NETDB_H
# include <netdb.h>
#endif
+
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#define MODULE_NAME "apcups"
/* Default values for contacting daemon */
-static char *global_host = NULL;
+static char *global_host = "localhost";
static int global_port = NISPORT;
/*
static char *load_file_template = "apcups/charge_percent.rrd";
static char *load_ds_def[] =
{
- "DS:percent:GAUGE:"COLLECTD_HEARTBEAT":0:100",
+ "DS:percent:GAUGE:"COLLECTD_HEARTBEAT":0:110",
};
static int load_ds_num = 1;
return (buflen);
}
-#if 0
/* Close the network connection */
static void net_close (int *fd)
{
close (*fd);
*fd = -1;
}
-#endif
/*
double value;
static int sockfd = -1;
- static int complain = 0;
+ static unsigned int complain = 0;
#if APCMAIN
# define PRINT_VALUE(name, val) printf(" Found property: name = %s; value = %f;\n", name, val)
{
if ((sockfd = net_open (host, NULL, port)) < 0)
{
- /* Complain once every six hours. */
+ /* Complain first time and once every six hours. */
int complain_step = 21600 / atoi (COLLECTD_STEP);
- if ((complain % complain_step) == 0)
+ if (complain == 0 || (complain % complain_step) == 0)
syslog (LOG_ERR, "apcups plugin: Connecting to the apcupsd failed.");
complain++;
return (-1);
+ } else {
+ if(complain > 1)
+ syslog (LOG_ERR, "apcups plugin: Connection re-established to the apcupsd.");
}
complain = 0;
}
apcups_detail->linefreq = value;
else if (strcmp ("TIMELEFT", tokptr) == 0)
apcups_detail->timeleft = value;
- else
- {
- syslog (LOG_WARNING, "apcups plugin: Received unknown property from apcupsd: `%s' = %f",
- key, value);
- }
tokptr = strtok (NULL, ":");
} /* while (tokptr != NULL) */
}
-
+
if (n < 0)
{
syslog (LOG_WARNING, "apcups plugin: Error reading from socket");
return (-1);
+ } else {
+ /* close the opened socket */
+ net_close(&sockfd);
}
+
return (0);
}
/* we are not really going to use this */
struct apc_detail_s apcups_detail;
- openlog ("apcups", LOG_PID | LOG_NDELAY | LOG_LOCAL1);
+ openlog ("apcups", LOG_PID | LOG_NDELAY | LOG_LOCAL1, LOG_USER);
- if (!*host || strcmp (host, "0.0.0.0") == 0)
- host = "localhost";
+ if (global_host == NULL || strcmp (global_host, "0.0.0.0") == 0)
+ global_host = "localhost";
- if(do_apc_status (host, port, &apcups_detail) < 0)
+ if(apc_query_server (global_host, global_port, &apcups_detail) < 0)
{
printf("apcups: Failed...\n");
return(-1);
}
- apc_query_server (global_host, global_port, &apcups_detail);
-
return 0;
}
#else