[ejabberd] How to add new commands to ejabberdctl?

Horacio Sanson hsanson at gmail.com
Sat Feb 22 04:47:11 MSK 2014


Thanks a lot,

I am new to Erlang and had no idea about Atoms. Now everything works
perfectly.

Horacio


On Sat, Feb 22, 2014 at 12:10 AM, Badlop <badlop at gmail.com> wrote:

> 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
> >
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20140222/8a2108c8/attachment.html>


More information about the ejabberd mailing list