src/utils_logtail.[ch]: Add a module to provide facilities for logfile tailing.
[collectd.git] / src / utils_logtail.h
1 /*
2  * collectd - src/utils_logtail.h
3  * Copyright (C) 2007-2008  C-Ware, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Author:
19  *   Luke Heberling <lukeh at c-ware.com>
20  *
21  * Description:
22  *   Encapsulates useful code to plugins which must parse a log file.
23  *
24  */
25
26 #include "utils_llist.h"
27 #include "utils_tail.h"
28
29 struct logtail_instance_s;
30 typedef struct logtail_instance_s logtail_instance_t;
31
32 /*
33  * NAME
34  *   logtail_term
35  *
36  * DESCRIPTION
37  *   Call to release resources associated with the plugin.
38  *
39  * PARAMETERS
40  *   `instances' The handle used to identify the plugin.
41  *
42  * RETURN VALUE
43  *   Zero on success, nonzero on failure.
44  */
45 int logtail_term (llist_t **instances);
46
47 /*
48  * NAME
49  *   logtail_term
50  *
51  * DESCRIPTION
52  *   Call to initialize the plugin
53  *
54  * PARAMETERS
55  *   `instances' The handle used to identify the plugin.
56  *
57  * RETURN VALUE
58  *   Zero on success, nonzero on failure.
59  */
60 int logtail_init (llist_t **instances);
61
62 /*
63  * NAME
64  *   logtail_read
65  *
66  * DESCRIPTION
67  *   Looks for more data in the log file, sends each line
68  *   through the given function, and submits the counters to
69  *   collectd.
70  *
71  * PARAMETERS
72  *   `instances' The handle used to identify the plugin.
73  *
74  *   `func'      The function used to parse each line from the log.
75  *
76  *   `plugin'    The name of the plugin.
77  *
78  *   `names'     An array of counter names in the same order as the
79  *               counters themselves.
80  *
81  * RETURN VALUE
82  *   Zero on success, nonzero on failure.
83  */
84 int logtail_read (llist_t **instances, tailfunc *func, char *plugin,
85                 char **names);
86
87 /*
88  * NAME
89  *   logtail_config
90  *
91  * DESCRIPTION
92  *   Configures the logtail instance for the given plugin.
93  *
94  * PARAMETERS
95  *   `instances' The handle used to identify the plugin.
96  *
97  *   `ci'        The configuration item from collectd.
98  *
99  *   `plugin'    The name of the plugin.
100  *
101  *   `names'     An array of counter names in the same order as the
102  *               counters themselves.
103  *
104  *   `default_file' The default log file if none is found in the
105  *               configuration.
106  *
107  *   `default_cache_size' The default cache size if none is found in the
108  *               configuration.
109  *
110  * RETURN VALUE
111  *   Zero on success, nonzero on failure.
112  */
113 int logtail_config (llist_t **instances, oconfig_item_t *ci, char *plugin,
114                         char **names, char *default_file,
115                         int default_cache_size);
116
117 /*
118  * NAME
119  *   logtail_counters
120  *
121  * DESCRIPTION
122  *   Returns the counters maintained for the plugin.
123  *
124  * PARAMETERS
125  *   `instance' The handle used to identify the logtail instance.
126  *
127  */
128 unsigned long *logtail_counters (logtail_instance_t *instance);
129
130 /*
131  * NAME
132  *   logtail_cache
133  *
134  * DESCRIPTION
135  *   Stores the data in the cache.
136  *
137  * PARAMETERS
138  *   `instance' The handle used to identify the logtail instance.
139  *
140  *   `plugin'   The name of the plugin.
141  *
142  *   `key'      The key to identify the cached data.
143  *   
144  *   `data'     The data to cache.
145  *
146  *   `len'      The length of the data to cache.
147  *
148  * RETURN VALUE
149  *   Zero on success, nonzero on failure.
150  */
151 int logtail_cache (logtail_instance_t *instance, char *plugin, char *key,
152                 void **data, int len);
153
154 /*
155  * NAME
156  *   logtail_decache
157  *
158  * DESCRIPTION
159  *   Removes the data from the cache.
160  *
161  * PARAMETERS
162  *   `instance' The handle used to identify the logtail instance.
163  *
164  *   `key'      The key to identify the cached data.
165  *   
166  */
167 void logtail_decache (logtail_instance_t *instance, char *key);
168