Skip to content

Commit

Permalink
mod_admin_modules: add warning if not all modules are running. (#3249)
Browse files Browse the repository at this point in the history
* mod_admin_modules: add warning if not all modules are running. Fixes #3045

* Fix modules url
  • Loading branch information
mworrell committed Jan 12, 2023
1 parent f78f554 commit 4e2f9d1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
16 changes: 16 additions & 0 deletions modules/mod_admin/models/m_admin_status.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ m_find_value(unused, #m{value=memory}, _Context) ->
m_find_value(usage, #m{value=memory}, _Context) ->
recon_alloc:memory(usage);

% modules
m_find_value(modules, #m{value=undefined} = M, Context) ->
M#m{value=modules};
m_find_value(down, #m{value=modules}, Context) ->
Status = z_module_manager:get_modules_status(Context),
lists:flatten([
[ Module || {Module, _, _Pid, _Date} <- Specs ]
|| {State, Specs} <- Status, State =/= running
]);
m_find_value(up, #m{value=modules}, Context) ->
Status = z_module_manager:get_modules_status(Context),
lists:flatten([
[ Module || {Module, _, _Pid, _Date} <- Specs ]
|| {running, Specs} <- Status
]);

% init_arguments
m_find_value(init_arguments, #m{value=undefined} = M, _Context) ->
Args = init:get_arguments(),
Expand Down
2 changes: 2 additions & 0 deletions modules/mod_admin/templates/admin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<div class="admin-header">
<h2>{_ Dashboard _}</h2>
</div>

{% include "_admin_modules_down_warning.tpl" %}
{% include "_admin_dashboard_buttons.tpl" %}
{% include "_admin_dashboard.tpl" %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,27 @@ html(Context) ->
[ {Module, atom_to_list(State)} || {Module, _, _Pid, _Date} <- Specs ]
|| {State, Specs} <- Status
]),
Configurable = [{M#module_index.module, M} || M <- z_module_indexer:find_all(template, "_admin_configure_module.tpl", Context)],
Vars =
[
{configurable, Configurable},
{selected, Selected},
{modules, mod_admin_modules:all(Context)},
{status, Status1}
],
Configurable = lists:map(
fun(M) ->
{M#module_index.module, M}
end,
z_module_indexer:find_all(template, "_admin_configure_module.tpl", Context)),
Modules = mod_admin_modules:all(Context),
Vars = [
{configurable, Configurable},
{selected, Selected},
{modules, Modules},
{down, filter_down(Status1)},
{status, Status1}
],
Template = z_context:get(template, Context, "admin_modules.tpl"),
Html = z_template:render(Template, Vars, Context),
z_context:output(Html, Context).

filter_down(Status) ->
lists:filtermap(
fun
({_, "running"}) -> false;
({M, _}) -> {true, M}
end,
Status).
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% if m.acl.is_allowed.use.mod_admin_modules %}
{% if m.admin_status.modules.down as down %}
<div class="alert alert-warning">
<p>
<b><span class="glyphicon glyphicon-warning-sign"></span> {_ The following modules are not running: _}<br></b>
{% for mod in down %}
{{ mod|escape }}{% if not forloop.last %},{% endif %}
{% endfor %}
</p>
<p>
<a class="btn btn-primary" href="{% url admin_modules %}">{_ Modules _}</a>
</p>
</div>
{% endif %}
{% endif %}
11 changes: 11 additions & 0 deletions modules/mod_admin_modules/templates/admin_modules.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
while others are externally developed. This page shows an overview of all modules which are currently known to this Zotonic installation. _}</p>
</div>

{% if down %}
<div class="alert alert-warning">
<p>
<b><span class="glyphicon glyphicon-warning-sign"></span> {_ The following modules are not running: _}<br></b>
{% for mod in down %}
{{ mod|escape }}{% if not forloop.last %},{% endif %}
{% endfor %}
</p>
</div>
{% endif %}

<div {% include "_language_attrs.tpl" language=`en` %}>
<table class="table table-striped do_adminLinkedTable">
<thead>
Expand Down

0 comments on commit 4e2f9d1

Please sign in to comment.