2026-01-27 09:06:40 -05:00
|
|
|
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-02-09 05:42:22 -05:00
|
|
|
|
|
|
|
|
#ifndef NOTIFICATION_H
|
|
|
|
|
#define NOTIFICATION_H
|
|
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "icinga/i2-icinga.hpp"
|
2018-01-18 07:50:38 -05:00
|
|
|
#include "icinga/notification-ti.hpp"
|
|
|
|
|
#include "icinga/checkable-ti.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "icinga/user.hpp"
|
|
|
|
|
#include "icinga/usergroup.hpp"
|
|
|
|
|
#include "icinga/timeperiod.hpp"
|
|
|
|
|
#include "icinga/checkresult.hpp"
|
2014-11-13 05:23:57 -05:00
|
|
|
#include "remote/endpoint.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "remote/messageorigin.hpp"
|
|
|
|
|
#include "base/array.hpp"
|
2023-06-14 10:04:38 -04:00
|
|
|
#include <cstdint>
|
2013-03-17 15:19:29 -04:00
|
|
|
|
2013-02-09 05:42:22 -05:00
|
|
|
namespace icinga
|
|
|
|
|
{
|
|
|
|
|
|
2014-04-07 07:59:41 -04:00
|
|
|
/**
|
|
|
|
|
* @ingroup icinga
|
|
|
|
|
*/
|
|
|
|
|
enum NotificationFilter
|
|
|
|
|
{
|
|
|
|
|
StateFilterOK = 1,
|
|
|
|
|
StateFilterWarning = 2,
|
|
|
|
|
StateFilterCritical = 4,
|
|
|
|
|
StateFilterUnknown = 8,
|
|
|
|
|
|
|
|
|
|
StateFilterUp = 16,
|
2025-05-20 11:17:23 -04:00
|
|
|
StateFilterDown = 32,
|
|
|
|
|
|
|
|
|
|
StateFilterAll = StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown | StateFilterUp | StateFilterDown,
|
2014-04-07 07:59:41 -04:00
|
|
|
};
|
|
|
|
|
|
2013-02-09 05:42:22 -05:00
|
|
|
/**
|
|
|
|
|
* The notification type.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup icinga
|
|
|
|
|
*/
|
|
|
|
|
enum NotificationType
|
|
|
|
|
{
|
2016-06-21 08:46:01 -04:00
|
|
|
NotificationDowntimeStart = 1,
|
|
|
|
|
NotificationDowntimeEnd = 2,
|
|
|
|
|
NotificationDowntimeRemoved = 4,
|
|
|
|
|
NotificationCustom = 8,
|
|
|
|
|
NotificationAcknowledgement = 16,
|
|
|
|
|
NotificationProblem = 32,
|
|
|
|
|
NotificationRecovery = 64,
|
|
|
|
|
NotificationFlappingStart = 128,
|
2025-05-20 11:17:23 -04:00
|
|
|
NotificationFlappingEnd = 256,
|
|
|
|
|
|
|
|
|
|
NotificationTypeAll = NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved |
|
|
|
|
|
NotificationCustom | NotificationAcknowledgement | NotificationProblem | NotificationRecovery |
|
|
|
|
|
NotificationFlappingStart | NotificationFlappingEnd,
|
2013-02-09 05:42:22 -05:00
|
|
|
};
|
|
|
|
|
|
2013-06-13 05:33:00 -04:00
|
|
|
class NotificationCommand;
|
2014-05-11 11:14:35 -04:00
|
|
|
class ApplyRule;
|
2014-12-12 09:33:02 -05:00
|
|
|
struct ScriptFrame;
|
2014-11-16 10:20:39 -05:00
|
|
|
class Host;
|
|
|
|
|
class Service;
|
2024-09-27 06:38:18 -04:00
|
|
|
class UserGroup;
|
2013-02-09 05:42:22 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An Icinga notification specification.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup icinga
|
|
|
|
|
*/
|
2018-01-04 00:11:04 -05:00
|
|
|
class Notification final : public ObjectImpl<Notification>
|
2013-02-09 05:42:22 -05:00
|
|
|
{
|
|
|
|
|
public:
|
2014-11-02 18:44:04 -05:00
|
|
|
DECLARE_OBJECT(Notification);
|
|
|
|
|
DECLARE_OBJECTNAME(Notification);
|
2013-02-09 05:42:22 -05:00
|
|
|
|
2025-05-21 03:09:10 -04:00
|
|
|
Notification();
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
static void StaticInitialize();
|
2013-12-17 08:24:29 -05:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
intrusive_ptr<Checkable> GetCheckable() const;
|
|
|
|
|
intrusive_ptr<NotificationCommand> GetCommand() const;
|
|
|
|
|
TimePeriod::Ptr GetPeriod() const;
|
|
|
|
|
std::set<User::Ptr> GetUsers() const;
|
2024-09-27 06:38:18 -04:00
|
|
|
std::set<intrusive_ptr<UserGroup>> GetUserGroups() const;
|
2013-03-20 05:08:27 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void UpdateNotificationNumber();
|
|
|
|
|
void ResetNotificationNumber();
|
2013-07-18 11:04:09 -04:00
|
|
|
|
2016-08-12 08:49:29 -04:00
|
|
|
void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force,
|
2017-12-19 09:50:05 -05:00
|
|
|
bool reminder = false, const String& author = "", const String& text = "");
|
2014-01-28 11:53:40 -05:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
Endpoint::Ptr GetCommandEndpoint() const;
|
2014-11-04 16:03:39 -05:00
|
|
|
|
2019-07-02 10:33:11 -04:00
|
|
|
// Logging, etc.
|
2013-02-23 19:10:34 -05:00
|
|
|
static String NotificationTypeToString(NotificationType type);
|
2019-07-02 10:33:11 -04:00
|
|
|
// Compat, used for notifications, etc.
|
|
|
|
|
static String NotificationTypeToStringCompat(NotificationType type);
|
2016-06-21 08:46:01 -04:00
|
|
|
static String NotificationFilterToString(int filter, const std::map<String, int>& filterMap);
|
2013-02-09 05:42:22 -05:00
|
|
|
|
2019-07-02 10:33:11 -04:00
|
|
|
static String NotificationServiceStateToString(ServiceState state);
|
|
|
|
|
static String NotificationHostStateToString(HostState state);
|
|
|
|
|
|
2015-08-04 08:47:44 -04:00
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
|
2023-06-14 10:04:38 -04:00
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const String&, uint_fast8_t, const MessageOrigin::Ptr&)> OnLastNotifiedStatePerUserUpdated;
|
2023-12-12 09:55:04 -05:00
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnLastNotifiedStatePerUserCleared;
|
2013-08-28 08:59:41 -04:00
|
|
|
|
2018-01-03 23:12:56 -05:00
|
|
|
void Validate(int types, const ValidationUtils& utils) override;
|
2014-11-30 17:32:13 -05:00
|
|
|
|
2018-01-11 01:08:09 -05:00
|
|
|
void ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
|
|
|
|
void ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
2019-04-30 09:56:57 -04:00
|
|
|
void ValidateTimes(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
|
2014-04-07 07:59:41 -04:00
|
|
|
|
2014-11-16 10:20:39 -05:00
|
|
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
|
|
|
|
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
static const std::map<String, int>& GetStateFilterMap();
|
|
|
|
|
static const std::map<String, int>& GetTypeFilterMap();
|
2016-06-21 08:46:01 -04:00
|
|
|
|
2018-01-03 23:12:56 -05:00
|
|
|
void OnAllConfigLoaded() override;
|
|
|
|
|
void Start(bool runtimeCreated) override;
|
|
|
|
|
void Stop(bool runtimeRemoved) override;
|
2013-02-11 08:01:52 -05:00
|
|
|
|
2025-05-21 03:09:10 -04:00
|
|
|
Array::Ptr GetTypes() const override;
|
|
|
|
|
void SetTypes(const Array::Ptr& value, bool suppress_events, const Value& cookie) override;
|
|
|
|
|
|
|
|
|
|
Array::Ptr GetStates() const override;
|
|
|
|
|
void SetStates(const Array::Ptr& value, bool suppress_events, const Value& cookie) override;
|
|
|
|
|
|
2013-08-20 05:06:04 -04:00
|
|
|
private:
|
2015-10-29 03:06:03 -04:00
|
|
|
ObjectImpl<Checkable>::Ptr m_Checkable;
|
2025-05-21 03:09:10 -04:00
|
|
|
// These attributes represent the actual notification "types" and "states" attributes from the "notification.ti".
|
|
|
|
|
// However, since we want to ensure that the type and state bitsets are always in sync with those attributes,
|
|
|
|
|
// we need to override their setters, and this on the hand introduces another problem: The virtual setters are
|
|
|
|
|
// called from within the ObjectImpl<Notification> constructor, which obviously violates the C++ standard [^1].
|
|
|
|
|
// So, in order to avoid all this kind of mess, these two attributes have the "no_storage" flag set, and
|
|
|
|
|
// their getters/setters are pure virtual, which means this class has to provide the implementation of them.
|
|
|
|
|
//
|
|
|
|
|
// [^1]: https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors
|
|
|
|
|
AtomicOrLocked<Array::Ptr> m_Types;
|
|
|
|
|
AtomicOrLocked<Array::Ptr> m_States;
|
2015-08-20 11:18:48 -04:00
|
|
|
|
2016-08-12 08:49:29 -04:00
|
|
|
bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder);
|
|
|
|
|
|
2023-03-31 06:38:24 -04:00
|
|
|
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, const String& author = "", const String& text = "");
|
2014-04-05 06:56:56 -04:00
|
|
|
|
2022-10-27 10:15:35 -04:00
|
|
|
static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
|
|
|
|
|
static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule, bool skipFilter = false);
|
2015-03-12 12:09:26 -04:00
|
|
|
|
2016-06-21 08:46:01 -04:00
|
|
|
static std::map<String, int> m_StateFilterMap;
|
|
|
|
|
static std::map<String, int> m_TypeFilterMap;
|
2013-02-09 05:42:22 -05:00
|
|
|
};
|
|
|
|
|
|
2017-12-31 01:22:16 -05:00
|
|
|
int ServiceStateToFilter(ServiceState state);
|
|
|
|
|
int HostStateToFilter(HostState state);
|
2014-04-07 07:59:41 -04:00
|
|
|
|
2013-02-09 05:42:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* NOTIFICATION_H */
|