plugin
This commit is contained in:
parent
554a7cbbd0
commit
25de5ee94d
28
CHANGELOG.md
28
CHANGELOG.md
|
@ -2,6 +2,34 @@
|
||||||
eMQTTD ChangeLog
|
eMQTTD ChangeLog
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
v0.8.0-alpha (2015-03-20)
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
MQTT/WebSocket
|
||||||
|
|
||||||
|
v0.7.0-alpha (2015-03-20)
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Admin Console
|
||||||
|
|
||||||
|
v0.6.0-alpha (2015-03-20)
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Plugin Architecture
|
||||||
|
|
||||||
|
Mnesia Authentication
|
||||||
|
|
||||||
|
MySQL Auth
|
||||||
|
|
||||||
|
LDAP Auth
|
||||||
|
|
||||||
|
PG Auth
|
||||||
|
|
||||||
|
Mnesia ACL
|
||||||
|
|
||||||
|
MySQL ACL
|
||||||
|
|
||||||
|
|
||||||
v0.5.0-alpha (2015-03-12)
|
v0.5.0-alpha (2015-03-12)
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,14 @@
|
||||||
-define(PRINT(Format, Args),
|
-define(PRINT(Format, Args),
|
||||||
io:format(Format, Args)).
|
io:format(Format, Args)).
|
||||||
|
|
||||||
-export([status/1, cluster/1,
|
-export([status/1,
|
||||||
listeners/1,
|
|
||||||
useradd/1, userdel/1,
|
|
||||||
broker/1,
|
broker/1,
|
||||||
bridges/1, start_bridge/1, stop_bridge/1]).
|
cluster/1,
|
||||||
|
listeners/1,
|
||||||
|
bridges/1,
|
||||||
|
plugins/1,
|
||||||
|
useradd/1,
|
||||||
|
userdel/1]).
|
||||||
|
|
||||||
status([]) ->
|
status([]) ->
|
||||||
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
||||||
|
@ -97,23 +100,42 @@ listeners([]) ->
|
||||||
?PRINT(" current_clients: ~p~n", [esockd:get_current_clients(Pid)])
|
?PRINT(" current_clients: ~p~n", [esockd:get_current_clients(Pid)])
|
||||||
end, esockd:listeners()).
|
end, esockd:listeners()).
|
||||||
|
|
||||||
bridges([]) ->
|
bridges(["list"]) ->
|
||||||
lists:foreach(fun({{Node, Topic}, _Pid}) ->
|
lists:foreach(fun({{Node, Topic}, _Pid}) ->
|
||||||
?PRINT("bridge: ~s ~s~n", [Node, Topic])
|
?PRINT("bridge: ~s ~s~n", [Node, Topic])
|
||||||
end, emqttd_bridge_sup:bridges()).
|
end, emqttd_bridge_sup:bridges());
|
||||||
|
|
||||||
start_bridge([SNode, Topic]) ->
|
bridges(["start", SNode, Topic]) ->
|
||||||
case emqttd_bridge_sup:start_bridge(list_to_atom(SNode), list_to_binary(Topic)) of
|
case emqttd_bridge_sup:start_bridge(list_to_atom(SNode), list_to_binary(Topic)) of
|
||||||
{ok, _} -> ?PRINT_MSG("bridge is started.~n");
|
{ok, _} -> ?PRINT_MSG("bridge is started.~n");
|
||||||
{error, Error} -> ?PRINT("error: ~p~n", [Error])
|
{error, Error} -> ?PRINT("error: ~p~n", [Error])
|
||||||
end.
|
end;
|
||||||
|
|
||||||
stop_bridge([SNode, Topic]) ->
|
bridges(["stop", SNode, Topic]) ->
|
||||||
case emqttd_bridge_sup:stop_bridge(list_to_atom(SNode), list_to_binary(Topic)) of
|
case emqttd_bridge_sup:stop_bridge(list_to_atom(SNode), list_to_binary(Topic)) of
|
||||||
ok -> ?PRINT_MSG("bridge is stopped.~n");
|
ok -> ?PRINT_MSG("bridge is stopped.~n");
|
||||||
{error, Error} -> ?PRINT("error: ~p~n", [Error])
|
{error, Error} -> ?PRINT("error: ~p~n", [Error])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
plugins(["list"]) ->
|
||||||
|
Plugins = emqttd_plugin_manager:list(),
|
||||||
|
lists:foreach(fun({Name, Attrs}) ->
|
||||||
|
?PRINT("plugin ~s~n", [Name]),
|
||||||
|
[?PRINT(" ~s:~p~n", [Attr, Val]) || {Attr, Val} <- Attrs]
|
||||||
|
end, Plugins);
|
||||||
|
|
||||||
|
plugins(["load", Name]) ->
|
||||||
|
case emqttd_plugin_manager:load(list_to_atom(Name)) of
|
||||||
|
ok -> ?PRINT("plugin ~s is loaded successfully.~n", [Name]);
|
||||||
|
{error, Reason} -> ?PRINT("error: ~s~n", [Reason])
|
||||||
|
end;
|
||||||
|
|
||||||
|
plugins(["unload", Name]) ->
|
||||||
|
case emqttd_plugin_manager:load(list_to_atom(Name)) of
|
||||||
|
ok -> ?PRINT("plugin ~s is unloaded successfully.~n", [Name]);
|
||||||
|
{error, Reason} -> ?PRINT("error: ~s~n", [Reason])
|
||||||
|
end.
|
||||||
|
|
||||||
node_name(SNode) ->
|
node_name(SNode) ->
|
||||||
SNode1 =
|
SNode1 =
|
||||||
case string:tokens(SNode, "@") of
|
case string:tokens(SNode, "@") of
|
||||||
|
@ -132,3 +154,4 @@ node_name(SNode) ->
|
||||||
end,
|
end,
|
||||||
list_to_atom(SNode1).
|
list_to_atom(SNode1).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,11 @@
|
||||||
%%% SOFTWARE.
|
%%% SOFTWARE.
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
%%% @doc
|
%%% @doc
|
||||||
%%% emqttd plugin framework.
|
%%% emqttd plugin.
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
%%% @end
|
||||||
%%%-----------------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------------
|
||||||
|
|
||||||
-module(emqttd_plugin).
|
-module(emqttd_plugin).
|
||||||
|
|
||||||
|
-record(plugin, {name, app, attrs}).
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
%%%-----------------------------------------------------------------------------
|
||||||
|
%%% @Copyright (C) 2012-2015, Feng Lee <feng@emqtt.io>
|
||||||
|
%%%
|
||||||
|
%%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
%%% of this software and associated documentation files (the "Software"), to deal
|
||||||
|
%%% in the Software without restriction, including without limitation the rights
|
||||||
|
%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
%%% copies of the Software, and to permit persons to whom the Software is
|
||||||
|
%%% furnished to do so, subject to the following conditions:
|
||||||
|
%%%
|
||||||
|
%%% The above copyright notice and this permission notice shall be included in all
|
||||||
|
%%% copies or substantial portions of the Software.
|
||||||
|
%%%
|
||||||
|
%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
%%% SOFTWARE.
|
||||||
|
%%%-----------------------------------------------------------------------------
|
||||||
|
%%% @doc
|
||||||
|
%%% emqttd plugin manager.
|
||||||
|
%%%
|
||||||
|
%%% @end
|
||||||
|
%%%-----------------------------------------------------------------------------
|
||||||
|
-module(emqttd_plugin_manager).
|
||||||
|
|
||||||
|
-export([list/0, load/1, unload/1]).
|
||||||
|
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% List all loaded plugins.
|
||||||
|
%%
|
||||||
|
%% @end
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
list() ->
|
||||||
|
[].
|
||||||
|
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Load Plugin.
|
||||||
|
%%
|
||||||
|
%% @end
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
load(Name) when is_atom(Name) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
%% @doc
|
||||||
|
%% Unload Plugin.
|
||||||
|
%%
|
||||||
|
%% @end
|
||||||
|
%%------------------------------------------------------------------------------
|
||||||
|
unload(Name) when is_atom(Name) ->
|
||||||
|
ok.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ case "$1" in
|
||||||
|
|
||||||
broker)
|
broker)
|
||||||
if [ $# -gt 2 ]; then
|
if [ $# -gt 2 ]; then
|
||||||
echo "Usage: $SCRIPT broker [stats | metrics]"
|
echo "Usage: $SCRIPT broker [status | stats | metrics]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -166,55 +166,45 @@ case "$1" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
bridges)
|
bridges)
|
||||||
if [ $# -gt 1 ]; then
|
|
||||||
echo "Usage: $SCRIPT bridges"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# Make sure the local node IS running
|
# Make sure the local node IS running
|
||||||
RES=`$NODETOOL ping`
|
RES=`$NODETOOL ping`
|
||||||
if [ "$RES" != "pong" ]; then
|
if [ "$RES" != "pong" ]; then
|
||||||
echo "emqttd is not running!"
|
echo "emqttd is not running!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [[ $# -eq 2 ]] && [[ $2 = "list" ]]; then
|
||||||
|
$NODETOOL rpc emqttd_ctl bridges list
|
||||||
|
elif [ $# -eq 4 ]; then
|
||||||
shift
|
shift
|
||||||
|
|
||||||
$NODETOOL rpc emqttd_ctl bridges $@
|
$NODETOOL rpc emqttd_ctl bridges $@
|
||||||
;;
|
else
|
||||||
|
echo "Usage: "
|
||||||
start_bridge)
|
echo "$SCRIPT bridges list"
|
||||||
if [ $# -ne 3 ]; then
|
echo "$SCRIPT bridges start <Node> <Topic>"
|
||||||
echo "Usage: $SCRIPT start_bridge <Node> <Topic>"
|
echo "$SCRIPT bridges stop <Node> <Topic>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
plugins)
|
||||||
# Make sure the local node IS running
|
# Make sure the local node IS running
|
||||||
RES=`$NODETOOL ping`
|
RES=`$NODETOOL ping`
|
||||||
if [ "$RES" != "pong" ]; then
|
if [ "$RES" != "pong" ]; then
|
||||||
echo "emqttd is not running!"
|
echo "emqttd is not running!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [ $# -eq 2 && $2 = "list"]; then
|
||||||
|
$NODETOOL rpc emqttd_ctl plugins list
|
||||||
|
elif [ $# -eq 3 ]; then
|
||||||
shift
|
shift
|
||||||
|
$NODETOOL rpc emqttd_ctl plugins $@
|
||||||
$NODETOOL rpc emqttd_ctl start_bridge $@
|
else
|
||||||
;;
|
echo "Usage: "
|
||||||
|
echo "$SCRIPT plugins list"
|
||||||
stop_bridge)
|
echo "$SCRIPT plugins load <Plugin>"
|
||||||
if [ $# -ne 3 ]; then
|
echo "$SCRIPT plugins unload <Plugin>"
|
||||||
echo "Usage: $SCRIPT stop_bridge <Node> <Topic>"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make sure the local node IS running
|
|
||||||
RES=`$NODETOOL ping`
|
|
||||||
if [ "$RES" != "pong" ]; then
|
|
||||||
echo "emqttd is not running!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shift
|
|
||||||
|
|
||||||
$NODETOOL rpc emqttd_ctl stop_bridge $@
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
listeners)
|
listeners)
|
||||||
if [ $# -gt 1 ]; then
|
if [ $# -gt 1 ]; then
|
||||||
echo "Usage: $SCRIPT listeners"
|
echo "Usage: $SCRIPT listeners"
|
||||||
|
@ -233,15 +223,18 @@ case "$1" in
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Usage: $SCRIPT"
|
echo "Usage: $SCRIPT"
|
||||||
echo " status #query emqttd status"
|
echo " status #query status"
|
||||||
echo " listeners #query emqttd listeners"
|
echo " broker [stats | metrics] #query broker stats or metrics"
|
||||||
echo " broker [stats | metrics] #query broker stats/metrics"
|
|
||||||
echo " cluster [<Node>] #query or cluster nodes"
|
echo " cluster [<Node>] #query or cluster nodes"
|
||||||
echo " bridges #query bridges"
|
echo " plugins list #query loaded plugins"
|
||||||
echo " start_bridge <Node> <Topic> #start bridge"
|
echo " plugins load <Plugin> #load plugin"
|
||||||
echo " stop_bridge <Node> <Topic> #stop bridge"
|
echo " plugins unload <Plugin> #unload plugin"
|
||||||
|
echo " bridges list #query bridges"
|
||||||
|
echo " bridges start <Node> <Topic> #start bridge"
|
||||||
|
echo " bridges stop <Node> <Topic> #stop bridge"
|
||||||
echo " useradd <Username> <Password> #add user"
|
echo " useradd <Username> <Password> #add user"
|
||||||
echo " userdel <Username> #delete user"
|
echo " userdel <Username> #delete user"
|
||||||
|
echo " listeners #query broker listeners"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue