/src/fluent-bit/src/http_server/api/v1/plugins.c
Line | Count | Source |
1 | | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* Fluent Bit |
4 | | * ========== |
5 | | * Copyright (C) 2015-2026 The Fluent Bit Authors |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #include <fluent-bit/flb_info.h> |
21 | | #include <fluent-bit/flb_pack.h> |
22 | | #include <fluent-bit/flb_input.h> |
23 | | #include <fluent-bit/flb_filter.h> |
24 | | #include <fluent-bit/flb_output.h> |
25 | | #include <fluent-bit/flb_sds.h> |
26 | | #include <fluent-bit/flb_http_server.h> |
27 | | #include <fluent-bit/http_server/flb_hs_utils.h> |
28 | | #include <msgpack.h> |
29 | | |
30 | | /* API: List all built-in plugins */ |
31 | | static int cb_plugins(struct flb_hs *hs, |
32 | | struct flb_http_request *request, |
33 | | struct flb_http_response *response) |
34 | 0 | { |
35 | 0 | int len; |
36 | 0 | flb_sds_t out_buf; |
37 | 0 | msgpack_packer mp_pck; |
38 | 0 | msgpack_sbuffer mp_sbuf; |
39 | 0 | struct mk_list *head; |
40 | 0 | struct flb_input_plugin *in; |
41 | 0 | struct flb_filter_plugin *filter; |
42 | 0 | struct flb_output_plugin *out; |
43 | 0 | struct flb_config *config = hs->config; |
44 | |
|
45 | 0 | (void) request; |
46 | | |
47 | | /* initialize buffers */ |
48 | 0 | msgpack_sbuffer_init(&mp_sbuf); |
49 | 0 | msgpack_packer_init(&mp_pck, &mp_sbuf, msgpack_sbuffer_write); |
50 | |
|
51 | 0 | msgpack_pack_map(&mp_pck, 1); |
52 | 0 | msgpack_pack_str(&mp_pck, 7); |
53 | 0 | msgpack_pack_str_body(&mp_pck, "plugins", 7); |
54 | | |
55 | | /* |
56 | | * plugins are: inputs, filters, outputs |
57 | | */ |
58 | 0 | msgpack_pack_map(&mp_pck, 3); |
59 | | |
60 | | /* Inputs */ |
61 | 0 | msgpack_pack_str(&mp_pck, 6); |
62 | 0 | msgpack_pack_str_body(&mp_pck, "inputs", 6); |
63 | 0 | len = mk_list_size(&config->in_plugins); |
64 | 0 | msgpack_pack_array(&mp_pck, len); |
65 | 0 | mk_list_foreach(head, &hs->config->in_plugins) { |
66 | 0 | in = mk_list_entry(head, struct flb_input_plugin, _head); |
67 | 0 | len = strlen(in->name); |
68 | 0 | msgpack_pack_str(&mp_pck, len); |
69 | 0 | msgpack_pack_str_body(&mp_pck, in->name, len); |
70 | 0 | } |
71 | | |
72 | | /* Filters */ |
73 | 0 | msgpack_pack_str(&mp_pck, 7); |
74 | 0 | msgpack_pack_str_body(&mp_pck, "filters", 7); |
75 | 0 | len = mk_list_size(&config->filter_plugins); |
76 | 0 | msgpack_pack_array(&mp_pck, len); |
77 | 0 | mk_list_foreach(head, &config->filter_plugins) { |
78 | 0 | filter = mk_list_entry(head, struct flb_filter_plugin, _head); |
79 | 0 | len = strlen(filter->name); |
80 | 0 | msgpack_pack_str(&mp_pck, len); |
81 | 0 | msgpack_pack_str_body(&mp_pck, filter->name, len); |
82 | 0 | } |
83 | | |
84 | | /* Outputs */ |
85 | 0 | msgpack_pack_str(&mp_pck, 7); |
86 | 0 | msgpack_pack_str_body(&mp_pck, "outputs", 7); |
87 | 0 | len = mk_list_size(&config->out_plugins); |
88 | 0 | msgpack_pack_array(&mp_pck, len); |
89 | 0 | mk_list_foreach(head, &config->out_plugins) { |
90 | 0 | out = mk_list_entry(head, struct flb_output_plugin, _head); |
91 | 0 | len = strlen(out->name); |
92 | 0 | msgpack_pack_str(&mp_pck, len); |
93 | 0 | msgpack_pack_str_body(&mp_pck, out->name, len); |
94 | 0 | } |
95 | | |
96 | | /* Export to JSON */ |
97 | 0 | out_buf = flb_msgpack_raw_to_json_sds(mp_sbuf.data, mp_sbuf.size, FLB_TRUE); |
98 | 0 | msgpack_sbuffer_destroy(&mp_sbuf); |
99 | |
|
100 | 0 | flb_hs_response_set_payload(response, |
101 | 0 | 200, |
102 | 0 | FLB_HS_CONTENT_TYPE_JSON, |
103 | 0 | out_buf, |
104 | 0 | flb_sds_len(out_buf)); |
105 | |
|
106 | 0 | flb_sds_destroy(out_buf); |
107 | 0 | return 0; |
108 | 0 | } |
109 | | |
110 | | /* Perform registration */ |
111 | | int api_v1_plugins(struct flb_hs *hs) |
112 | 0 | { |
113 | 0 | return flb_hs_register_endpoint(hs, "/api/v1/plugins", |
114 | 0 | FLB_HS_ROUTE_EXACT, cb_plugins); |
115 | 0 | } |