Handles errors when retrieving top talkers

This commit is contained in:
Simone Mainardi 2016-02-02 10:46:56 +01:00
parent 418f48e714
commit e8a3d43065
2 changed files with 8 additions and 6 deletions

View file

@ -225,16 +225,19 @@ local function getHistoricalTopTalkersInInterval(ifid, ifname, epoch_start, epoc
--]]
local res = {["senders"] = {}, ["receivers"] = {}}
for record,_ in pairs(query) do
record = json.decode(record)
if recod == nil then goto completed end
record = parseJSON(record)
-- tprint(record)
if not record or not next(record) or not record["vlan"] then goto next_record end
-- tprint(record)
for _, vlan in pairs(record["vlan"]) do
local vlanid = vlan["label"]
local vlanname = vlan["name"]
-- TODO: handle vlans
if not vlan["hosts"] then goto next_vlan end
for _, host_pair in pairs(vlan["hosts"]) do
for direction, top_hosts in pairs(host_pair) do
for _, host in pairs(top_hosts) do
local label = host["label"]
local label = host["address"]
local traffic = tonumber(host["value"])
if label == nil then label = "" end
if traffic == nil then traffic = 0 end
@ -243,13 +246,13 @@ local function getHistoricalTopTalkersInInterval(ifid, ifname, epoch_start, epoc
else
res[direction][label] = res[direction][label] + traffic
end
--host["label"] = host["value"]
end
end
end
::next_vlan::
end
::next_record::
end
::completed::
-- tprint(res)
return json.encode(res, nil)
end