1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
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. *
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. *
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 ******************************************************************************/
23 #include "icinga/i2-icinga.hpp"
24 #include "icinga/checkable-ti.hpp"
25 #include "icinga/timeperiod.hpp"
26 #include "icinga/notification.hpp"
27 #include "icinga/comment.hpp"
28 #include "icinga/downtime.hpp"
29 #include "remote/endpoint.hpp"
30 #include "remote/messageorigin.hpp"
41 DependencyCheckExecution,
42 DependencyNotification
63 SeverityFlagDowntime = 1,
64 SeverityFlagAcknowledgement = 2,
65 SeverityFlagUnhandled = 8,
66 SeverityFlagPending = 16,
67 SeverityFlagWarning = 32,
68 SeverityFlagUnknown = 64,
69 SeverityFlagCritical = 128,
81 class Checkable : public ObjectImpl<Checkable>
84 DECLARE_OBJECT(Checkable);
85 DECLARE_OBJECTNAME(Checkable);
87 static void StaticInitialize();
91 std::set<Checkable::Ptr> GetParents() const;
92 std::set<Checkable::Ptr> GetChildren() const;
93 std::set<Checkable::Ptr> GetAllChildren() const;
95 void AddGroup(const String& name);
97 bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr<Dependency> *failedDependency = nullptr, int rstack = 0) const;
99 AcknowledgementType GetAcknowledgement();
101 void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double expiry = 0, const MessageOrigin::Ptr& origin = nullptr);
102 void ClearAcknowledgement(const MessageOrigin::Ptr& origin = nullptr);
104 int GetSeverity() const override;
107 intrusive_ptr<CheckCommand> GetCheckCommand() const;
108 TimePeriod::Ptr GetCheckPeriod() const;
110 long GetSchedulingOffset();
111 void SetSchedulingOffset(long offset);
113 void UpdateNextCheck(const MessageOrigin::Ptr& origin = nullptr);
115 bool HasBeenChecked() const;
116 virtual bool IsStateOK(ServiceState state) = 0;
118 double GetLastCheck() const final;
120 virtual void SaveLastState(ServiceState state, double timestamp) = 0;
122 static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
124 void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr);
126 void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr);
128 Endpoint::Ptr GetCommandEndpoint() const;
130 static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, const MessageOrigin::Ptr&)> OnNewCheckResult;
131 static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, StateType, const MessageOrigin::Ptr&)> OnStateChange;
132 static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, std::set<Checkable::Ptr>, const MessageOrigin::Ptr&)> OnReachabilityChanged;
133 static boost::signals2::signal<void (const Checkable::Ptr&, NotificationType, const CheckResult::Ptr&,
134 const String&, const String&, const MessageOrigin::Ptr&)> OnNotificationsRequested;
135 static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const User::Ptr&,
136 const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&,
137 const MessageOrigin::Ptr&)> OnNotificationSentToUser;
138 static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
139 const NotificationType&, const CheckResult::Ptr&, const String&,
140 const String&, const MessageOrigin::Ptr&)> OnNotificationSentToAllUsers;
141 static boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType,
142 bool, bool, double, const MessageOrigin::Ptr&)> OnAcknowledgementSet;
143 static boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin::Ptr&)> OnAcknowledgementCleared;
144 static boost::signals2::signal<void (const Checkable::Ptr&)> OnNextCheckUpdated;
145 static boost::signals2::signal<void (const Checkable::Ptr&)> OnEventCommandExecuted;
148 int GetDowntimeDepth() const final;
150 void RemoveAllDowntimes();
151 void TriggerDowntimes();
152 bool IsInDowntime() const;
153 bool IsAcknowledged() const;
155 std::set<Downtime::Ptr> GetDowntimes() const;
156 void RegisterDowntime(const Downtime::Ptr& downtime);
157 void UnregisterDowntime(const Downtime::Ptr& downtime);
160 void RemoveAllComments();
161 void RemoveCommentsByType(int type);
163 std::set<Comment::Ptr> GetComments() const;
164 void RegisterComment(const Comment::Ptr& comment);
165 void UnregisterComment(const Comment::Ptr& comment);
168 void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = "");
170 std::set<Notification::Ptr> GetNotifications() const;
171 void RegisterNotification(const Notification::Ptr& notification);
172 void UnregisterNotification(const Notification::Ptr& notification);
174 void ResetNotificationNumbers();
177 void ExecuteEventHandler(const Dictionary::Ptr& resolvedMacros = nullptr,
178 bool useResolvedMacros = false);
180 intrusive_ptr<EventCommand> GetEventCommand() const;
182 /* Flapping Detection */
183 bool IsFlapping() const;
186 void AddDependency(const intrusive_ptr<Dependency>& dep);
187 void RemoveDependency(const intrusive_ptr<Dependency>& dep);
188 std::vector<intrusive_ptr<Dependency> > GetDependencies() const;
190 void AddReverseDependency(const intrusive_ptr<Dependency>& dep);
191 void RemoveReverseDependency(const intrusive_ptr<Dependency>& dep);
192 std::vector<intrusive_ptr<Dependency> > GetReverseDependencies() const;
194 void ValidateCheckInterval(const Lazy<double>& lvalue, const ValidationUtils& value) final;
195 void ValidateMaxCheckAttempts(const Lazy<int>& lvalue, const ValidationUtils& value) final;
197 static void IncreasePendingChecks();
198 static void DecreasePendingChecks();
199 static int GetPendingChecks();
201 static Object::Ptr GetPrototype();
204 void Start(bool runtimeCreated) override;
205 void OnAllConfigLoaded() override;
208 mutable boost::mutex m_CheckableMutex;
209 bool m_CheckRunning{false};
210 long m_SchedulingOffset;
212 static boost::mutex m_StatsMutex;
213 static int m_PendingChecks;
216 std::set<Downtime::Ptr> m_Downtimes;
217 mutable boost::mutex m_DowntimeMutex;
219 static void NotifyFixedDowntimeStart(const Downtime::Ptr& downtime);
220 static void NotifyFlexibleDowntimeStart(const Downtime::Ptr& downtime);
221 static void NotifyDowntimeInternal(const Downtime::Ptr& downtime);
223 static void NotifyDowntimeEnd(const Downtime::Ptr& downtime);
226 std::set<Comment::Ptr> m_Comments;
227 mutable boost::mutex m_CommentMutex;
230 std::set<Notification::Ptr> m_Notifications;
231 mutable boost::mutex m_NotificationMutex;
234 mutable boost::mutex m_DependencyMutex;
235 std::set<intrusive_ptr<Dependency> > m_Dependencies;
236 std::set<intrusive_ptr<Dependency> > m_ReverseDependencies;
238 void GetAllChildrenInternal(std::set<Checkable::Ptr>& children, int level = 0) const;
241 void UpdateFlappingStatus(bool stateChange);
246 #endif /* CHECKABLE_H */
248 #include "icinga/dependency.hpp"