ntopng/include/Recipients.h
Alfredo Cardigliano 4b41152001
Some checks are pending
Build / build (push) Waiting to run
CIFuzz / Fuzzing (address) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
CodeQL / Analyze-1 (push) Waiting to run
Implement alert/notifications filtering by labels
2026-04-24 14:55:02 +02:00

136 lines
4.3 KiB
C++

/*
*
* (C) 2014-26 - ntop.org
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#ifndef _RECIPIENTS_
#define _RECIPIENTS_
#include "ntop_includes.h"
class Recipients {
private:
/* Per-recipient queues */
RecipientQueue* recipient_queues[MAX_NUM_RECIPIENTS];
Mutex m;
AlertLevel default_recipient_minimum_severity;
public:
Recipients();
~Recipients();
/**
* @brief Dequeues a notification from a `recipient_id` queue, given a certain
* priority
* @param recipient_id An integer recipient identifier
*
* @return AlertFifoItem on success, NULL on empty queue
*/
AlertFifoItem* dequeue(u_int16_t recipient_id);
/**
* @brief Enqueues a notification to a `recipient_id` queue, depending on the
* priority
* @param recipient_id An integer recipient identifier
* @param prio The priority of the notification
* @param notification The notification to be enqueued
*
* @return True if the enqueue succeeded, false otherwise
*/
bool enqueue(u_int16_t recipient_id, const AlertFifoItem* const notification);
/**
* @brief Enqueues a notification to all available recipients
* @param notification The notification to be enqueued
*
* @return True if the enqueue succeeded, false otherwise
*/
bool enqueue(const AlertFifoItem* const notification);
/**
* @brief Registers a recipient identified with `recipient_id` so its
* notification can be enqueued/dequeued
* @param recipient_id An integer recipient identifier
* @param minimum_severity The minimum severity for notifications to use this
* recipient
* @param enabled_categories A bitmap of notification categories to use this
* recipient
* @param enabled_host_pools A bitmap of pools to use this recipient
* @param enabled_entities A bitmap of notification entities to use this
* recipient
*
* @return
*/
void register_recipient(u_int16_t recipient_id, AlertLevel minimum_severity,
Bitmap128 enabled_categories,
Bitmap4096 enabled_host_pools,
Bitmap128 enabled_entities,
Bitmap128 enabled_flow_alert_types,
Bitmap128 enabled_host_alert_types,
Bitmap128 enabled_other_alert_types,
bool match_alert_id, bool skip_alerts,
Bitmap64 enabled_labels = Bitmap64());
/**
* @brief Marks a recipient as deleted
* @param recipient_id An integer recipient identifier
*
* @return
*/
void delete_recipient(u_int16_t recipient_id);
/**
* @brief Returns status (drops and uses) of a given recipient
* @param recipient_id An integer recipient identifier
* @param vm A Lua VM instance
*
* @return
*/
void lua(u_int16_t recipient_id, lua_State* vm);
/**
* @brief Returns the last use (i.e., successful dequeue) of a given recipient
* @param recipient_id An integer recipient identifier
*
* @return An epoch with the last use, or 0 if never used.
*/
time_t last_use(u_int16_t recipient_id);
/**
* @brief Inc recipient stats (used by Lua recipients)
* @param recipient_id An integer recipient identifier
*/
void incStats(u_int16_t recipient_id, u_int64_t delivered,
u_int64_t filtered_out, u_int64_t delivery_failures);
/**
* @brief Checks whether there are notifications queued in any of the
* recipients
*
* @return true if there are not notifications enqueued, false otherwise
*/
bool empty();
AlertLevel get_default_recipient_minimum_severity() {
return default_recipient_minimum_severity;
};
};
#endif /* _RECIPIENTS_ */