From 174cedcb95bafff080754f713eef8e2efb0ea9bf Mon Sep 17 00:00:00 2001 From: Simone Mainardi Date: Tue, 2 Mar 2021 09:03:05 +0100 Subject: [PATCH] extends get/alert/ts.lua to retrieve per-host counters --- scripts/lua/modules/alert_utils.lua | 8 +++++++- scripts/lua/rest/v1/get/alert/ts.lua | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/lua/modules/alert_utils.lua b/scripts/lua/modules/alert_utils.lua index 9a1ef02e54..9288ad4835 100644 --- a/scripts/lua/modules/alert_utils.lua +++ b/scripts/lua/modules/alert_utils.lua @@ -368,7 +368,7 @@ end -- ################################# -function alert_utils.getNumAlertsPerHour(what, epoch_begin, epoch_end, alert_type, alert_severity) +function alert_utils.getNumAlertsPerHour(what, epoch_begin, epoch_end, alert_type, alert_severity, host_info) local opts = { epoch_begin = epoch_begin, epoch_end = epoch_end, @@ -376,6 +376,12 @@ function alert_utils.getNumAlertsPerHour(what, epoch_begin, epoch_end, alert_typ alert_severity = alert_severity, } + if host_info and host_info.host then + local entity_info = alerts_api.hostAlertEntity(host_info.host, host_info.vlan) + opts.entity = entity_info.alert_entity.entity_id + opts.entity_val = entity_info.alert_entity_val + end + return performAlertsQuery("select (alert_tstamp - alert_tstamp % 3600) as hour, count(*) count", what, opts, nil, "hour") end diff --git a/scripts/lua/rest/v1/get/alert/ts.lua b/scripts/lua/rest/v1/get/alert/ts.lua index 92a16ad5b7..0bae7c9775 100644 --- a/scripts/lua/rest/v1/get/alert/ts.lua +++ b/scripts/lua/rest/v1/get/alert/ts.lua @@ -31,6 +31,7 @@ local epoch_begin = _GET["epoch_begin"] local epoch_end = _GET["epoch_end"] local alert_type = _GET["alert_type"] local alert_severity = _GET["alert_severity"] +local host_info = url2hostinfo(_GET) if isEmptyString(ifid) then rc = rest_utils.consts.err.invalid_interface @@ -38,6 +39,7 @@ if isEmptyString(ifid) then return end + interface.select(ifid) if isEmptyString(what) then @@ -77,7 +79,7 @@ if what == "engaged" then engaged = true end -local counters = alert_utils.getNumAlertsPerHour(what, epoch_begin, epoch_end, alert_type, alert_severity) +local counters = alert_utils.getNumAlertsPerHour(what, epoch_begin, epoch_end, alert_type, alert_severity, host_info) if counters == nil then rc = rest_utils.consts.err.internal_error