Adds min host info to all host-alerts (engaged/released/triggered)

This commit is contained in:
Simone Mainardi 2020-11-19 17:11:18 +01:00
parent e8159593eb
commit 566babf34c
3 changed files with 34 additions and 4 deletions

View file

@ -128,6 +128,18 @@ local function addAlertPoolInfo(entity_info, alert_json)
end
end
-- ##############################################
--! @brief Adds host information to the alert (only works for host alerts)
--! @param alert_json Host info will be placed in key `host_info` of table `alert_json`
local function addAlertHostInfo(alert_json)
if alert_json then
-- Add only minimal information to keep the final result as small as possible
alert_json.host_info = host.getMinInfo()
end
end
-- ##############################################
--! @param type_info data returned by one of the type_info building functions
@ -180,7 +192,9 @@ function alerts_api.store(entity_info, type_info, when)
addAlertPoolInfo(entity_info, alert_to_store)
if(entity_info.alert_entity.entity_id == alert_consts.alertEntity("host")) then
-- NOTE: for engaged alerts this operation is performed during trigger in C
-- NOTE: for engaged alerts this operation is performed during trigger in C
host.checkContext(entity_info.alert_entity_val)
addAlertHostInfo(alert_to_store)
interface.incTotalHostAlerts(entity_info.alert_entity_val, type_info.alert_type.alert_key)
end
@ -284,6 +298,7 @@ function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
if(entity_info.alert_entity.entity_id == alert_consts.alertEntity("host")) then
host.checkContext(entity_info.alert_entity_val)
triggered = host.storeTriggeredAlert(table.unpack(params))
addAlertHostInfo(triggered)
elseif(entity_info.alert_entity.entity_id == alert_consts.alertEntity("interface")) then
interface.checkContext(entity_info.alert_entity_val)
triggered = interface.storeTriggeredAlert(table.unpack(params))
@ -360,6 +375,7 @@ function alerts_api.release(entity_info, type_info, when, cur_alerts)
if(entity_info.alert_entity.entity_id == alert_consts.alertEntity("host")) then
host.checkContext(entity_info.alert_entity_val)
released = host.releaseTriggeredAlert(table.unpack(params))
addAlertHostInfo(released)
elseif(entity_info.alert_entity.entity_id == alert_consts.alertEntity("interface")) then
interface.checkContext(entity_info.alert_entity_val)
released = interface.releaseTriggeredAlert(table.unpack(params))