mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-12 21:13:04 +00:00
Added possibility to send notification to recipients (#7781)
This commit is contained in:
parent
54fdef7f10
commit
b691841321
15 changed files with 285 additions and 122 deletions
|
|
@ -29,6 +29,7 @@ RecipientQueue::RecipientQueue(u_int16_t _recipient_id) {
|
|||
recipient_id = _recipient_id;
|
||||
queue = NULL, drops = 0, uses = 0;
|
||||
last_use = 0;
|
||||
skip_alerts = false;
|
||||
|
||||
/* No minimum severity */
|
||||
minimum_severity = alert_level_none;
|
||||
|
|
@ -81,56 +82,62 @@ bool RecipientQueue::enqueue(const AlertFifoItem* const notification,
|
|||
AlertEntity alert_entity) {
|
||||
bool res = false;
|
||||
|
||||
#ifdef DEBUG_RECIPIENT_QUEUE
|
||||
ntop->getTrace()->traceEvent(TRACE_NORMAL, "Checking alert (entity %d) for recipient %d", alert_entity, recipient_id);
|
||||
#endif
|
||||
/* Checking if the alerts have not to be enqueued */
|
||||
if(skip_alerts && notification->score > 0)
|
||||
return true; /* Skipping alerts */
|
||||
else if(!skip_alerts) {
|
||||
/* In case alerts have not to be skipped, check the filters */
|
||||
#ifdef DEBUG_RECIPIENT_QUEUE
|
||||
ntop->getTrace()->traceEvent(TRACE_NORMAL, "Checking alert (entity %d) for recipient %d", alert_entity, recipient_id);
|
||||
#endif
|
||||
|
||||
if (!notification ||
|
||||
notification->alert_severity <
|
||||
minimum_severity /* Severity too low for this recipient */
|
||||
||
|
||||
!(enabled_categories.isSetBit(
|
||||
notification
|
||||
->alert_category)) /* Category not enabled for this recipient */
|
||||
|| !(enabled_entities.isSetBit(
|
||||
alert_entity)) /* Entity not enabled for this recipient */
|
||||
||
|
||||
(alert_entity_flow == alert_entity && !enabled_flow_checks.isSetBit(notification->alert_id))
|
||||
||
|
||||
(alert_entity_host == alert_entity && !enabled_host_checks.isSetBit(notification->alert_id))
|
||||
) {
|
||||
#ifdef DEBUG_RECIPIENT_QUEUE
|
||||
ntop->getTrace()->traceEvent(TRACE_NORMAL, "Alert filtered out due to filtering policy for recipient %d", recipient_id);
|
||||
#endif
|
||||
return true; /* Nothing to enqueue */
|
||||
}
|
||||
|
||||
if (!notification ||
|
||||
notification->alert_severity <
|
||||
minimum_severity /* Severity too low for this recipient */
|
||||
||
|
||||
!(enabled_categories.isSetBit(
|
||||
notification
|
||||
->alert_category)) /* Category not enabled for this recipient */
|
||||
|| !(enabled_entities.isSetBit(
|
||||
alert_entity)) /* Entity not enabled for this recipient */
|
||||
||
|
||||
(alert_entity_flow == alert_entity && !enabled_flow_checks.isSetBit(notification->alert_id))
|
||||
||
|
||||
(alert_entity_host == alert_entity && !enabled_host_checks.isSetBit(notification->alert_id))
|
||||
) {
|
||||
#ifdef DEBUG_RECIPIENT_QUEUE
|
||||
ntop->getTrace()->traceEvent(TRACE_NORMAL, "Alert filtered out due to filtering policy for recipient %d", recipient_id);
|
||||
#endif
|
||||
return true; /* Nothing to enqueue */
|
||||
}
|
||||
if (recipient_id == 0 && /* Default recipient (DB) */
|
||||
alert_entity == alert_entity_flow &&
|
||||
ntop->getPrefs()->do_dump_flows_on_clickhouse()) {
|
||||
/* Do not store flow alerts on ClickHouse as they are retrieved using a view
|
||||
* on historical flows) */
|
||||
/* But still increment the number of uses */
|
||||
uses++;
|
||||
#ifdef DEBUG_RECIPIENT_QUEUE
|
||||
ntop->getTrace()->traceEvent(TRACE_NORMAL, "Flow alert (no enqueue - clickhouse uses: %u)", uses);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
if (recipient_id == 0 && /* Default recipient (DB) */
|
||||
alert_entity == alert_entity_flow &&
|
||||
ntop->getPrefs()->do_dump_flows_on_clickhouse()) {
|
||||
/* Do not store flow alerts on ClickHouse as they are retrieved using a view
|
||||
* on historical flows) */
|
||||
/* But still increment the number of uses */
|
||||
uses++;
|
||||
#ifdef DEBUG_RECIPIENT_QUEUE
|
||||
ntop->getTrace()->traceEvent(TRACE_NORMAL, "Flow alert (no enqueue - clickhouse uses: %u)", uses);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
if (recipient_id == 0) {
|
||||
/* Default recipient (SQLite / ClickHouse DB) - do not filter alerts by host
|
||||
*/
|
||||
} else {
|
||||
/* Other recipients (notifications) */
|
||||
if (alert_entity == alert_entity_flow) {
|
||||
if (!enabled_host_pools.isSetBit(
|
||||
notification->flow.cli_host_pool) &&
|
||||
!enabled_host_pools.isSetBit(notification->flow.srv_host_pool))
|
||||
return true;
|
||||
} else if (alert_entity == alert_entity_host) {
|
||||
if (!enabled_host_pools.isSetBit(notification->host.host_pool))
|
||||
return true;
|
||||
if (recipient_id == 0) {
|
||||
/* Default recipient (SQLite / ClickHouse DB) - do not filter alerts by host
|
||||
*/
|
||||
} else {
|
||||
/* Other recipients (notifications) */
|
||||
if (alert_entity == alert_entity_flow) {
|
||||
if (!enabled_host_pools.isSetBit(
|
||||
notification->flow.cli_host_pool) &&
|
||||
!enabled_host_pools.isSetBit(notification->flow.srv_host_pool))
|
||||
return true;
|
||||
} else if (alert_entity == alert_entity_host) {
|
||||
if (!enabled_host_pools.isSetBit(notification->host.host_pool))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue