Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

publish FS register events

  • Loading branch information...
commit 580837eaa4bc2d26d8575ca80e79b47554a564b9 1 parent 377e83c
James Aimonetti authored
View
0  applications/log/.placeholder
No changes.
View
0  ecallmgr/log/.placeholder
No changes.
View
36 ecallmgr/src/ecallmgr_fs_node.erl
@@ -72,8 +72,13 @@ monitor_loop(Node, #handler_state{stats=#node_stats{created_channels=Cr, destroy
EvtName = get_value(<<"Event-Name">>, Data),
format_log(info, "FS_NODE(~p): Evt: ~p~n", [self(), EvtName]),
case EvtName of
- <<"HEARTBEAT">> -> monitor_loop(Node, S#handler_state{stats=Stats#node_stats{last_heartbeat=erlang:now()}});
- _ -> monitor_loop(Node, S)
+ <<"HEARTBEAT">> ->
+ monitor_loop(Node, S#handler_state{stats=Stats#node_stats{last_heartbeat=erlang:now()}});
+ <<"CUSTOM">> ->
+ spawn(fun() -> process_custom_data(Data, S#handler_state.amqp_host, S#handler_state.app_vsn) end),
+ monitor_loop(Node, S);
+ _ ->
+ monitor_loop(Node, S)
end;
{event, [UUID | Data]} ->
EvtName = get_value(<<"Event-Name">>, Data),
@@ -180,3 +185,30 @@ process_status([[$U,$P, $ | Uptime], SessSince, Sess30, SessMax, CPU]) ->
,{sessions_max, whistle_util:to_integer(lists:flatten(SessMaxNum))}
,{cpu, lists:flatten(CPUNum)}
].
+
+process_custom_data(Data, Host, AppVsn) ->
+ case get_value(<<"Event-Subclass">>, Data) of
+ undefined -> ok;
+ <<"sofia::register">> -> publish_register_event(Data, Host, AppVsn);
+ _ -> ok
+ end.
+
+publish_register_event(Data, Host, AppVsn) ->
+ Keys = ?OPTIONAL_REG_SUCCESS_HEADERS ++ ?REG_SUCCESS_HEADERS,
+ DefProp = whistle_api:default_headers(<<>>, <<"directory">>, <<"reg_success">>, ?MODULE, AppVsn),
+ ApiProp = lists:foldl(fun(K, Api) ->
+ Lk = binary_to_lower(K),
+ case props:get_value(Lk, Data) of
+ undefined -> Api;
+ V -> [{K, V} | Api]
+ end
+ end, DefProp, Keys),
+ case whistle_api:reg_sucess(ApiProp) of
+ {error, E} -> format_log(error, "FS_NODE.custom_data: Failed API message creation: ~p~n", [E]);
+ {ok, JSON} ->
+ amqp_util:broadcast_publish(Host, JSON, <<"application/json">>)
+ end.
+
+-spec(binary_to_lower/1 :: (B :: binary()) -> binary()).
+binary_to_lower(B) when is_binary(B) ->
+ whistle_util:to_binary(string:to_lower(whistle_util:to_list(B))).
View
20 utils/src/whistle_api.erl
@@ -23,7 +23,7 @@
-export([default_headers/5, extract_defaults/1]).
%% Authentication and Routing
--export([auth_req/1, auth_resp/1, route_req/1, route_resp/1, route_resp_route/1, route_win/1]).
+-export([auth_req/1, auth_resp/1, reg_success/1, route_req/1, route_resp/1, route_resp_route/1, route_win/1]).
%% Resources
-export([resource_req/1, resource_resp/1, resource_error/1]).
@@ -37,7 +37,7 @@
]).
%% Validation functions
--export([auth_req_v/1, auth_resp_v/1, route_req_v/1, route_resp_v/1, route_resp_route_v/1, route_win_v/1
+-export([auth_req_v/1, auth_resp_v/1, reg_success_v/1, route_req_v/1, route_resp_v/1, route_resp_route_v/1, route_win_v/1
,call_event_v/1, error_resp_v/1, play_req_v/1, record_req_v/1, store_req_v/1, store_amqp_resp_v/1
,store_http_resp_v/1, tones_req_v/1, tones_req_tone_v/1, queue_req_v/1, bridge_req_v/1
,bridge_req_endpoint_v/1, answer_req_v/1, park_req_v/1, play_collect_digits_req_v/1
@@ -121,6 +121,22 @@ auth_resp_v(Prop) ->
validate(Prop, ?AUTH_RESP_HEADERS, ?AUTH_RESP_VALUES, ?AUTH_RESP_TYPES).
%%--------------------------------------------------------------------
+%% @doc Registration Success - see wiki
+%% Takes proplist, creates JSON string or error
+%% @end
+%%--------------------------------------------------------------------
+-spec(reg_success/1 :: (Prop :: proplist()) -> tuple(ok, iolist()) | tuple(error, string())).
+reg_success(Prop) ->
+ case reg_success_v(Prop) of
+ true -> build_message(Prop, ?REG_SUCCESS_HEADERS, ?OPTIONAL_REG_SUCCESS_HEADERS);
+ false -> {error, "Proplist failed validation for reg_success"}
+ end.
+
+-spec(reg_success_v/1 :: (Prop :: proplist()) -> boolean()).
+reg_success_v(Prop) ->
+ validate(Prop, ?REG_SUCCESS_HEADERS, ?REG_SUCCESS_VALUES, ?REG_SUCCESS_TYPES).
+
+%%--------------------------------------------------------------------
%% @doc Dialplan Route Request - see wiki
%% Takes proplist, creates JSON string or error
%% @end
View
11 utils/src/whistle_api.hrl
@@ -91,6 +91,17 @@
,{<<"Tenant-ID">>, fun is_binary/1}
]).
+%% Registration Success
+-define(REG_SUCCESS_HEADERS, [<<"Event-Timestamp">>, <<"From-User">>, <<"From-Host">>, <<"Contact">>, <<"RPid">>
+ ,<<"Expires">>, <<"To-User">>, <<"To-Host">>, <<"Network-IP">>, <<"Network-Port">>
+ , <<"Username">>, <<"Realm">>
+ ]).
+-define(OPTIONAL_REG_SUCCESS_HEADERS, [<<"Status">>, <<"User-Agent">>]).
+-define(REG_SUCCESS_VALUES, [{<<"Event-Category">>, <<"directory">>}
+ ,{<<"Event-Name">>, <<"reg_success">>}
+ ]).
+-define(REG_SUCCESS_TYPES, []).
+
%% Route Requests - http://corp.switchfreedom.com/mediawiki/index.php/Resource_Control_%28Call_Setup_/_Teardown%29
-define(ROUTE_REQ_HEADERS, [<<"Msg-ID">>, <<"To">>, <<"From">>, <<"Call-ID">>
,<<"Caller-ID-Name">>, <<"Caller-ID-Number">>
Please sign in to comment.
Something went wrong with that request. Please try again.