Skip to content

Commit

Permalink
system fixes (2600hz#2864)
Browse files Browse the repository at this point in the history
* remove duplicated system alert

kapps_call_command:store_file already does this.

* add support for mod_kazoo 1.4

* update system default templates

adds http_headers processing

* unneeded / unwanted loop running_apps

if the env KAZOO_APPS= then it will keep displaying log messages about
initializing from env

* fix subject in system_report

* groups reply_headers into http_headers for template processing

* catch restore_system_template error
  • Loading branch information
lazedo authored and fenollp committed Dec 5, 2016
1 parent 27e37a1 commit 3ef84b7
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 25 deletions.
14 changes: 1 addition & 13 deletions applications/callflow/src/module/cf_voicemail.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1301,21 +1301,9 @@ new_message(AttachmentName, Length, #mailbox{mailbox_number=BoxNum
],
case kvm_message:new(Call, NewMsgProps) of
'ok' -> send_mwi_update(Box, Call);
{'error', Call1, Msg} ->
system_report(Msg, Call1)
{'error', _, _Msg} -> lager:warning("failed to save voice mail message recorded media : ~p", [_Msg])
end.

-spec system_report(text(), kapps_call:call()) -> 'ok'.
system_report(Msg, Call) ->
Notify = props:filter_undefined(
[{<<"Subject">>, <<"failed to store voicemail recorded media">>}
,{<<"Message">>, iolist_to_binary(Msg)}
,{<<"Details">>, kapps_call:to_json(Call)}
,{<<"Account-ID">>, kapps_call:account_id(Call)}
| kz_api:default_headers(?APP_NAME, ?APP_VERSION)
]),
kz_amqp_worker:cast(Notify, fun kapi_notifications:publish_system_alert/1).

%%--------------------------------------------------------------------
%% @private
%% @doc
Expand Down
12 changes: 10 additions & 2 deletions applications/ecallmgr/src/ecallmgr_fs_node_command.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ exec_cmd(<<"send_http">>, Args, JObj, Node, Options) ->
lager:debug("received http_send command for node ~s with version ~s", [Node, Version]),
Url = kz_json:get_ne_binary_value(<<"Url">>, Args),
File = kz_json:get_value(<<"File-Name">>, Args),
Method = <<"http_", (kz_json:get_value(<<"Http-Method">>, Args, <<"put">>))/binary>>,
HttpFun = case Version >= <<"mod_kazoo v1.4">> of
'true' -> <<"kz_http_">>;
'false' -> <<"http_">>
end,
Method = <<HttpFun/binary, (kz_json:get_value(<<"Http-Method">>, Args, <<"put">>))/binary>>,
Default = ecallmgr_config:is_true([?NODE_CMD_CONFIG, <<"send_http">>, <<"delete_on_success">>], 'false'),
DeleteOnSuccess = kz_json:is_true(<<"Delete-On-Success">>, JObj, Default),
send_http(Node, Version, File, Url, Method, JObj, DeleteOnSuccess);
Expand Down Expand Up @@ -91,7 +95,7 @@ send_http(Node, Version, File, Url, Method, JObj, DeleteOnSuccess) ->
end.

send_http_api_and_callback_funs(Version)->
case Version >= <<"mod_kazoo v1.3">> of
case Version >= <<"mod_kazoo v1.4">> of
'true' -> {fun freeswitch:bgapi4/5, fun send_http_cb/4};
'false' -> {fun freeswitch:bgapi/5, fun send_http_cb/3}
end.
Expand All @@ -110,6 +114,10 @@ send_http_cb('ok', <<"+OK", _/binary>>, _FSProps, [JobId, JObj, DeleteOnSuccess,
lager:debug("processed http_send command with success : ~s", [JobId]),
_ = maybe_delete_file(Node, File, DeleteOnSuccess),
reply_success(JObj);
send_http_cb(_, <<"-ERR ", Reply/binary>>, [_ | FSProps], [JobId, JObj | _]) ->
lager:debug("error processing http_send : ~p : ~s", [Reply, JobId]),
Props = ecallmgr_util:unserialize_fs_props(FSProps),
reply_error(Reply, kz_json:from_list(Props), JObj);
send_http_cb(_, Reply, [_ | FSProps], [JobId, JObj | _]) ->
lager:debug("error processing http_send : ~p : ~s", [Reply, JobId]),
Props = ecallmgr_util:unserialize_fs_props(FSProps),
Expand Down
124 changes: 123 additions & 1 deletion applications/teletype/priv/templates/system_alert.html
Original file line number Diff line number Diff line change
@@ -1 +1,123 @@
<html><head><meta charset="utf-8" /></head><body><h2>Alert</h2><p>{{message}}</p>{% if request %}<h2>Producer</h2><table cellpadding="4" cellspacing="0" border="0">{% for key, value in request %}<tr><td>{{ key }}: </td><td>{{ value }}</td></tr>{% endfor %}</table>{% endif %}{% if details %}<h2>Details</h2><table cellpadding="4" cellspacing="0" border="0">{% for key, value in details %}<tr><td>{{ key }}: </td><td>{{ value }}</td></tr>{% endfor %}</table>{% endif %}{% if callflow %}<h2>Callflow</h2><table cellpadding="4" cellspacing="0" border="0">{% for key, value in callflow %}<tr><td>{{ key }}: </td><td>{{ value }}</td></tr>{% endfor %}</table>{% endif %}{% if error_details %}<h2>Error Details</h2><table cellpadding="4" cellspacing="0" border="0">{% for key, value in error_details %}<tr><td>{{ key }}: </td><td>{{ value }}</td></tr>{% endfor %}</table>{% endif %}{% if key_store %}<h2>Key Value Store</h2><table cellpadding="4" cellspacing="0" border="0">{% for key, value in key_store %}<tr><td>{{ key }}: </td><td>{{ value }}</td></tr>{% endfor %}</table>{% endif %}{% if channel_vars %}<h2>Channel Vars</h2><table cellpadding="4" cellspacing="0" border="0">{% for key, value in channel_vars %}<tr><td>{{ key }}: </td><td>{{ value }}</td></tr>{% endfor %}</table>{% endif %}{% if sip_headers %}<h2>SIP Headers</h2><table cellpadding="4" cellspacing="0" border="0">{% for key, value in sip_headers %}<tr><td>{{ key }}: </td><td>{{ value }}</td></tr>{% endfor %}</table>{% endif %}{% if account %}<h2>Account</h2><table cellpadding="4" cellspacing="0" border="0"><tr><td>Account ID: </td><td>{{account.id}}</td></tr><tr><td>Account Name: </td><td>{{account.name}}</td></tr><tr><td>Account Realm: </td><td>{{account.realm}}</td></tr></table>{% endif %}{% if user %}<h2>Admin</h2><table cellpadding="4" cellspacing="0" border="0"><tr><td>Name: </td><td>{{user.first_name}} {{user.last_name}}</td></tr><tr><td>Email: </td><td>{{user.email}}</td></tr><tr><td>Timezone: </td><td>{{user.timezone}}</td></tr></table>{% endif %}{% if account.pvt_wnm_numbers %}<h2>Phone Numbers</h2><ul>{% for number in account.pvt_wnm_numbers %}<li>{{number}}</li>{% endfor %}</ul>{% endif %}</body></html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<h2>Alert</h2>
<p>{{message}}</p>
{% if request %}
<h2>Producer</h2>
<table cellpadding="4" cellspacing="0" border="0">
{% for key, value in request %}
<tr>
<td>{{ key }}:</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}{% if details %}
<h2>Details</h2>
<table cellpadding="4" cellspacing="0" border="0">
{% for key, value in details %}
<tr>
<td>{{ key }}:</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}{% if callflow %}
<h2>Callflow</h2>
<table cellpadding="4" cellspacing="0" border="0">
{% for key, value in callflow %}
<tr>
<td>{{ key }}:</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}{% if error_details %}
<h2>Error Details</h2>
<table cellpadding="4" cellspacing="0" border="0">
{% for key, value in error_details %}
<tr>
<td>{{ key }}:</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}{% if http_headers %}
<h2>HTTP Headers</h2>
{% for header in http_headers %}
<li>{{ header }}</li>
{% endfor %}
{% endif %}{% if key_store %}
<h2>Key Value Store</h2>
<table cellpadding="4" cellspacing="0" border="0">
{% for key, value in key_store %}
<tr>
<td>{{ key }}:</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}{% if channel_vars %}
<h2>Channel Vars</h2>
<table cellpadding="4" cellspacing="0" border="0">
{% for key, value in channel_vars %}
<tr>
<td>{{ key }}:</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}{% if sip_headers %}
<h2>SIP Headers</h2>
<table cellpadding="4" cellspacing="0" border="0">
{% for key, value in sip_headers %}
<tr>
<td>{{ key }}:</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endif %}{% if account %}
<h2>Account</h2>
<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td>Account ID:</td>
<td>{{account.id}}</td>
</tr>
<tr>
<td>Account Name:</td>
<td>{{account.name}}</td>
</tr>
<tr>
<td>Account Realm:</td>
<td>{{account.realm}}</td>
</tr>
</table>
{% endif %}{% if user %}
<h2>Admin</h2>
<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td>Name:</td>
<td>{{user.first_name}} {{user.last_name}}</td>
</tr>
<tr>
<td>Email:</td>
<td>{{user.email}}</td>
</tr>
<tr>
<td>Timezone:</td>
<td>{{user.timezone}}</td>
</tr>
</table>
{% endif %}{% if account.pvt_wnm_numbers %}
<h2>Phone Numbers</h2>
<ul>
{% for number in account.pvt_wnm_numbers %}
<li>{{number}}</li>{% endfor %}
</ul>
{% endif %}
</body>
</html>
3 changes: 3 additions & 0 deletions applications/teletype/priv/templates/system_alert.text
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Alert
{% endif %}{% if error_details %}Error Details
{% for key, value in error_details %}{{ key }}: {{ value }}
{% endfor %}
{% endif %}{% if http_headers %}HTTP Headers
{% for header in http_headers %}{{ header }}
{% endfor %}
{% endif %}{% if key_store %}Key Value Store
{% for key, value in key_store %}{{ key }}: {{ value }}
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion applications/teletype/src/teletype_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ restore_system_template(TemplateId) ->

Mod = kz_util:to_atom(<<"teletype_", ModId/binary>>, 'true'),
io:format(" re-initializing template ~s~n", [ModId]),
Mod:init(),
catch(Mod:init()),
io:format(" finished~n").

list_system_templates() ->
Expand Down
2 changes: 2 additions & 0 deletions applications/teletype/src/templates/teletype_system_alert.erl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ details_groups([{<<"cf_flow">>, V} | KS], {Group, Acc}) ->
details_groups(KS, {Group, details_groups(V, {<<"callflow">>, Acc})});
details_groups([{<<"error_details">>, V} | KS], {Group, Acc}) ->
details_groups(KS, {Group, details_groups(V, {<<"error_details">>, Acc})});
details_groups([{<<"reply_headers">>, V} | KS], {Group, Acc}) ->
details_groups(KS, {Group, details_groups(V, {<<"http_headers">>, Acc})});
details_groups([{<<"cf_", _/binary>>,_}=KV | KS], {Group, Acc}) ->
details_groups(KS, {Group, add_to_group(<<"callflow">>, KV, Acc)});
details_groups([KV | KS], {Group, Acc}) ->
Expand Down
8 changes: 1 addition & 7 deletions core/kazoo_apps/src/kapps_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,7 @@ sysconf_first(_, _) -> 'true'.

-spec list_apps() -> atoms().
list_apps() ->
case get_running_apps() of
[] ->
[kz_util:to_atom(KApp, 'true')
|| KApp <- start_which_kapps()
];
Resp -> [App || {App, _, _} <- Resp]
end.
[App || {App, _, _} <- get_running_apps()].

%%%===================================================================
%%% Internal functions
Expand Down
2 changes: 1 addition & 1 deletion core/kazoo_apps/src/kapps_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ system_report(Subject, Msg, Call) ->
AppName = kapps_call:application_name(Call),
AppVersion = kapps_call:application_version(Call),
Notify = props:filter_undefined(
[{<<"Subject">>, Subject}
[{<<"Subject">>, iolist_to_binary(Subject)}
,{<<"Message">>, iolist_to_binary(Msg)}
,{<<"Details">>, kapps_call:to_json(Call)}
,{<<"Account-ID">>, kapps_call:account_id(Call)}
Expand Down

0 comments on commit 3ef84b7

Please sign in to comment.