Merge branch 'collectd-5.4'
[collectd.git] / src / utils_tail_match.c
index ae1f4f7..8776ad1 100644 (file)
@@ -3,22 +3,27 @@
  * Copyright (C) 2007-2008  C-Ware, Inc.
  * Copyright (C) 2008       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
- * Free Software Foundation; only version 2 of the License is applicable.
+ * 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:
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Author:
  *   Luke Heberling <lukeh at c-ware.com>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  *
  * Description:
  *   Encapsulates useful code to plugins which must parse a log file.
@@ -37,6 +42,7 @@ struct cu_tail_match_simple_s
   char plugin_instance[DATA_MAX_NAME_LEN];
   char type[DATA_MAX_NAME_LEN];
   char type_instance[DATA_MAX_NAME_LEN];
+  cdtime_t interval;
 };
 typedef struct cu_tail_match_simple_s cu_tail_match_simple_t;
 
@@ -54,6 +60,7 @@ struct cu_tail_match_s
   int flags;
   cu_tail_t *tail;
 
+  cdtime_t interval;
   cu_tail_match_match_t *matches;
   size_t matches_num;
 };
@@ -88,6 +95,7 @@ static int simple_submit_match (cu_match_t *match, void *user_data)
   sstrncpy (vl.type_instance, data->type_instance,
       sizeof (vl.type_instance));
 
+  vl.interval = data->interval;
   plugin_dispatch_values (&vl);
 
   if (match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
@@ -103,7 +111,7 @@ static int tail_callback (void *data, char *buf,
     int __attribute__((unused)) buflen)
 {
   cu_tail_match_t *obj = (cu_tail_match_t *) data;
-  int i;
+  size_t i;
 
   for (i = 0; i < obj->matches_num; i++)
     match_apply (obj->matches[i].match, buf);
@@ -135,7 +143,7 @@ cu_tail_match_t *tail_match_create (const char *filename)
 
 void tail_match_destroy (cu_tail_match_t *obj)
 {
-  int i;
+  size_t i;
 
   if (obj == NULL)
     return;
@@ -180,6 +188,7 @@ int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
   obj->matches = temp;
   obj->matches_num++;
 
+  DEBUG ("tail_match_add_match interval %lf", CDTIME_T_TO_DOUBLE(((cu_tail_match_simple_t *)user_data)->interval));
   temp = obj->matches + (obj->matches_num - 1);
 
   temp->match = match;
@@ -191,15 +200,15 @@ int tail_match_add_match (cu_tail_match_t *obj, cu_match_t *match,
 } /* int tail_match_add_match */
 
 int tail_match_add_match_simple (cu_tail_match_t *obj,
-    const char *regex, int ds_type,
+    const char *regex, const char *excluderegex, int ds_type,
     const char *plugin, const char *plugin_instance,
-    const char *type, const char *type_instance)
+    const char *type, const char *type_instance, const cdtime_t interval)
 {
   cu_match_t *match;
   cu_tail_match_simple_t *user_data;
   int status;
 
-  match = match_create_simple (regex, ds_type);
+  match = match_create_simple (regex, excluderegex, ds_type);
   if (match == NULL)
     return (-1);
 
@@ -221,6 +230,8 @@ int tail_match_add_match_simple (cu_tail_match_t *obj,
     sstrncpy (user_data->type_instance, type_instance,
        sizeof (user_data->type_instance));
 
+  user_data->interval = interval;
+
   status = tail_match_add_match (obj, match, simple_submit_match,
       user_data, free);
 
@@ -237,7 +248,7 @@ int tail_match_read (cu_tail_match_t *obj)
 {
   char buffer[4096];
   int status;
-  int i;
+  size_t i;
 
   status = cu_tail_read (obj->tail, buffer, sizeof (buffer), tail_callback,
       (void *) obj);