]> granicus.if.org Git - icinga2/blob - lib/icinga/notification.hpp
Merge pull request #7001 from Icinga/bugfix/doc-assignment-5430
[icinga2] / lib / icinga / notification.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef NOTIFICATION_H
4 #define NOTIFICATION_H
5
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 "remote/endpoint.hpp"
14 #include "remote/messageorigin.hpp"
15 #include "base/array.hpp"
16
17 namespace icinga
18 {
19
20 /**
21  * @ingroup icinga
22  */
23 enum NotificationFilter
24 {
25         StateFilterOK = 1,
26         StateFilterWarning = 2,
27         StateFilterCritical = 4,
28         StateFilterUnknown = 8,
29
30         StateFilterUp = 16,
31         StateFilterDown = 32
32 };
33
34 /**
35  * The notification type.
36  *
37  * @ingroup icinga
38  */
39 enum NotificationType
40 {
41         NotificationDowntimeStart = 1,
42         NotificationDowntimeEnd = 2,
43         NotificationDowntimeRemoved = 4,
44         NotificationCustom = 8,
45         NotificationAcknowledgement = 16,
46         NotificationProblem = 32,
47         NotificationRecovery = 64,
48         NotificationFlappingStart = 128,
49         NotificationFlappingEnd = 256
50 };
51
52 class NotificationCommand;
53 class ApplyRule;
54 struct ScriptFrame;
55 class Host;
56 class Service;
57
58 /**
59  * An Icinga notification specification.
60  *
61  * @ingroup icinga
62  */
63 class Notification final : public ObjectImpl<Notification>
64 {
65 public:
66         DECLARE_OBJECT(Notification);
67         DECLARE_OBJECTNAME(Notification);
68
69         static void StaticInitialize();
70
71         intrusive_ptr<Checkable> GetCheckable() const;
72         intrusive_ptr<NotificationCommand> GetCommand() const;
73         TimePeriod::Ptr GetPeriod() const;
74         std::set<User::Ptr> GetUsers() const;
75         std::set<UserGroup::Ptr> GetUserGroups() const;
76
77         void UpdateNotificationNumber();
78         void ResetNotificationNumber();
79
80         void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force,
81                 bool reminder = false, const String& author = "", const String& text = "");
82
83         Endpoint::Ptr GetCommandEndpoint() const;
84
85         static String NotificationTypeToString(NotificationType type);
86         static String NotificationFilterToString(int filter, const std::map<String, int>& filterMap);
87
88         static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
89
90         void Validate(int types, const ValidationUtils& utils) override;
91
92         void ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
93         void ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
94
95         static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
96         static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
97
98         static const std::map<String, int>& GetStateFilterMap();
99         static const std::map<String, int>& GetTypeFilterMap();
100
101 protected:
102         void OnConfigLoaded() override;
103         void OnAllConfigLoaded() override;
104         void Start(bool runtimeCreated) override;
105         void Stop(bool runtimeRemoved) override;
106
107 private:
108         ObjectImpl<Checkable>::Ptr m_Checkable;
109
110         bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder);
111
112         void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
113
114         static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
115         static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule);
116
117         static String NotificationTypeToStringInternal(NotificationType type);
118         static String NotificationServiceStateToString(ServiceState state);
119         static String NotificationHostStateToString(HostState state);
120
121         static std::map<String, int> m_StateFilterMap;
122         static std::map<String, int> m_TypeFilterMap;
123 };
124
125 int ServiceStateToFilter(ServiceState state);
126 int HostStateToFilter(HostState state);
127
128 }
129
130 #endif /* NOTIFICATION_H */