summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6085380)
raw | patch | inline | side by side (parent: 6085380)
author | anthony <anthony> | |
Tue, 6 Jun 2006 02:27:50 +0000 (02:27 +0000) | ||
committer | anthony <anthony> | |
Tue, 6 Jun 2006 02:27:50 +0000 (02:27 +0000) |
I re-inserted the net_close() and now when apcupsd is shutdown (or otherwise goes away)
collectd stays running.
2. Changed the 'complain' and 'complain_step' code so that it will chirp the first time, then
every 6 hours. As it was originally it would only start complaining after 6 hours. Additionally
I made complain an unsigned int. If it was an int and rolled over I wasn't certain what would happen.
3. 'global_host' set to localhost. It was set to NULL, but what happens is if someone does not enter
an apcups section to collectd.conf, then it will not connect to anyone. With 'global_host' set to localhost
the default behavior is now to connect to the apcupsd on the localhost.
4. Added entry for apcupsd.so in 'contrib/collectd.spec'.
collectd stays running.
2. Changed the 'complain' and 'complain_step' code so that it will chirp the first time, then
every 6 hours. As it was originally it would only start complaining after 6 hours. Additionally
I made complain an unsigned int. If it was an int and rolled over I wasn't certain what would happen.
3. 'global_host' set to localhost. It was set to NULL, but what happens is if someone does not enter
an apcups section to collectd.conf, then it will not connect to anyone. With 'global_host' set to localhost
the default behavior is now to connect to the apcupsd on the localhost.
4. Added entry for apcupsd.so in 'contrib/collectd.spec'.
collectd.spec | patch | blob | history | |
src/apcups.c | patch | blob | history |
diff --git a/collectd.spec b/collectd.spec
index 0a03acf93c682cc21dff77e4752db7ee72ae8598..d0d19902a75f21e922e524b221e9db936374f69a 100644 (file)
--- a/collectd.spec
+++ b/collectd.spec
%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*
diff --git a/src/apcups.c b/src/apcups.c
index f879f7c8a183f6ef77dad33dab3b400e6a808f8c..b9a500d00f64769b08d66d77f8e467330daf84d8 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
#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