summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 06e0c04)
raw | patch | inline | side by side (parent: 06e0c04)
author | Steven Bell <stv.bell07@gmail.com> | |
Sun, 19 Feb 2017 05:45:21 +0000 (00:45 -0500) | ||
committer | Steven Bell <stv.bell07@gmail.com> | |
Sun, 19 Feb 2017 05:45:21 +0000 (00:45 -0500) |
AUTHORS | patch | blob | history | |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/nut.c | patch | blob | history |
index 8962e775b5e2b78f134ccb60b1c19c7e5c445494..d866c7004f70ec72719c4b056d6387c92d0283be 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
Stefan Hacker <stefan.hacker at web.de>
- teamspeak2 plugin.
+Steven Bell <stv.bell07 at gmail.com>
+ - nut plugin.
+
Sven Trenkel <collectd at semidefinite.de>
- netapp plugin.
- python plugin.
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 1cc86af48889ae8119c8e1cc179082603a31a02f..ff7b01b406f3e85a37c7a842225eda8f0dac5c2a 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#<Plugin nut>
# UPS "upsname@hostname:port"
+# ForceSSL true
#</Plugin>
#<Plugin olsrd>
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 51fe68d23831ddf01357226f96b3f2851a7471dc..4c045a6da52d275fb472764037875c82e42667af 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
Add a UPS to collect data from. The format is identical to the one accepted by
L<upsc(8)>.
+=item B<ForceSSL> B<true>|B<false>
+
+Stops connections from falling back to unsecured if an SSL connection
+cannot be established. Defaults to false if undeclared.
+
=back
=head2 Plugin C<olsrd>
diff --git a/src/nut.c b/src/nut.c
index c0ee7abfe1d88bc75dff569d56c0bc2e7ea0c533..0d506f03d446b560c69c22771434a404a54b61a0 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
static int read_busy = 0;
-static const char *config_keys[] = {"UPS"};
+static const char *config_keys[] = {"UPS", "FORCESSL"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
+static int force_ssl = 0; // Initialized to default of 0 (false)
static void free_nut_ups_t(nut_ups_t *ups) {
if (ups->conn != NULL) {
return (0);
} /* int nut_add_ups */
+static int nut_force_ssl(const char *value) {
+ if (strcasecmp(value, "true") == 0)
+ force_ssl = 1;
+ else if (strcasecmp(value, "false") == 0)
+ force_ssl = 0; // Should already be set to 0 from initialization
+ else {
+ force_ssl = 0;
+ WARNING("nut plugin: nut_force_ssl: invalid FORCESSL value "
+ "found. Defaulting to false.");
+ }
+ return (0);
+} /* int nut_parse_force_ssl */
+
static int nut_config(const char *key, const char *value) {
if (strcasecmp(key, "UPS") == 0)
return (nut_add_ups(value));
+ else if (strcasecmp(key, "FORCESSL") == 0)
+ return (nut_force_ssl(value));
else
return (-1);
} /* int nut_config */
char **answer;
unsigned int answer_num;
int status;
+ int ssl_status;
+ int ssl_flags;
/* (Re-)Connect if we have no connection */
if (ups->conn == NULL) {
return (-1);
}
- status =
- upscli_connect(ups->conn, ups->hostname, ups->port, UPSCLI_CONN_TRYSSL);
+ if (force_ssl == 1)
+ ssl_flags = UPSCLI_CONN_REQSSL;
+ else
+ ssl_flags = UPSCLI_CONN_TRYSSL;
+
+ status = upscli_connect(ups->conn, ups->hostname, ups->port, ssl_flags);
+
if (status != 0) {
ERROR("nut plugin: nut_read_one: upscli_connect (%s, %i) failed: %s",
ups->hostname, ups->port, upscli_strerror(ups->conn));
sfree(ups->conn);
return (-1);
- }
+ } /* if (status != 0) */
INFO("nut plugin: Connection to (%s, %i) established.", ups->hostname,
ups->port);
+
+ // Output INFO or WARNING based on SSL and VERIFICATION
+ ssl_status = upscli_ssl(ups->conn); // 1 for SSL, 0 for not, -1 for error
+ if (ssl_status == 1){
+ INFO("nut plugin: Connection is secured with SSL.");
+ }
+ else if (ssl_status == 0){
+ WARNING("nut plugin: Connection is unsecured (no SSL).");
+ }else{
+ ERROR("nut plugin: nut_read_one: upscli_ssl failed: %s",
+ upscli_strerror(ups->conn));
+ sfree(ups->conn);
+ return (-1);
+ } /* if (ssl_status == 1 && verify_peer == 1) */
+
} /* if (ups->conn == NULL) */
/* nut plugin: nut_read_one: upscli_list_start (adpos) failed: Protocol