plugin
This commit is contained in:
parent
554a7cbbd0
commit
25de5ee94d
28
CHANGELOG.md
28
CHANGELOG.md
|
@ -2,6 +2,34 @@
|
|||
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)
|
||||
-------------------------
|
||||
|
||||
|
|
|
@ -36,11 +36,14 @@
|
|||
-define(PRINT(Format, Args),
|
||||
io:format(Format, Args)).
|
||||
|
||||
-export([status/1, cluster/1,
|
||||
listeners/1,
|
||||
useradd/1, userdel/1,
|
||||
-export([status/1,
|
||||
broker/1,
|
||||
bridges/1, start_bridge/1, stop_bridge/1]).
|
||||
cluster/1,
|
||||
listeners/1,
|
||||
bridges/1,
|
||||
plugins/1,
|
||||
useradd/1,
|
||||
userdel/1]).
|
||||
|
||||
status([]) ->
|
||||
{InternalStatus, _ProvidedStatus} = init:get_status(),
|
||||
|
@ -97,23 +100,42 @@ listeners([]) ->
|
|||
?PRINT(" current_clients: ~p~n", [esockd:get_current_clients(Pid)])
|
||||
end, esockd:listeners()).
|
||||
|
||||
bridges([]) ->
|
||||
bridges(["list"]) ->
|
||||
lists:foreach(fun({{Node, Topic}, _Pid}) ->
|
||||
?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
|
||||
{ok, _} -> ?PRINT_MSG("bridge is started.~n");
|
||||
{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
|
||||
ok -> ?PRINT_MSG("bridge is stopped.~n");
|
||||
{error, Error} -> ?PRINT("error: ~p~n", [Error])
|
||||
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) ->
|
||||
SNode1 =
|
||||
case string:tokens(SNode, "@") of
|
||||
|
@ -132,3 +154,4 @@ node_name(SNode) ->
|
|||
end,
|
||||
list_to_atom(SNode1).
|
||||
|
||||
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
%%% SOFTWARE.
|
||||
%%%-----------------------------------------------------------------------------
|
||||
%%% @doc
|
||||
%%% emqttd plugin framework.
|
||||
%%% emqttd plugin.
|
||||
%%%
|
||||
%%% @end
|
||||
%%%-----------------------------------------------------------------------------
|
||||
|
||||
-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)
|
||||
if [ $# -gt 2 ]; then
|
||||
echo "Usage: $SCRIPT broker [stats | metrics]"
|
||||
echo "Usage: $SCRIPT broker [status | stats | metrics]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
@ -166,55 +166,45 @@ case "$1" in
|
|||
;;
|
||||
|
||||
bridges)
|
||||
if [ $# -gt 1 ]; then
|
||||
echo "Usage: $SCRIPT bridges"
|
||||
exit 1
|
||||
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 bridges $@
|
||||
;;
|
||||
|
||||
start_bridge)
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "Usage: $SCRIPT start_bridge <Node> <Topic>"
|
||||
if [[ $# -eq 2 ]] && [[ $2 = "list" ]]; then
|
||||
$NODETOOL rpc emqttd_ctl bridges list
|
||||
elif [ $# -eq 4 ]; then
|
||||
shift
|
||||
$NODETOOL rpc emqttd_ctl bridges $@
|
||||
else
|
||||
echo "Usage: "
|
||||
echo "$SCRIPT bridges list"
|
||||
echo "$SCRIPT bridges start <Node> <Topic>"
|
||||
echo "$SCRIPT bridges stop <Node> <Topic>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
;;
|
||||
plugins)
|
||||
# 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 start_bridge $@
|
||||
;;
|
||||
|
||||
stop_bridge)
|
||||
if [ $# -ne 3 ]; then
|
||||
echo "Usage: $SCRIPT stop_bridge <Node> <Topic>"
|
||||
if [ $# -eq 2 && $2 = "list"]; then
|
||||
$NODETOOL rpc emqttd_ctl plugins list
|
||||
elif [ $# -eq 3 ]; then
|
||||
shift
|
||||
$NODETOOL rpc emqttd_ctl plugins $@
|
||||
else
|
||||
echo "Usage: "
|
||||
echo "$SCRIPT plugins list"
|
||||
echo "$SCRIPT plugins load <Plugin>"
|
||||
echo "$SCRIPT plugins unload <Plugin>"
|
||||
exit 1
|
||||
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)
|
||||
if [ $# -gt 1 ]; then
|
||||
echo "Usage: $SCRIPT listeners"
|
||||
|
@ -233,15 +223,18 @@ case "$1" in
|
|||
|
||||
*)
|
||||
echo "Usage: $SCRIPT"
|
||||
echo " status #query emqttd status"
|
||||
echo " listeners #query emqttd listeners"
|
||||
echo " broker [stats | metrics] #query broker stats/metrics"
|
||||
echo " cluster [<Node>] #query or cluster nodes"
|
||||
echo " bridges #query bridges"
|
||||
echo " start_bridge <Node> <Topic> #start bridge"
|
||||
echo " stop_bridge <Node> <Topic> #stop bridge"
|
||||
echo " useradd <Username> <Password> #add user"
|
||||
echo " userdel <Username> #delete user"
|
||||
echo " status #query status"
|
||||
echo " broker [stats | metrics] #query broker stats or metrics"
|
||||
echo " cluster [<Node>] #query or cluster nodes"
|
||||
echo " plugins list #query loaded plugins"
|
||||
echo " plugins load <Plugin> #load plugin"
|
||||
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 " userdel <Username> #delete user"
|
||||
echo " listeners #query broker listeners"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
|
|
Loading…
Reference in New Issue