Implements per pool member quotas

This commit is contained in:
Simone Mainardi 2017-05-09 14:58:44 +02:00 committed by emanuele-f
parent 1b313d2932
commit b5e685f243
12 changed files with 291 additions and 84 deletions

View file

@ -41,13 +41,14 @@ end
--------------------------------------------------------------------------------
function host_pools_utils.createPool(ifid, pool_id, pool_name, children_safe)
function host_pools_utils.createPool(ifid, pool_id, pool_name, children_safe, enforce_quotas_per_pool_member)
local details_key = get_pool_details_key(ifid, pool_id)
local ids_key = get_pool_ids_key(ifid)
ntop.setMembersCache(ids_key, pool_id)
ntop.setHashCache(details_key, "name", pool_name)
ntop.setHashCache(details_key, "children_safe", tostring(children_safe or false))
ntop.setHashCache(details_key, "enforce_quotas_per_pool_member", tostring(enforce_quotas_per_pool_member or false))
end
function host_pools_utils.deletePool(ifid, pool_id)
@ -175,6 +176,7 @@ function host_pools_utils.getPoolsList(ifid, without_info)
id = pool_id,
name = host_pools_utils.getPoolName(ifid, pool_id),
children_safe = host_pools_utils.getChildrenSafe(ifid, pool_id),
enforce_quotas_per_pool_member = host_pools_utils.getEnforceQuotasPerPoolMember(ifid, pool_id),
}
end
@ -248,6 +250,10 @@ function host_pools_utils.getChildrenSafe(ifid, pool_id)
return toboolean(get_pool_detail(ifid, pool_id, "children_safe"))
end
function host_pools_utils.getEnforceQuotasPerPoolMember(ifid, pool_id)
return toboolean(get_pool_detail(ifid, pool_id, "enforce_quotas_per_pool_member"))
end
function host_pools_utils.initPools()
for _, ifname in pairs(interface.getIfNames()) do
local ifid = getInterfaceId(ifname)
@ -322,4 +328,61 @@ function host_pools_utils.updateRRDs(ifid, dump_ndpi, verbose)
end
end
function host_pools_utils.printQuotas(pool_id, host, page_params)
local pools_stats = interface.getHostPoolsStats()
local pool_stats = pools_stats and pools_stats[tonumber(pool_id)]
local ndpi_stats = pool_stats.ndpi
local category_stats = pool_stats.ndpi_categories
local quota_and_protos = shaper_utils.getPoolProtoShapers(ifId, pool_id)
-- Empty check
local empty = true
for _, proto in pairs(quota_and_protos) do
if ((tonumber(proto.traffic_quota) > 0) or (tonumber(proto.time_quota) > 0)) then
-- at least a quota is set
empty = false
break
end
end
if empty then
print("<div class=\"alert alert alert-danger\"><img src=".. ntop.getHttpPrefix() .. "/img/warning.png>"..i18n("shaping.no_quota_data")..
". Create new quotas <a href=\""..ntop.getHttpPrefix().."/lua/if_stats.lua?page=filtering&pool="..pool_id.."\">here</a>.</div>")
else
print[[
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>]] print(i18n("protocol")) print[[</th>
<th class="text-center">]] print(i18n("shaping.daily_traffic")) print[[</th>
<th class="text-center">]] print(i18n("shaping.daily_time")) print[[</th>
</tr>
</thead>
<tbody id="pool_quotas_ndpi_tbody">
</tbody>
</table>
<script>
function update_ndpi_table() {
$.ajax({
type: 'GET',
url: ']]
print(getPageUrl(ntop.getHttpPrefix().."/lua/pro/pool_details_ndpi.lua").."', data: ")
print(tableToJsObject(page_params))
print[[,
success: function(content) {
if(content)
$('#pool_quotas_ndpi_tbody').html(content);
}
});
}
setInterval(update_ndpi_table, 5000);
update_ndpi_table();
</script>]]
end
end
return host_pools_utils