1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "icinga/i2-icinga.hpp"
7 #include "icinga/notification-ti.hpp"
8 #include "icinga/checkable-ti.hpp"
9 #include "icinga/user.hpp"
10 #include "icinga/usergroup.hpp"
11 #include "icinga/timeperiod.hpp"
12 #include "icinga/checkresult.hpp"
13 #include "icinga/notificationresult.hpp"
14 #include "remote/endpoint.hpp"
15 #include "remote/messageorigin.hpp"
16 #include "base/array.hpp"
24 enum NotificationFilter
27 StateFilterWarning = 2,
28 StateFilterCritical = 4,
29 StateFilterUnknown = 8,
36 * The notification type.
42 NotificationDowntimeStart = 1,
43 NotificationDowntimeEnd = 2,
44 NotificationDowntimeRemoved = 4,
45 NotificationCustom = 8,
46 NotificationAcknowledgement = 16,
47 NotificationProblem = 32,
48 NotificationRecovery = 64,
49 NotificationFlappingStart = 128,
50 NotificationFlappingEnd = 256
53 class NotificationCommand;
60 * An Icinga notification specification.
64 class Notification final : public ObjectImpl<Notification>
67 DECLARE_OBJECT(Notification);
68 DECLARE_OBJECTNAME(Notification);
70 static void StaticInitialize();
72 intrusive_ptr<Checkable> GetCheckable() const;
73 intrusive_ptr<NotificationCommand> GetCommand() const;
74 TimePeriod::Ptr GetPeriod() const;
75 std::set<User::Ptr> GetUsers() const;
76 std::set<UserGroup::Ptr> GetUserGroups() const;
78 void UpdateNotificationNumber();
79 void ResetNotificationNumber();
81 void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force,
82 bool reminder = false, const String& author = "", const String& text = "");
84 Endpoint::Ptr GetCommandEndpoint() const;
86 void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin = nullptr);
88 static String NotificationTypeToString(NotificationType type);
89 static String NotificationFilterToString(int filter, const std::map<String, int>& filterMap);
91 static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
92 static boost::signals2::signal<void (const Notification::Ptr&, const NotificationResult::Ptr&, const MessageOrigin::Ptr&)> OnNewNotificationResult;
94 void Validate(int types, const ValidationUtils& utils) override;
96 void ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
97 void ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
99 static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
100 static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
102 static const std::map<String, int>& GetStateFilterMap();
103 static const std::map<String, int>& GetTypeFilterMap();
106 void OnConfigLoaded() override;
107 void OnAllConfigLoaded() override;
108 void Start(bool runtimeCreated) override;
109 void Stop(bool runtimeRemoved) override;
112 ObjectImpl<Checkable>::Ptr m_Checkable;
114 bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder);
116 void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
118 static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
119 static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule);
121 static String NotificationTypeToStringInternal(NotificationType type);
122 static String NotificationServiceStateToString(ServiceState state);
123 static String NotificationHostStateToString(HostState state);
125 static std::map<String, int> m_StateFilterMap;
126 static std::map<String, int> m_TypeFilterMap;
129 int ServiceStateToFilter(ServiceState state);
130 int HostStateToFilter(HostState state);
134 #endif /* NOTIFICATION_H */