]> granicus.if.org Git - icinga2/blob - lib/icinga/notification.hpp
9d596cfb9fc54796f750d51cb77819c369055796
[icinga2] / lib / icinga / notification.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef NOTIFICATION_H
21 #define NOTIFICATION_H
22
23 #include "icinga/i2-icinga.hpp"
24 #include "icinga/notification.thpp"
25 #include "icinga/user.hpp"
26 #include "icinga/usergroup.hpp"
27 #include "icinga/timeperiod.hpp"
28 #include "icinga/checkresult.hpp"
29 #include "remote/messageorigin.hpp"
30 #include "base/array.hpp"
31
32 namespace icinga
33 {
34
35 /**
36  * @ingroup icinga
37  */
38 enum NotificationFilter
39 {
40         StateFilterOK = 1,
41         StateFilterWarning = 2,
42         StateFilterCritical = 4,
43         StateFilterUnknown = 8,
44
45         StateFilterUp = 16,
46         StateFilterDown = 32
47 };
48
49 /**
50  * The notification type.
51  *
52  * @ingroup icinga
53  */
54 enum NotificationType
55 {
56         NotificationDowntimeStart = 0,
57         NotificationDowntimeEnd = 1,
58         NotificationDowntimeRemoved = 2,
59         NotificationCustom = 3,
60         NotificationAcknowledgement = 4,
61         NotificationProblem = 5,
62         NotificationRecovery = 6,
63         NotificationFlappingStart = 7 ,
64         NotificationFlappingEnd = 8,
65 };
66
67 class NotificationCommand;
68 class Checkable;
69 class ApplyRule;
70
71 /**
72  * An Icinga notification specification.
73  *
74  * @ingroup icinga
75  */
76 class I2_ICINGA_API Notification : public ObjectImpl<Notification>
77 {
78 public:
79         DECLARE_OBJECT(Notification);
80         DECLARE_OBJECTNAME(Notification);
81
82         static void StaticInitialize(void);
83
84         intrusive_ptr<Checkable> GetCheckable(void) const;
85         intrusive_ptr<NotificationCommand> GetCommand(void) const;
86         TimePeriod::Ptr GetPeriod(void) const;
87         std::set<User::Ptr> GetUsers(void) const;
88         std::set<UserGroup::Ptr> GetUserGroups(void) const;
89
90         double GetNextNotification(void) const;
91         void SetNextNotification(double time, const MessageOrigin& origin = MessageOrigin());
92
93         void UpdateNotificationNumber(void);
94         void ResetNotificationNumber(void);
95
96         void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
97
98         bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force);
99
100         static String NotificationTypeToString(NotificationType type);
101
102         static boost::signals2::signal<void (const Notification::Ptr&, double, const MessageOrigin&)> OnNextNotificationChanged;
103
104         static void RegisterApplyRuleHandler(void);
105
106         static void ValidateFilters(const String& location, const Dictionary::Ptr& attrs);
107
108 protected:
109         virtual void OnConfigLoaded(void);
110         virtual void Start(void);
111         virtual void Stop(void);
112
113 private:
114         void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
115
116         static void EvaluateApplyRuleOneInstance(const intrusive_ptr<Checkable>& checkable, const String& name, const Dictionary::Ptr& locals, const ApplyRule& rule);
117         static bool EvaluateApplyRuleOne(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule);
118         static void EvaluateApplyRule(const ApplyRule& rule);
119         static void EvaluateApplyRules(const std::vector<ApplyRule>& rules);
120 };
121
122 I2_ICINGA_API int ServiceStateToFilter(ServiceState state);
123 I2_ICINGA_API int HostStateToFilter(HostState state);
124 I2_ICINGA_API int FilterArrayToInt(const Array::Ptr& typeFilters, int defaultValue);
125
126 }
127
128 #endif /* NOTIFICATION_H */