mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-02 00:40:10 +00:00
Fix alert count with clickhouse (#6046)
This commit is contained in:
parent
643fdeec68
commit
d2d42ad180
2 changed files with 19 additions and 6 deletions
|
|
@ -679,10 +679,10 @@ function alert_store:select_historical(filter, fields)
|
|||
local q
|
||||
if ntop.isClickHouseEnabled() then
|
||||
q = string.format(" SELECT %u entity_id, (toUnixTimestamp(tstamp_end) - toUnixTimestamp(tstamp)) duration, %s FROM `%s` WHERE %s %s %s %s %s",
|
||||
self._alert_entity.entity_id, fields, self._table_name, where_clause, group_by_clause, order_by_clause, limit_clause, offset_clause)
|
||||
self._alert_entity.entity_id, fields, self._table_name, where_clause, group_by_clause, order_by_clause, limit_clause, offset_clause)
|
||||
else
|
||||
q = string.format(" SELECT %u entity_id, (tstamp_end - tstamp) duration, %s FROM `%s` WHERE %s %s %s %s %s",
|
||||
self._alert_entity.entity_id, fields, self._table_name, where_clause, group_by_clause, order_by_clause, limit_clause, offset_clause)
|
||||
self._alert_entity.entity_id, fields, self._table_name, where_clause, group_by_clause, order_by_clause, limit_clause, offset_clause)
|
||||
end
|
||||
|
||||
res = interface.alert_store_query(q)
|
||||
|
|
@ -754,9 +754,16 @@ end
|
|||
|
||||
--@brief Performs a query and counts the number of records
|
||||
function alert_store:count()
|
||||
local count_query = self:select_historical(nil, "count(*) as count")
|
||||
local where_clause = ''
|
||||
|
||||
where_clause = self:build_where_clause()
|
||||
|
||||
local q = string.format(" SELECT count(*) as count FROM `%s` WHERE %s",
|
||||
self._table_name, where_clause)
|
||||
|
||||
local count_query = interface.alert_store_query(q)
|
||||
|
||||
local num_results = 0
|
||||
|
||||
if count_query then
|
||||
num_results = tonumber(count_query[1]["count"])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -103,8 +103,14 @@ function flow_alert_store:top_cli_ip_historical()
|
|||
-- Preserve all the filters currently set
|
||||
local where_clause = self:build_where_clause()
|
||||
|
||||
local q = string.format("SELECT cli_ip, vlan_id, cli_name, count(*) count FROM %s WHERE %s GROUP BY cli_ip ORDER BY count DESC LIMIT %u",
|
||||
self._table_name, where_clause, self._top_limit)
|
||||
local q
|
||||
if ntop.isClickHouseEnabled() then
|
||||
q = string.format("SELECT cli_ip, vlan_id, cli_name, count(*) count FROM %s WHERE %s GROUP BY cli_ip, vlan_id ORDER BY count DESC LIMIT %u",
|
||||
self._table_name, where_clause, self._top_limit)
|
||||
else
|
||||
q = string.format("SELECT cli_ip, vlan_id, cli_name, count(*) count FROM %s WHERE %s GROUP BY cli_ip ORDER BY count DESC LIMIT %u",
|
||||
self._table_name, where_clause, self._top_limit)
|
||||
end
|
||||
|
||||
local q_res = interface.alert_store_query(q) or {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue