Fixes incorrect system interface id used (#6136)

This commit is contained in:
MatteoBiscosi 2021-12-15 15:37:48 +01:00
parent 3d11f2bec9
commit 46c98aa90d

View file

@ -805,10 +805,17 @@ end
function alert_store:has_alerts()
-- First, check for engaged alerts (fastest)
local _, num_alerts = self:select_engaged()
local ifid = tonumber(_GET["ifid"]) or tonumber(interface.getId())
if num_alerts > 0 then
return true
end
-- The System Interface has the id -1 and in u_int16_t is 65535
if (ifid == -1) then
ifid = 65535
end
-- Now check for historical alerts written in the database. Slightly slower.
-- Fastest way to query SQLite for existance of records. Response will be either a string '1' if records exist,
@ -816,12 +823,12 @@ function alert_store:has_alerts()
local q, res, has_historical_alerts
if(ntop.isClickHouseEnabled()) then
q = string.format(" SELECT COUNT(*) as num_alerts FROM `%s` WHERE interface_id = %d", self._table_name, _GET["ifid"] or interface.getId())
q = string.format(" SELECT COUNT(*) as num_alerts FROM `%s` WHERE interface_id = %d", self._table_name, ifid)
res = interface.alert_store_query(q)
has_historical_alerts = res and res[1] and (tonumber(res[1].num_alerts) > 0) or false
else
q = string.format(" SELECT EXISTS (SELECT 1 FROM `%s` WHERE interface_id = %d) has_historical_alerts", self._table_name, _GET["ifid"] or interface.getId())
q = string.format(" SELECT EXISTS (SELECT 1 FROM `%s` WHERE interface_id = %d) has_historical_alerts", self._table_name, ifid)
res = interface.alert_store_query(q)
has_historical_alerts = res and res[1] and res[1]["has_historical_alerts"] == "1" or false
end
@ -1269,6 +1276,10 @@ function alert_store:add_request_filters()
ntop.setCache(alert_score_cached, score)
end
if ifid == "-1" then
ifid = 65535
end
self:add_status_filter(status)
self:add_time_filter(epoch_begin, epoch_end)