1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3 /* Fluent Bit
4 * ==========
5 * Copyright (C) 2019-2021 The Fluent Bit Authors
6 * Copyright (C) 2015-2018 Treasure Data Inc.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 #ifndef FLB_FILTER_H
22 #define FLB_FILTER_H
23
24 #include <fluent-bit/flb_info.h>
25
26 #ifdef FLB_HAVE_REGEX
27 #include <fluent-bit/flb_regex.h>
28 #endif
29
30 #ifdef FLB_HAVE_METRICS
31 #include <fluent-bit/flb_metrics.h>
32 #endif
33
34 #include <fluent-bit/flb_config.h>
35 #include <fluent-bit/flb_config_map.h>
36 #include <fluent-bit/flb_input_chunk.h>
37 #include <msgpack.h>
38
39 #include <cmetrics/cmetrics.h>
40 #include <cmetrics/cmt_counter.h>
41
42 #define FLB_FILTER_MODIFIED 1
43 #define FLB_FILTER_NOTOUCH 2
44
45 struct flb_input_instance;
46 struct flb_filter_instance;
47
48 struct flb_filter_plugin {
49 int flags; /* Flags (not available at the moment */
50 char *name; /* Filter short name */
51 char *description; /* Description */
52
53 /* Config map */
54 struct flb_config_map *config_map;
55
56 /* Callbacks */
57 int (*cb_init) (struct flb_filter_instance *, struct flb_config *, void *);
58 int (*cb_filter) (const void *, size_t,
59 const char *, int,
60 void **, size_t *,
61 struct flb_filter_instance *,
62 void *, struct flb_config *);
63 int (*cb_exit) (void *, struct flb_config *);
64
65 struct mk_list _head; /* Link to parent list (config->filters) */
66 };
67
68 struct flb_filter_instance {
69 int id; /* instance id */
70 int log_level; /* instance log level */
71 char name[32]; /* numbered name */
72 char *alias; /* alias name */
73 char *match; /* match rule based on Tags */
74 #ifdef FLB_HAVE_REGEX
75 struct flb_regex *match_regex; /* match rule (regex) based on Tags */
76 #endif
77 void *context; /* Instance local context */
78 void *data;
79 struct flb_filter_plugin *p; /* original plugin */
80 struct mk_list properties; /* config properties */
81 struct mk_list *config_map; /* configuration map */
82
83 struct mk_list _head; /* link to config->filters */
84
85 /*
86 * CMetrics
87 * --------
88 */
89 struct cmt *cmt; /* parent context */
90 struct cmt_counter *cmt_add_records; /* m: filter_add_records_total */
91 struct cmt_counter *cmt_drop_records; /* m: filter_drop_records_total */
92
93 #ifdef FLB_HAVE_METRICS
94 struct flb_metrics *metrics; /* metrics */
95 #endif
96
97 /* Keep a reference to the original context this instance belongs to */
98 struct flb_config *config;
99 };
100
flb_filter_config_map_set(struct flb_filter_instance * ins,void * context)101 static inline int flb_filter_config_map_set(struct flb_filter_instance *ins,
102 void *context)
103 {
104 return flb_config_map_set(&ins->properties, ins->config_map, context);
105 }
106
107 int flb_filter_set_property(struct flb_filter_instance *ins,
108 const char *k, const char *v);
109 const char *flb_filter_get_property(const char *key,
110 struct flb_filter_instance *ins);
111
112 struct flb_filter_instance *flb_filter_new(struct flb_config *config,
113 const char *filter, void *data);
114 void flb_filter_exit(struct flb_config *config);
115 void flb_filter_do(struct flb_input_chunk *ic,
116 const void *data, size_t bytes,
117 const char *tag, int tag_len,
118 struct flb_config *config);
119 const char *flb_filter_name(struct flb_filter_instance *ins);
120 int flb_filter_init_all(struct flb_config *config);
121 void flb_filter_set_context(struct flb_filter_instance *ins, void *context);
122 void flb_filter_instance_destroy(struct flb_filter_instance *ins);
123
124 #endif
125