[ejabberd] How to add new commands to ejabberdctl?

Badlop badlop at gmail.com
Fri Feb 21 19:10:31 MSK 2014


The function net_adm:ping expects an atom:
$ man 3erl net_adm | grep -A 4 "  ping("
       ping(Node) -> pong | pang
              Types:
                 Node = atom()

But you provide a string:
  Problem 'error function_clause' occurred executing the command.
  Stacktrace: [{net_adm,ping,["jabber01"]},

Solution: before passing the argument, convert it to atom:
  case net_adm:ping(list_to_atom(NodeName)) of 'pong' ->


--
Badlop
ProcessOne


On 21 February 2014 11:27, Horacio Sanson <hsanson at gmail.com> wrote:
> I am trying to add a new command to ejabberdctl to facilitate the
> configuration of clusters but I am having some problems. Below is my code:
>
>
> #############################################
> -module(mod_cluster).
>
> -behavior(gen_mod).
>
> -export([start/2,stop/1,cluster_test/1]).
>
> -include("ejabberd.hrl").
> -include("ejabberd_commands.hrl").
> -include("mod_roster.hrl").
> -include("jlib.hrl").
>
> start(_Host, _Opts) ->
>   ejabberd_commands:register_commands(commands()).
>
> stop(_Host) ->
>   ejabberd_commands:unregister_commands(commands()).
>
> commands() ->
>   [
>     #ejabberd_commands{name = cluster_test, tags = [server],
>                        desc = "Test connectivity with remote node",
>                        module = ?MODULE, function = cluster_test,
>                        args = [{node, string}],
>                        result = {res, rescode}}
>   ].
>
>
> cluster_test(NodeName) ->
>         case net_adm:ping(NodeName) of 'pong' ->
>                 io:format("server is reachable.~n"),
>                 ok;
>         _ ->
>                 io:format("server could NOT be reached.~n"),
>                 error
>         end.
>
> ##############################################
>
> This code adds a cluster_test() function that checks connectivity with
> remote ejabberd nodes. I took this code from [1].
>
> Then registers this function as a command to ejabberctl. The idea is to be
> able to run the function from a terminal like:
>
>   > sudo ejabberdctl cluster_test  ejabberd at domain.local
>
> If I use the debug console and call the function directly it works as
> expected but invoking it from the terminal gives this error:
>
> ###################################################
> Problem 'error function_clause' occurred executing the command.
> Stacktrace: [{net_adm,ping,["jabber01"]},
>              {mod_cluster,cluster_test,1},
>              {ejabberd_ctl,call_command,3},
>              {ejabberd_ctl,try_call_command,3},
>              {ejabberd_ctl,process2,3},
>              {ejabberd_ctl,process,1},
>              {rpc,'-handle_call_call/6-fun-0-',5}]
> ####################################################
>
> I used the code from mod_admin_extra [2] as base to implement this but I am
> totally lost about Erlang.
>
> Any tips on what I may be doing wrong are greatly appreciated.
>
> [1] -
> http://chad.ill.ac/post/35967173942/easy-ejabberd-clustering-guide-mnesia-mysql
>
> [2] -
> https://github.com/processone/ejabberd-contrib/blob/master/mod_admin_extra/src/mod_admin_extra.erl
>
> regards,
> Horacio
>
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd
>


More information about the ejabberd mailing list