]> granicus.if.org Git - icinga2/blob - lib/icinga/notification.hpp
Implement modified attributes v2
[icinga2] / lib / icinga / notification.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2015 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/endpoint.hpp"
30 #include "remote/messageorigin.hpp"
31 #include "base/array.hpp"
32
33 namespace icinga
34 {
35
36 /**
37  * @ingroup icinga
38  */
39 enum NotificationFilter
40 {
41         StateFilterOK = 1,
42         StateFilterWarning = 2,
43         StateFilterCritical = 4,
44         StateFilterUnknown = 8,
45
46         StateFilterUp = 16,
47         StateFilterDown = 32
48 };
49
50 /**
51  * The notification type.
52  *
53  * @ingroup icinga
54  */
55 enum NotificationType
56 {
57         NotificationDowntimeStart = 0,
58         NotificationDowntimeEnd = 1,
59         NotificationDowntimeRemoved = 2,
60         NotificationCustom = 3,
61         NotificationAcknowledgement = 4,
62         NotificationProblem = 5,
63         NotificationRecovery = 6,
64         NotificationFlappingStart = 7 ,
65         NotificationFlappingEnd = 8,
66 };
67
68 class NotificationCommand;
69 class Checkable;
70 class ApplyRule;
71 struct ScriptFrame;
72 class Host;
73 class Service;
74
75 /**
76  * An Icinga notification specification.
77  *
78  * @ingroup icinga
79  */
80 class I2_ICINGA_API Notification : public ObjectImpl<Notification>
81 {
82 public:
83         DECLARE_OBJECT(Notification);
84         DECLARE_OBJECTNAME(Notification);
85
86         static void StaticInitialize(void);
87
88         intrusive_ptr<Checkable> GetCheckable(void) const;
89         intrusive_ptr<NotificationCommand> GetCommand(void) const;
90         TimePeriod::Ptr GetPeriod(void) const;
91         std::set<User::Ptr> GetUsers(void) const;
92         std::set<UserGroup::Ptr> GetUserGroups(void) const;
93
94         void UpdateNotificationNumber(void);
95         void ResetNotificationNumber(void);
96
97         void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
98
99         bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force);
100
101         Endpoint::Ptr GetCommandEndpoint(void) const;
102
103         static String NotificationTypeToString(NotificationType type);
104         static String NotificationFilterToString(int filter);
105
106         static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
107
108         static void RegisterApplyRuleHandler(void);
109
110         virtual void Validate(int types, const ValidationUtils& utils) override;
111
112         virtual void ValidateStates(const Array::Ptr& value, const ValidationUtils& utils) override;
113         virtual void ValidateTypes(const Array::Ptr& value, const ValidationUtils& utils) override;
114
115         static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
116         static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
117
118 protected:
119         virtual void OnConfigLoaded(void);
120         virtual void OnAllConfigLoaded(void);
121         virtual void Start(void);
122         virtual void Stop(void);
123
124 private:
125         void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
126
127         static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
128         static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule);
129
130         static String NotificationTypeToStringInternal(NotificationType type);
131         static String NotificationServiceStateToString(ServiceState state);
132         static String NotificationHostStateToString(HostState state);
133 };
134
135 I2_ICINGA_API int ServiceStateToFilter(ServiceState state);
136 I2_ICINGA_API int HostStateToFilter(HostState state);
137 I2_ICINGA_API int FilterArrayToInt(const Array::Ptr& typeFilters, int defaultValue);
138 I2_ICINGA_API std::vector<String> FilterIntToArray(int iFilter);
139
140 }
141
142 #endif /* NOTIFICATION_H */