Handle operators in (view only) tags

This commit is contained in:
Alfredo Cardigliano 2021-06-01 10:53:46 +02:00
parent f242b94b6d
commit ee7c012926
6 changed files with 33 additions and 27 deletions

View file

@ -14,6 +14,7 @@ local alert_consts = require "alert_consts"
local alert_utils = require "alert_utils"
local alert_severities = require "alert_severities"
local alert_roles = require "alert_roles"
local tag_utils = require "tag_utils"
-- ##############################################
@ -89,12 +90,10 @@ function alert_store:strip_filter_operator(value)
local filter = split(value, ",")
local value = filter[1]
local op = filter[2]
if op == 'lt' then
op = '<='
elseif op == 'gt' then
op = '>='
if tag_utils.tag_operators[op] then
op = tag_utils.tag_operators[op]
else
op = '='
op = tag_utils.tag_operators['eq']
end
return value, op
end

View file

@ -217,7 +217,7 @@ function all_alert_store:format_record(value, no_html)
local href_icon = "<i class='fas fa-laptop'></i>"
local record = self:format_record_common(value, alert_entities.host.entity_id, no_html)
local url = string.format('%s/lua/alert_stats.lua?page=%s&epoch_begin=%u&epoch_end=%u',
local url = string.format('%s/lua/alert_stats.lua?page=%s&epoch_begin=%u&epoch_end=%u&status=historical',
ntop.getHttpPrefix(),
alert_consts.alertEntityRaw(value["entity_id"]),
_GET["epoch_begin"],
@ -234,7 +234,7 @@ function all_alert_store:format_record(value, no_html)
record["count_group_notice_or_lower"] = {
value = value["count_group_notice_or_lower"],
color = alert_severities.notice.color,
url = url.."&severity=3,lt",
url = url.."&severity=3,lte",
}
record["count_group_warning"] = {
value = value["count_group_warning"],
@ -244,7 +244,7 @@ function all_alert_store:format_record(value, no_html)
record["count_group_error_or_higher"] = {
value = value["count_group_error_or_higher"],
color = alert_severities.error.color,
url = url.."&severity=5,gt",
url = url.."&severity=5,gte",
}
return record

View file

@ -64,10 +64,10 @@ tag_utils.nindex_tags_to_where_v6 = {
-- #####################################
function tag_utils.add_tag_if_valid(tags, tag_key, tag, formatters)
function tag_utils.add_tag_if_valid(tags, tag_key, operators, formatters)
if isEmptyString(_GET[tag_key]) then
return
return
end
local value
@ -77,16 +77,20 @@ function tag_utils.add_tag_if_valid(tags, tag_key, tag, formatters)
local splitted = split(get_value, ',')
if #splitted == 2 then
value = splitted[1]
selected_operator = splitted[2]
value = splitted[1]
selected_operator = splitted[2]
end
if formatters[tag_key] ~= nil then
value = formatters[tag_key](value)
value = formatters[tag_key](value)
end
table.insert(tags, {
value = value, label = i18n("tags.".. tag_key), key = tag_key, operators = tag.operators, selectedOperator = selected_operator
value = value,
label = i18n("tags.".. tag_key),
key = tag_key,
operators = operators,
selectedOperator = selected_operator
})
end

View file

@ -100,6 +100,7 @@ function ui_utils.render_datetime_range_picker(options)
options.max_delta_out = ternary(options.max_delta_in ~= nil, options.max_delta_in, 43200)
options.tags = ternary(options.tags ~= nil, table.merge(tags, options.tags), tags)
options.tags.localization = ternary(options.tags.i18n ~= nil, table.merge(tags_localization, options.tags.i18n), tags_localization)
options.tags.view_only = ternary(options.tags.view_only ~= nil, options.tags.view_only, false)
return template_utils.gen("pages/components/range-picker.template", options)
end