src/utils_logtail.[ch]: Implement a module that parses logfiles using the `utils_tail...
[collectd.git] / src / utils_logtail.h
1 /*
2  * collectd - src/utils_logtail.h
3  * Copyright (C) 2007-2008  C-Ware, Inc.
4  * Copyright (C) 2008       Florian Forster
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation; only version 2 of the License is applicable.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  *
19  * Authors:
20  *   Luke Heberling <lukeh at c-ware.com>
21  *   Florian Forster <octo at verplant.org>
22  *
23  * Description:
24  *   Encapsulates useful code to plugins which must parse a log file.
25  *
26  */
27
28 #include "utils_match.h"
29
30 struct cu_logtail_s;
31 typedef struct cu_logtail_s cu_logtail_t;
32
33 struct cu_logtail_simple_s
34 {
35   char plugin[DATA_MAX_NAME_LEN];
36   char plugin_instance[DATA_MAX_NAME_LEN];
37   char type[DATA_MAX_NAME_LEN];
38   char type_instance[DATA_MAX_NAME_LEN];
39 };
40 typedef struct cu_logtail_simple_s cu_logtail_simple_t;
41
42 /*
43  * NAME
44  *   logtail_create
45  *
46  * DESCRIPTION
47  *   Allocates, initializes and returns a new `cu_logtail_t' object.
48  *
49  * PARAMETERS
50  *   `filename'  The name to read data from.
51  *   `plugin'    The plugin name to use when dispatching values.
52  *
53  * RETURN VALUE
54  *   Returns NULL upon failure, non-NULL otherwise.
55  */
56 cu_logtail_t *logtail_create (const char *filename);
57
58 /*
59  * NAME
60  *   logtail_destroy
61  *
62  * DESCRIPTION
63  *   Releases resources used by the `cu_logtail_t' object.
64  *
65  * PARAMETERS
66  *   The object to destroy.
67  */
68 void logtail_destroy (cu_logtail_t *obj);
69
70 /*
71  * NAME
72  *   logtail_add_match_simple
73  *
74  * DESCRIPTION
75  *   Adds a match, in form of a regular expression, to the `cu_logtail_t'
76  *   object. The values matched by that regular expression are dispatched to
77  *   the daemon using the supplied `type' and `type_instance' fields.
78  *
79  * PARAMETERS
80  *   `obj'
81  *   `type'
82  *   `type_instance'
83  *   `match_ds_type'
84  *   `regex'
85  *
86  * RETURN VALUE
87  *   Zero upon success, non-zero otherwise.
88  */
89 int logtail_add_match (cu_logtail_t *obj, cu_match_t *match,
90     int (*submit_match) (cu_match_t *match, void *user_data),
91     void *user_data,
92     void (*free_user_data) (void *user_data));
93
94 int logtail_add_match_simple (cu_logtail_t *obj,
95     const char *regex, int ds_type,
96     const char *plugin, const char *plugin_instance,
97     const char *type, const char *type_instance);
98
99 /*
100  * NAME
101  *   logtail_read
102  *
103  * DESCRIPTION
104  *   Looks for more data in the log file, sends each line
105  *   through the given function, and submits the counters to
106  *   collectd.
107  *
108  * PARAMETERS
109  *   `instances' The handle used to identify the plugin.
110  *
111  *   `func'      The function used to parse each line from the log.
112  *
113  *   `plugin'    The name of the plugin.
114  *
115  *   `names'     An array of counter names in the same order as the
116  *               counters themselves.
117  *
118  * RETURN VALUE
119  *   Zero on success, nonzero on failure.
120 */
121 int logtail_read (cu_logtail_t *obj);
122
123 /* vim: set sw=2 sts=2 ts=8 : */