85 lines
2.4 KiB
Erlang
85 lines
2.4 KiB
Erlang
%%--------------------------------------------------------------------
|
|
%% Copyright (c) 2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
%%--------------------------------------------------------------------
|
|
-module(emqx_bridge_opents).
|
|
|
|
-include_lib("typerefl/include/types.hrl").
|
|
-include_lib("hocon/include/hoconsc.hrl").
|
|
-include_lib("emqx_resource/include/emqx_resource.hrl").
|
|
|
|
-import(hoconsc, [mk/2, enum/1, ref/2]).
|
|
|
|
-export([
|
|
conn_bridge_examples/1
|
|
]).
|
|
|
|
-export([
|
|
namespace/0,
|
|
roots/0,
|
|
fields/1,
|
|
desc/1
|
|
]).
|
|
|
|
%% -------------------------------------------------------------------------------------------------
|
|
%% api
|
|
conn_bridge_examples(Method) ->
|
|
[
|
|
#{
|
|
<<"opents">> => #{
|
|
summary => <<"OpenTSDB Bridge">>,
|
|
value => values(Method)
|
|
}
|
|
}
|
|
].
|
|
|
|
values(_Method) ->
|
|
#{
|
|
enable => true,
|
|
type => opents,
|
|
name => <<"foo">>,
|
|
server => <<"http://127.0.0.1:4242">>,
|
|
pool_size => 8,
|
|
resource_opts => #{
|
|
worker_pool_size => 1,
|
|
health_check_interval => ?HEALTHCHECK_INTERVAL_RAW,
|
|
batch_size => ?DEFAULT_BATCH_SIZE,
|
|
batch_time => ?DEFAULT_BATCH_TIME,
|
|
query_mode => async,
|
|
max_buffer_bytes => ?DEFAULT_BUFFER_BYTES
|
|
}
|
|
}.
|
|
|
|
%% -------------------------------------------------------------------------------------------------
|
|
%% Hocon Schema Definitions
|
|
namespace() -> "bridge_opents".
|
|
|
|
roots() -> [].
|
|
|
|
fields("config") ->
|
|
[
|
|
{enable, mk(boolean(), #{desc => ?DESC("config_enable"), default => true})}
|
|
] ++ emqx_resource_schema:fields("resource_opts") ++
|
|
emqx_bridge_opents_connector:fields(config);
|
|
fields("post") ->
|
|
[type_field(), name_field() | fields("config")];
|
|
fields("put") ->
|
|
fields("config");
|
|
fields("get") ->
|
|
emqx_bridge_schema:status_fields() ++ fields("post").
|
|
|
|
desc("config") ->
|
|
?DESC("desc_config");
|
|
desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" ->
|
|
["Configuration for OpenTSDB using `", string:to_upper(Method), "` method."];
|
|
desc(_) ->
|
|
undefined.
|
|
|
|
%% -------------------------------------------------------------------------------------------------
|
|
%% internal
|
|
|
|
type_field() ->
|
|
{type, mk(enum([opents]), #{required => true, desc => ?DESC("desc_type")})}.
|
|
|
|
name_field() ->
|
|
{name, mk(binary(), #{required => true, desc => ?DESC("desc_name")})}.
|