Merge branch 'collectd-4.9' into collectd-4.10
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 6 Nov 2010 11:08:20 +0000 (12:08 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 6 Nov 2010 11:08:20 +0000 (12:08 +0100)
Conflicts:
src/collectd.conf.in
src/python.c

14 files changed:
README
configure.in
contrib/collection3/etc/collection.conf
contrib/collection3/lib/Collectd/Graph/Common.pm
src/collectd-python.pod
src/collectd.h
src/curl_json.c
src/match_value.c
src/netapp.c
src/network.c
src/notify_email.c
src/python.c
src/utils_match.c
src/utils_tail.c

diff --git a/README b/README
index ade430c..5063069 100644 (file)
--- a/README
+++ b/README
@@ -586,6 +586,9 @@ Prerequisites
     Used to capture packets by the `dns' plugin.
     <http://www.tcpdump.org/>
 
+  * libperfstat (optional)
+    Used by various plugins to gather statistics under AIX.
+
   * libperl (optional)
     Obviously used by the `perl' plugin. The library has to be compiled with
     ithread support (introduced in Perl 5.6.0).
index 75ac706..a47fed0 100644 (file)
@@ -91,6 +91,10 @@ if test "x$ac_system" = "xSolaris"
 then
        AC_DEFINE(_POSIX_PTHREAD_SEMANTICS, 1, [Define to enforce POSIX thread semantics under Solaris.])
 fi
+if test "x$ac_system" = "xAIX"
+then
+       AC_DEFINE(_THREAD_SAFE_ERRNO, 1, [Define to use the thread-safe version of errno under AIX.])
+fi
 
 # Where to install .pc files.
 pkgconfigdir="${libdir}/pkgconfig"
index 9c5e3d1..3bb3d8b 100644 (file)
@@ -567,6 +567,16 @@ GraphWidth 400
 <Type ps_cputime>
   Module PsCputime
 </Type>
+<Type ps_disk_octets>
+  Module GenericIO
+  DataSources read write
+  DSName "read Read   "
+  DSName write Written
+  RRDTitle "Process disk traffic ({instance})"
+  RRDVerticalLabel "Bytes per second"
+# RRDOptions ...
+  RRDFormat "%5.1lf%s"
+</Type>
 <Type ps_rss>
   DataSources value
   DSName value RSS
index f88c22b..c6e2508 100644 (file)
@@ -106,7 +106,9 @@ sub group_files_by_plugin_instance
   for (my $i = 0; $i < @files; $i++)
   {
     my $file = $files[$i];
-    my $key = $file->{'plugin_instance'} || '';
+    my $key1 = $file->{'hostname'} || '';
+    my $key2 = $file->{'plugin_instance'} || '';
+    my $key = "$key1-$key2";
 
     $data->{$key} ||= [];
     push (@{$data->{$key}}, $file);
index 81a78e7..267296c 100644 (file)
@@ -1,3 +1,13 @@
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
 =head1 NAME
 
 collectd-python - Documentation of collectd's C<python plugin>
index 8849b30..e7fc4e3 100644 (file)
@@ -227,10 +227,6 @@ typedef bool _Bool;
 # include <kstat.h>
 #endif
 
-#if HAVE_SENSORS_SENSORS_H
-# include <sensors/sensors.h>
-#endif
-
 #ifndef PACKAGE_NAME
 #define PACKAGE_NAME "collectd"
 #endif
index 21deed6..0527dc8 100644 (file)
@@ -764,6 +764,7 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */
   if (db->yajl == NULL)
   {
     ERROR ("curl_json plugin: yajl_alloc failed.");
+    db->yajl = yprev;
     return (-1);
   }
 
index 9f02226..ae6282c 100644 (file)
@@ -53,9 +53,18 @@ struct mv_match_s
  */
 static void mv_free_match (mv_match_t *m) /* {{{ */
 {
+  int i;
+  
   if (m == NULL)
     return;
 
+  if (m->data_sources != NULL)
+  {
+    for (i = 0; i < m->data_sources_num; ++i)
+      free(m->data_sources[i]);
+    free(m->data_sources);
+  }
+  
   free (m);
 } /* }}} void mv_free_match */
 
index 317b0fe..c50b3db 100644 (file)
@@ -566,7 +566,7 @@ static int submit_values (const char *host, /* {{{ */
                const char *plugin_inst,
                const char *type, const char *type_inst,
                value_t *values, int values_len,
-               time_t timestamp)
+               time_t timestamp, int interval)
 {
        value_list_t vl = VALUE_LIST_INIT;
 
@@ -576,6 +576,9 @@ static int submit_values (const char *host, /* {{{ */
        if (timestamp > 0)
                vl.time = timestamp;
 
+       if (interval > 0)
+               vl.interval = interval;
+
        if (host != NULL)
                sstrncpy (vl.host, host, sizeof (vl.host));
        else
@@ -592,7 +595,7 @@ static int submit_values (const char *host, /* {{{ */
 
 static int submit_two_counters (const char *host, const char *plugin_inst, /* {{{ */
                const char *type, const char *type_inst, counter_t val0, counter_t val1,
-               time_t timestamp)
+               time_t timestamp, int interval)
 {
        value_t values[2];
 
@@ -600,23 +603,23 @@ static int submit_two_counters (const char *host, const char *plugin_inst, /* {{
        values[1].counter = val1;
 
        return (submit_values (host, plugin_inst, type, type_inst,
-                               values, 2, timestamp));
+                               values, 2, timestamp, interval));
 } /* }}} int submit_two_counters */
 
 static int submit_counter (const char *host, const char *plugin_inst, /* {{{ */
-               const char *type, const char *type_inst, counter_t counter, time_t timestamp)
+               const char *type, const char *type_inst, counter_t counter, time_t timestamp, int interval)
 {
        value_t v;
 
        v.counter = counter;
 
        return (submit_values (host, plugin_inst, type, type_inst,
-                               &v, 1, timestamp));
+                               &v, 1, timestamp, interval));
 } /* }}} int submit_counter */
 
 static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */
                const char *type, const char *type_inst, gauge_t val0, gauge_t val1,
-               time_t timestamp)
+               time_t timestamp, int interval)
 {
        value_t values[2];
 
@@ -624,18 +627,18 @@ static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ *
        values[1].gauge = val1;
 
        return (submit_values (host, plugin_inst, type, type_inst,
-                               values, 2, timestamp));
+                               values, 2, timestamp, interval));
 } /* }}} int submit_two_gauge */
 
 static int submit_double (const char *host, const char *plugin_inst, /* {{{ */
-               const char *type, const char *type_inst, double d, time_t timestamp)
+               const char *type, const char *type_inst, double d, time_t timestamp, int interval)
 {
        value_t v;
 
        v.gauge = (gauge_t) d;
 
        return (submit_values (host, plugin_inst, type, type_inst,
-                               &v, 1, timestamp));
+                               &v, 1, timestamp, interval));
 } /* }}} int submit_uint64 */
 
 /* Calculate hit ratio from old and new counters and submit the resulting
@@ -647,7 +650,8 @@ static int submit_cache_ratio (const char *host, /* {{{ */
                uint64_t new_misses,
                uint64_t old_hits,
                uint64_t old_misses,
-               time_t timestamp)
+               time_t timestamp,
+               int interval)
 {
        value_t v;
 
@@ -664,12 +668,12 @@ static int submit_cache_ratio (const char *host, /* {{{ */
        }
 
        return (submit_values (host, plugin_inst, "cache_ratio", type_inst,
-                               &v, 1, timestamp));
+                               &v, 1, timestamp, interval));
 } /* }}} int submit_cache_ratio */
 
 /* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
 static int submit_wafl_data (const char *hostname, const char *instance, /* {{{ */
-               cfg_wafl_t *old_data, const cfg_wafl_t *new_data)
+               cfg_wafl_t *old_data, const cfg_wafl_t *new_data, int interval)
 {
        /* Submit requested counters */
        if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_NAME_CACHE | HAVE_WAFL_NAME_CACHE)
@@ -677,28 +681,28 @@ static int submit_wafl_data (const char *hostname, const char *instance, /* {{{
                submit_cache_ratio (hostname, instance, "name_cache_hit",
                                new_data->name_cache_hit, new_data->name_cache_miss,
                                old_data->name_cache_hit, old_data->name_cache_miss,
-                               new_data->timestamp);
+                               new_data->timestamp, interval);
 
        if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_DIR_CACHE | HAVE_WAFL_FIND_DIR)
                        && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_FIND_DIR))
                submit_cache_ratio (hostname, instance, "find_dir_hit",
                                new_data->find_dir_hit, new_data->find_dir_miss,
                                old_data->find_dir_hit, old_data->find_dir_miss,
-                               new_data->timestamp);
+                               new_data->timestamp, interval);
 
        if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_BUF_CACHE | HAVE_WAFL_BUF_HASH)
                        && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_BUF_HASH))
                submit_cache_ratio (hostname, instance, "buf_hash_hit",
                                new_data->buf_hash_hit, new_data->buf_hash_miss,
                                old_data->buf_hash_hit, old_data->buf_hash_miss,
-                               new_data->timestamp);
+                               new_data->timestamp, interval);
 
        if (HAS_ALL_FLAGS (old_data->flags, CFG_WAFL_INODE_CACHE | HAVE_WAFL_INODE_CACHE)
                        && HAS_ALL_FLAGS (new_data->flags, HAVE_WAFL_INODE_CACHE))
                submit_cache_ratio (hostname, instance, "inode_cache_hit",
                                new_data->inode_cache_hit, new_data->inode_cache_miss,
                                old_data->inode_cache_hit, old_data->inode_cache_miss,
-                               new_data->timestamp);
+                               new_data->timestamp, interval);
 
        /* Clear old HAVE_* flags */
        old_data->flags &= ~HAVE_WAFL_ALL;
@@ -724,7 +728,7 @@ static int submit_wafl_data (const char *hostname, const char *instance, /* {{{
  * update flags appropriately. */
 static int submit_volume_perf_data (const char *hostname, /* {{{ */
                data_volume_perf_t *old_data,
-               const data_volume_perf_t *new_data)
+               const data_volume_perf_t *new_data, int interval)
 {
        char plugin_instance[DATA_MAX_NAME_LEN];
 
@@ -739,7 +743,7 @@ static int submit_volume_perf_data (const char *hostname, /* {{{ */
                        && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_BYTES_READ | HAVE_VOLUME_PERF_BYTES_WRITE))
        {
                submit_two_counters (hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
-                               (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp);
+                               (counter_t) new_data->read_bytes, (counter_t) new_data->write_bytes, new_data->timestamp, interval);
        }
 
        /* Check for and submit disk-operations values */
@@ -747,7 +751,7 @@ static int submit_volume_perf_data (const char *hostname, /* {{{ */
                        && HAS_ALL_FLAGS (new_data->flags, HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE))
        {
                submit_two_counters (hostname, plugin_instance, "disk_ops", /* type instance = */ NULL,
-                               (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp);
+                               (counter_t) new_data->read_ops, (counter_t) new_data->write_ops, new_data->timestamp, interval);
        }
 
        /* Check for, calculate and submit disk-latency values */
@@ -791,7 +795,7 @@ static int submit_volume_perf_data (const char *hostname, /* {{{ */
                }
 
                submit_two_gauge (hostname, plugin_instance, "disk_latency", /* type instance = */ NULL,
-                               latency_per_op_read, latency_per_op_write, new_data->timestamp);
+                               latency_per_op_read, latency_per_op_write, new_data->timestamp, interval);
        }
 
        /* Clear all HAVE_* flags. */
@@ -820,7 +824,7 @@ static int submit_volume_perf_data (const char *hostname, /* {{{ */
  */
 /* Data corresponding to <WAFL /> */
 static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* {{{ */
-               na_elem_t *data)
+               na_elem_t *data, int interval)
 {
        cfg_wafl_t perf_data;
        const char *plugin_inst;
@@ -899,7 +903,7 @@ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /*
                }
        }
 
-       return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data));
+       return (submit_wafl_data (hostname, plugin_inst, cfg_wafl, &perf_data, interval));
 } /* }}} void cna_handle_wafl_data */
 
 static int cna_setup_wafl (cfg_wafl_t *cw) /* {{{ */
@@ -973,7 +977,7 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */
                return (-1);
        }
 
-       status = cna_handle_wafl_data (host->name, host->cfg_wafl, data);
+       status = cna_handle_wafl_data (host->name, host->cfg_wafl, data, host->interval);
 
        if (status == 0)
                host->cfg_wafl->interval.last_read = now;
@@ -984,7 +988,7 @@ static int cna_query_wafl (host_config_t *host) /* {{{ */
 
 /* Data corresponding to <Disks /> */
 static int cna_handle_disk_data (const char *hostname, /* {{{ */
-               cfg_disk_t *cfg_disk, na_elem_t *data)
+               cfg_disk_t *cfg_disk, na_elem_t *data, int interval)
 {
        time_t timestamp;
        na_elem_t *instances;
@@ -1098,7 +1102,7 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */
 
        if ((cfg_disk->flags & CFG_DISK_BUSIEST) && (worst_disk != NULL))
                submit_double (hostname, "system", "percent", "disk_busy",
-                               worst_disk->disk_busy_percent, timestamp);
+                               worst_disk->disk_busy_percent, timestamp, interval);
 
        return (0);
 } /* }}} int cna_handle_disk_data */
@@ -1168,7 +1172,7 @@ static int cna_query_disk (host_config_t *host) /* {{{ */
                return (-1);
        }
 
-       status = cna_handle_disk_data (host->name, host->cfg_disk, data);
+       status = cna_handle_disk_data (host->name, host->cfg_disk, data, host->interval);
 
        if (status == 0)
                host->cfg_disk->interval.last_read = now;
@@ -1179,7 +1183,7 @@ static int cna_query_disk (host_config_t *host) /* {{{ */
 
 /* Data corresponding to <VolumePerf /> */
 static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
-               cfg_volume_perf_t *cvp, na_elem_t *data)
+               cfg_volume_perf_t *cvp, na_elem_t *data, int interval)
 {
        time_t timestamp;
        na_elem_t *elem_instances;
@@ -1264,7 +1268,7 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */
                        }
                } /* for (elem_counter) */
 
-               submit_volume_perf_data (hostname, v, &perf_data);
+               submit_volume_perf_data (hostname, v, &perf_data, interval);
        } /* for (volume) */
 
        return (0);
@@ -1339,7 +1343,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */
                return (-1);
        }
 
-       status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data);
+       status = cna_handle_volume_perf_data (host->name, host->cfg_volume_perf, data, host->interval);
 
        if (status == 0)
                host->cfg_volume_perf->interval.last_read = now;
@@ -1350,7 +1354,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */
 
 /* Data corresponding to <VolumeUsage /> */
 static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
-               cfg_volume_usage_t *cfg_volume)
+               cfg_volume_usage_t *cfg_volume, int interval)
 {
        data_volume_usage_t *v;
 
@@ -1398,32 +1402,32 @@ static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
                if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_FREE))
                        submit_double (hostname, /* plugin instance = */ plugin_instance,
                                        "df_complex", "free",
-                                       (double) norm_free, /* timestamp = */ 0);
+                                       (double) norm_free, /* timestamp = */ 0, interval);
 
                if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SIS_SAVED))
                        submit_double (hostname, /* plugin instance = */ plugin_instance,
                                        "df_complex", "sis_saved",
-                                       (double) sis_saved, /* timestamp = */ 0);
+                                       (double) sis_saved, /* timestamp = */ 0, interval);
 
                if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_NORM_USED))
                        submit_double (hostname, /* plugin instance = */ plugin_instance,
                                        "df_complex", "used",
-                                       (double) norm_used, /* timestamp = */ 0);
+                                       (double) norm_used, /* timestamp = */ 0, interval);
 
                if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_RSVD))
                        submit_double (hostname, /* plugin instance = */ plugin_instance,
                                        "df_complex", "snap_reserved",
-                                       (double) snap_reserve_free, /* timestamp = */ 0);
+                                       (double) snap_reserve_free, /* timestamp = */ 0, interval);
 
                if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED | HAVE_VOLUME_USAGE_SNAP_RSVD))
                        submit_double (hostname, /* plugin instance = */ plugin_instance,
                                        "df_complex", "snap_reserve_used",
-                                       (double) snap_reserve_used, /* timestamp = */ 0);
+                                       (double) snap_reserve_used, /* timestamp = */ 0, interval);
 
                if (HAS_ALL_FLAGS (v->flags, HAVE_VOLUME_USAGE_SNAP_USED))
                        submit_double (hostname, /* plugin instance = */ plugin_instance,
                                        "df_complex", "snap_normal_used",
-                                       (double) snap_norm_used, /* timestamp = */ 0);
+                                       (double) snap_norm_used, /* timestamp = */ 0, interval);
 
                /* Clear all the HAVE_* flags */
                v->flags &= ~HAVE_VOLUME_USAGE_ALL;
@@ -1650,7 +1654,7 @@ static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
                } /* }}} end of 32-bit workaround */
        } /* for (elem_volume) */
 
-       return (cna_submit_volume_usage_data (host->name, cfg_volume));
+       return (cna_submit_volume_usage_data (host->name, cfg_volume, host->interval));
 } /* }}} int cna_handle_volume_usage_data */
 
 static int cna_setup_volume_usage (cfg_volume_usage_t *cvu) /* {{{ */
@@ -1714,7 +1718,7 @@ static int cna_query_volume_usage (host_config_t *host) /* {{{ */
 
 /* Data corresponding to <System /> */
 static int cna_handle_system_data (const char *hostname, /* {{{ */
-               cfg_system_t *cfg_system, na_elem_t *data)
+               cfg_system_t *cfg_system, na_elem_t *data, int interval)
 {
        na_elem_t *instances;
        na_elem_t *counter;
@@ -1786,27 +1790,27 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */
                                && (value > 0) && (strlen(name) > 4)
                                && (!strcmp(name + strlen(name) - 4, "_ops"))) {
                        submit_counter (hostname, instance, "disk_ops_complex", name,
-                                       (counter_t) value, timestamp);
+                                       (counter_t) value, timestamp, interval);
                }
        } /* for (counter) */
 
        if ((cfg_system->flags & CFG_SYSTEM_DISK)
                        && (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
                submit_two_counters (hostname, instance, "disk_octets", NULL,
-                               disk_read, disk_written, timestamp);
+                               disk_read, disk_written, timestamp, interval);
                                
        if ((cfg_system->flags & CFG_SYSTEM_NET)
                        && (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
                submit_two_counters (hostname, instance, "if_octets", NULL,
-                               net_recv, net_sent, timestamp);
+                               net_recv, net_sent, timestamp, interval);
 
        if ((cfg_system->flags & CFG_SYSTEM_CPU)
                        && (HAS_ALL_FLAGS (counter_flags, 0x10 | 0x20)))
        {
                submit_counter (hostname, instance, "cpu", "system",
-                               cpu_busy, timestamp);
+                               cpu_busy, timestamp, interval);
                submit_counter (hostname, instance, "cpu", "idle",
-                               cpu_total - cpu_busy, timestamp);
+                               cpu_total - cpu_busy, timestamp, interval);
        }
 
        return (0);
@@ -1862,7 +1866,7 @@ static int cna_query_system (host_config_t *host) /* {{{ */
                return (-1);
        }
 
-       status = cna_handle_system_data (host->name, host->cfg_system, data);
+       status = cna_handle_system_data (host->name, host->cfg_system, data, host->interval);
 
        if (status == 0)
                host->cfg_system->interval.last_read = now;
index 457637b..412b457 100644 (file)
@@ -31,6 +31,7 @@
 #include "utils_fbhash.h"
 #include "utils_avltree.h"
 #include "utils_cache.h"
+#include "utils_complain.h"
 
 #include "network.h"
 
@@ -917,6 +918,8 @@ static int parse_packet (sockent_t *se,
 static int parse_part_sign_sha256 (sockent_t *se, /* {{{ */
     void **ret_buffer, size_t *ret_buffer_len, int flags)
 {
+  static c_complain_t complain_no_users = C_COMPLAIN_INIT_STATIC;
+
   char *buffer;
   size_t buffer_len;
   size_t buffer_offset;
@@ -938,8 +941,9 @@ static int parse_part_sign_sha256 (sockent_t *se, /* {{{ */
 
   if (se->data.server.userdb == NULL)
   {
-    NOTICE ("network plugin: Received signed network packet but can't verify "
-        "it because no user DB has been configured. Will accept it.");
+    c_complain (LOG_NOTICE, &complain_no_users,
+        "network plugin: Received signed network packet but can't verify it "
+        "because no user DB has been configured. Will accept it.");
     return (0);
   }
 
index 62e1c48..0aed27f 100644 (file)
@@ -1,6 +1,7 @@
 /**
  * collectd - src/notify_email.c
  * Copyright (C) 2008  Oleg King
+ * Copyright (C) 2010  Florian Forster
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -18,6 +19,7 @@
  *
  * Authors:
  *   Oleg King <king2 at kaluga.ru>
+ *   Florian Forster <octo at collectd.org>
  **/
 
 #include "collectd.h"
@@ -26,6 +28,7 @@
 
 #include <auth-client.h>
 #include <libesmtp.h>
+#include <pthread.h>
 
 #define MAXSTRING               256
 
@@ -45,6 +48,7 @@ static char **recipients;
 static int recipients_len = 0;
 
 static smtp_session_t session;
+static pthread_mutex_t session_lock = PTHREAD_MUTEX_INITIALIZER;
 static smtp_message_t message;
 static auth_context_t authctx = NULL;
 
@@ -113,17 +117,23 @@ static int notify_email_init (void)
 {
   char server[MAXSTRING];
 
+  ssnprintf(server, sizeof (server), "%s:%i",
+      (smtp_host == NULL) ? DEFAULT_SMTP_HOST : smtp_host,
+      smtp_port);
+
+  pthread_mutex_lock (&session_lock);
+
   auth_client_init();
-  if (!(session = smtp_create_session ())) {
+
+  session = smtp_create_session ();
+  if (session == NULL) {
+    pthread_mutex_unlock (&session_lock);
     ERROR ("notify_email plugin: cannot create SMTP session");
     return (-1);
   }
 
   smtp_set_monitorcb (session, monitor_cb, NULL, 1);
   smtp_set_hostname (session, hostname_g);
-  ssnprintf(server, sizeof (server), "%s:%i",
-      (smtp_host == NULL) ? DEFAULT_SMTP_HOST : smtp_host,
-      smtp_port);
   smtp_set_server (session, server);
 
   if (smtp_user && smtp_password) {
@@ -133,18 +143,30 @@ static int notify_email_init (void)
   }
 
   if ( !smtp_auth_set_context (session, authctx)) {
+    pthread_mutex_unlock (&session_lock);
     ERROR ("notify_email plugin: cannot set SMTP auth context");
     return (-1);   
   }
 
+  pthread_mutex_unlock (&session_lock);
   return (0);
 } /* int notify_email_init */
 
 static int notify_email_shutdown (void)
 {
-  smtp_destroy_session (session);
-  auth_destroy_context (authctx);
+  pthread_mutex_lock (&session_lock);
+
+  if (session != NULL)
+    smtp_destroy_session (session);
+  session = NULL;
+
+  if (authctx != NULL)
+    auth_destroy_context (authctx);
+  authctx = NULL;
+
   auth_client_exit();
+
+  pthread_mutex_unlock (&session_lock);
   return (0);
 } /* int notify_email_shutdown */
 
@@ -248,7 +270,16 @@ static int notify_email_notification (const notification_t *n,
       n->host,
       n->message);
 
+  pthread_mutex_lock (&session_lock);
+
+  if (session == NULL) {
+    /* Initialization failed or we're in the process of shutting down. */
+    pthread_mutex_unlock (&session_lock);
+    return (-1);
+  }
+
   if (!(message = smtp_add_message (session))) {
+    pthread_mutex_unlock (&session_lock);
     ERROR ("notify_email plugin: cannot set SMTP message");
     return (-1);   
   }
@@ -264,6 +295,7 @@ static int notify_email_notification (const notification_t *n,
     char buf[MAXSTRING];
     ERROR ("notify_email plugin: SMTP server problem: %s",
         smtp_strerror (smtp_errno (), buf, sizeof buf));
+    pthread_mutex_unlock (&session_lock);
     return (-1);
   } else {
     const smtp_status_t *status;
@@ -274,6 +306,7 @@ static int notify_email_notification (const notification_t *n,
     smtp_enumerate_recipients (message, print_recipient_status, NULL);
   }
 
+  pthread_mutex_unlock (&session_lock);
   return (0);
 } /* int notify_email_notification */
 
index 8772cd1..c056b5b 100644 (file)
@@ -978,6 +978,7 @@ PyMODINIT_FUNC PyInit_collectd(void) {
 
 static int cpy_config(oconfig_item_t *ci) {
        int i;
+       char *argv = "";
        PyObject *sys, *tb;
        PyObject *sys_path;
        PyObject *module;
@@ -1017,6 +1018,9 @@ static int cpy_config(oconfig_item_t *ci) {
                cpy_log_exception("python initialization");
                return 1;
        }
+       PySys_SetArgv(1, &argv);
+       PyList_SetSlice(sys_path, 0, 1, NULL);
+
 #ifdef IS_PY3K
        module = PyImport_ImportModule("collectd");
 #else
index 4d4b57d..062bcfe 100644 (file)
@@ -228,7 +228,7 @@ cu_match_t *match_create_callback (const char *regex, const char *excluderegex,
     return (NULL);
   memset (obj, '\0', sizeof (cu_match_t));
 
-  status = regcomp (&obj->regex, regex, REG_EXTENDED);
+  status = regcomp (&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
   if (status != 0)
   {
     ERROR ("Compiling the regular expression \"%s\" failed.", regex);
index 904a521..5b7551d 100644 (file)
@@ -220,6 +220,8 @@ int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
 
        while (42)
        {
+               size_t len;
+
                status = cu_tail_readline (obj, buf, buflen);
                if (status != 0)
                {
@@ -232,6 +234,13 @@ int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
                if (buf[0] == 0)
                        break;
 
+               len = strlen (buf);
+               while (len > 0) {
+                       if (buf[len - 1] != '\n')
+                               break;
+                       buf[len - 1] = '\0';
+               }
+
                status = callback (data, buf, buflen);
                if (status != 0)
                {