2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
#ifndef CHECKABLE_H
|
|
|
|
#define CHECKABLE_H
|
|
|
|
|
2019-08-14 17:43:06 +02:00
|
|
|
#include "base/atomic.hpp"
|
2019-07-02 11:23:16 +02:00
|
|
|
#include "base/timer.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/i2-icinga.hpp"
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "icinga/checkable-ti.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/timeperiod.hpp"
|
|
|
|
#include "icinga/notification.hpp"
|
|
|
|
#include "icinga/comment.hpp"
|
|
|
|
#include "icinga/downtime.hpp"
|
2014-11-13 11:23:57 +01:00
|
|
|
#include "remote/endpoint.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/messageorigin.hpp"
|
2019-08-14 17:43:06 +02:00
|
|
|
#include <cstdint>
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum DependencyType
|
|
|
|
{
|
|
|
|
DependencyState,
|
|
|
|
DependencyCheckExecution,
|
|
|
|
DependencyNotification
|
|
|
|
};
|
|
|
|
|
2014-04-17 11:29:47 +02:00
|
|
|
/**
|
|
|
|
* Checkable Types
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum CheckableType
|
|
|
|
{
|
|
|
|
CheckableHost,
|
|
|
|
CheckableService
|
|
|
|
};
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
class CheckCommand;
|
|
|
|
class EventCommand;
|
|
|
|
class Dependency;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An Icinga service.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class Checkable : public ObjectImpl<Checkable>
|
2014-04-03 15:36:13 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-11-03 00:44:04 +01:00
|
|
|
DECLARE_OBJECT(Checkable);
|
|
|
|
DECLARE_OBJECTNAME(Checkable);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static void StaticInitialize();
|
2016-08-10 12:28:41 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Checkable();
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::set<Checkable::Ptr> GetParents() const;
|
|
|
|
std::set<Checkable::Ptr> GetChildren() const;
|
|
|
|
std::set<Checkable::Ptr> GetAllChildren() const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-05-01 23:53:08 +02:00
|
|
|
void AddGroup(const String& name);
|
|
|
|
|
2017-12-14 15:37:20 +01:00
|
|
|
bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr<Dependency> *failedDependency = nullptr, int rstack = 0) const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
AcknowledgementType GetAcknowledgement();
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2019-12-04 15:19:03 +01:00
|
|
|
void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double changeTime = Utility::GetTime(), double expiry = 0, const MessageOrigin::Ptr& origin = nullptr);
|
|
|
|
void ClearAcknowledgement(const String& removedBy, double changeTime = Utility::GetTime(), const MessageOrigin::Ptr& origin = nullptr);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 05:12:56 +01:00
|
|
|
int GetSeverity() const override;
|
2019-04-09 11:34:59 +02:00
|
|
|
bool GetProblem() const override;
|
|
|
|
bool GetHandled() const override;
|
2019-09-24 17:54:20 +02:00
|
|
|
Timestamp GetNextUpdate() const override;
|
2017-02-09 15:32:10 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
/* Checks */
|
2018-01-04 04:25:35 +01:00
|
|
|
intrusive_ptr<CheckCommand> GetCheckCommand() const;
|
|
|
|
TimePeriod::Ptr GetCheckPeriod() const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
long GetSchedulingOffset();
|
2014-04-03 15:36:13 +02:00
|
|
|
void SetSchedulingOffset(long offset);
|
|
|
|
|
2017-11-30 08:36:35 +01:00
|
|
|
void UpdateNextCheck(const MessageOrigin::Ptr& origin = nullptr);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
bool HasBeenChecked() const;
|
2019-04-09 11:26:34 +02:00
|
|
|
virtual bool IsStateOK(ServiceState state) const = 0;
|
2016-03-10 14:32:57 +01:00
|
|
|
|
2018-01-04 05:12:56 +01:00
|
|
|
double GetLastCheck() const final;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2015-11-02 14:10:44 +01:00
|
|
|
virtual void SaveLastState(ServiceState state, double timestamp) = 0;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-05-26 20:56:34 +02:00
|
|
|
static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2017-11-30 08:36:35 +01:00
|
|
|
void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = nullptr);
|
2015-01-18 22:15:35 +01:00
|
|
|
void ExecuteCheck();
|
2017-11-30 08:36:35 +01:00
|
|
|
void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = nullptr);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Endpoint::Ptr GetCommandEndpoint() const;
|
2014-11-13 11:23:57 +01:00
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, const MessageOrigin::Ptr&)> OnNewCheckResult;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, StateType, const MessageOrigin::Ptr&)> OnStateChange;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const CheckResult::Ptr&, std::set<Checkable::Ptr>, const MessageOrigin::Ptr&)> OnReachabilityChanged;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, NotificationType, const CheckResult::Ptr&,
|
2017-12-19 15:50:05 +01:00
|
|
|
const String&, const String&, const MessageOrigin::Ptr&)> OnNotificationsRequested;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const User::Ptr&,
|
2020-01-07 14:20:59 +01:00
|
|
|
const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const String&,
|
|
|
|
const MessageOrigin::Ptr&)> OnNotificationSentToUser;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const Checkable::Ptr&, const std::set<User::Ptr>&,
|
2017-12-19 15:50:05 +01:00
|
|
|
const NotificationType&, const CheckResult::Ptr&, const String&,
|
|
|
|
const String&, const MessageOrigin::Ptr&)> OnNotificationSentToAllUsers;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType,
|
2019-12-04 15:19:03 +01:00
|
|
|
bool, bool, double, double, const MessageOrigin::Ptr&)> OnAcknowledgementSet;
|
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, const String&, double, const MessageOrigin::Ptr&)> OnAcknowledgementCleared;
|
2019-12-04 16:06:04 +01:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&, double)> OnFlappingChange;
|
2016-01-22 18:42:15 +01:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&)> OnNextCheckUpdated;
|
2014-04-03 15:36:13 +02:00
|
|
|
static boost::signals2::signal<void (const Checkable::Ptr&)> OnEventCommandExecuted;
|
|
|
|
|
2019-08-14 17:43:06 +02:00
|
|
|
static Atomic<uint_fast64_t> CurrentConcurrentChecks;
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
/* Downtimes */
|
2018-01-04 05:12:56 +01:00
|
|
|
int GetDowntimeDepth() const final;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void RemoveAllDowntimes();
|
|
|
|
void TriggerDowntimes();
|
|
|
|
bool IsInDowntime() const;
|
|
|
|
bool IsAcknowledged() const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::set<Downtime::Ptr> GetDowntimes() const;
|
2015-08-20 17:18:48 +02:00
|
|
|
void RegisterDowntime(const Downtime::Ptr& downtime);
|
|
|
|
void UnregisterDowntime(const Downtime::Ptr& downtime);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
/* Comments */
|
2018-01-04 04:25:35 +01:00
|
|
|
void RemoveAllComments();
|
2019-11-21 16:28:22 +01:00
|
|
|
void RemoveCommentsByType(int type, const String& removedBy = String());
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::set<Comment::Ptr> GetComments() const;
|
2015-08-20 17:18:48 +02:00
|
|
|
void RegisterComment(const Comment::Ptr& comment);
|
|
|
|
void UnregisterComment(const Comment::Ptr& comment);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Notifications */
|
|
|
|
void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = "");
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::set<Notification::Ptr> GetNotifications() const;
|
2015-08-20 17:18:48 +02:00
|
|
|
void RegisterNotification(const Notification::Ptr& notification);
|
|
|
|
void UnregisterNotification(const Notification::Ptr& notification);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void ResetNotificationNumbers();
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Event Handler */
|
2017-11-30 08:36:35 +01:00
|
|
|
void ExecuteEventHandler(const Dictionary::Ptr& resolvedMacros = nullptr,
|
2017-12-19 15:50:05 +01:00
|
|
|
bool useResolvedMacros = false);
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
intrusive_ptr<EventCommand> GetEventCommand() const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Flapping Detection */
|
2018-01-04 04:25:35 +01:00
|
|
|
bool IsFlapping() const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Dependencies */
|
2014-11-08 21:17:16 +01:00
|
|
|
void AddDependency(const intrusive_ptr<Dependency>& dep);
|
|
|
|
void RemoveDependency(const intrusive_ptr<Dependency>& dep);
|
2018-01-04 04:25:35 +01:00
|
|
|
std::vector<intrusive_ptr<Dependency> > GetDependencies() const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
void AddReverseDependency(const intrusive_ptr<Dependency>& dep);
|
|
|
|
void RemoveReverseDependency(const intrusive_ptr<Dependency>& dep);
|
2018-01-04 04:25:35 +01:00
|
|
|
std::vector<intrusive_ptr<Dependency> > GetReverseDependencies() const;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2018-01-11 07:08:09 +01:00
|
|
|
void ValidateCheckInterval(const Lazy<double>& lvalue, const ValidationUtils& value) final;
|
2019-01-28 17:33:05 +01:00
|
|
|
void ValidateRetryInterval(const Lazy<double>& lvalue, const ValidationUtils& value) final;
|
2018-01-11 07:08:09 +01:00
|
|
|
void ValidateMaxCheckAttempts(const Lazy<int>& lvalue, const ValidationUtils& value) final;
|
2014-12-05 12:59:57 +01:00
|
|
|
|
2020-07-29 17:13:41 +02:00
|
|
|
bool NotificationReasonApplies(NotificationType type);
|
|
|
|
bool IsLikelyToBeCheckedSoon();
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static void IncreasePendingChecks();
|
|
|
|
static void DecreasePendingChecks();
|
|
|
|
static int GetPendingChecks();
|
2018-01-16 10:40:08 +01:00
|
|
|
static void AquirePendingCheckSlot(int maxPendingChecks);
|
2016-05-12 13:46:22 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static Object::Ptr GetPrototype();
|
2016-08-08 14:14:45 +02:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
protected:
|
2018-01-04 05:12:56 +01:00
|
|
|
void Start(bool runtimeCreated) override;
|
|
|
|
void OnAllConfigLoaded() override;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
private:
|
2014-05-01 23:53:08 +02:00
|
|
|
mutable boost::mutex m_CheckableMutex;
|
2018-01-04 09:43:49 +01:00
|
|
|
bool m_CheckRunning{false};
|
2014-04-03 15:36:13 +02:00
|
|
|
long m_SchedulingOffset;
|
|
|
|
|
2016-05-12 13:46:22 +02:00
|
|
|
static boost::mutex m_StatsMutex;
|
|
|
|
static int m_PendingChecks;
|
2018-01-16 10:40:08 +01:00
|
|
|
static boost::condition_variable m_PendingChecksCV;
|
2016-05-12 13:46:22 +02:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
/* Downtimes */
|
2015-08-20 17:18:48 +02:00
|
|
|
std::set<Downtime::Ptr> m_Downtimes;
|
|
|
|
mutable boost::mutex m_DowntimeMutex;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2016-08-10 12:28:41 +02:00
|
|
|
static void NotifyFixedDowntimeStart(const Downtime::Ptr& downtime);
|
|
|
|
static void NotifyFlexibleDowntimeStart(const Downtime::Ptr& downtime);
|
|
|
|
static void NotifyDowntimeInternal(const Downtime::Ptr& downtime);
|
|
|
|
|
|
|
|
static void NotifyDowntimeEnd(const Downtime::Ptr& downtime);
|
|
|
|
|
2019-07-02 11:23:16 +02:00
|
|
|
static void FireSuppressedNotifications(const Timer * const&);
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
/* Comments */
|
2015-08-20 17:18:48 +02:00
|
|
|
std::set<Comment::Ptr> m_Comments;
|
|
|
|
mutable boost::mutex m_CommentMutex;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Notifications */
|
|
|
|
std::set<Notification::Ptr> m_Notifications;
|
2015-01-29 13:18:46 +01:00
|
|
|
mutable boost::mutex m_NotificationMutex;
|
2014-04-03 15:36:13 +02:00
|
|
|
|
|
|
|
/* Dependencies */
|
|
|
|
mutable boost::mutex m_DependencyMutex;
|
2014-11-08 21:17:16 +01:00
|
|
|
std::set<intrusive_ptr<Dependency> > m_Dependencies;
|
|
|
|
std::set<intrusive_ptr<Dependency> > m_ReverseDependencies;
|
2016-10-05 13:13:26 +02:00
|
|
|
|
|
|
|
void GetAllChildrenInternal(std::set<Checkable::Ptr>& children, int level = 0) const;
|
2017-11-03 17:50:59 +01:00
|
|
|
|
|
|
|
/* Flapping */
|
|
|
|
void UpdateFlappingStatus(bool stateChange);
|
2014-04-03 15:36:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CHECKABLE_H */
|
2014-11-08 21:17:16 +01:00
|
|
|
|
|
|
|
#include "icinga/dependency.hpp"
|