/****************************************************************************** * Icinga 2 * * Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software Foundation * * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ #ifndef CHECKABLE_H #define CHECKABLE_H #include "icinga/i2-icinga.hpp" #include "icinga/checkable.thpp" #include "icinga/timeperiod.hpp" #include "icinga/notification.hpp" #include "icinga/comment.hpp" #include "icinga/downtime.hpp" #include "remote/endpoint.hpp" #include "remote/messageorigin.hpp" namespace icinga { /** * @ingroup icinga */ enum DependencyType { DependencyState, DependencyCheckExecution, DependencyNotification }; /** * Checkable Types * * @ingroup icinga */ enum CheckableType { CheckableHost, CheckableService }; /** * Severity Flags * * @ingroup icinga */ enum SeverityFlag { SeverityFlagDowntime = 1, SeverityFlagAcknowledgement = 2, SeverityFlagUnhandled = 8, SeverityFlagPending = 16, SeverityFlagWarning = 32, SeverityFlagUnknown = 64, SeverityFlagCritical = 128, }; class CheckCommand; class EventCommand; class Dependency; /** * An Icinga service. * * @ingroup icinga */ class I2_ICINGA_API Checkable : public ObjectImpl { public: DECLARE_OBJECT(Checkable); DECLARE_OBJECTNAME(Checkable); static void StaticInitialize(void); Checkable(void); std::set GetParents(void) const; std::set GetChildren(void) const; std::set GetAllChildren(void) const; void AddGroup(const String& name); bool IsReachable(DependencyType dt = DependencyState, intrusive_ptr *failedDependency = NULL, int rstack = 0) const; AcknowledgementType GetAcknowledgement(void); void AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, bool notify = true, bool persistent = false, double expiry = 0, const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); void ClearAcknowledgement(const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); virtual int GetSeverity(void) const override; /* Checks */ intrusive_ptr GetCheckCommand(void) const; TimePeriod::Ptr GetCheckPeriod(void) const; long GetSchedulingOffset(void); void SetSchedulingOffset(long offset); void UpdateNextCheck(const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); bool HasBeenChecked(void) const; virtual bool IsStateOK(ServiceState state) = 0; virtual double GetLastCheck(void) const override; virtual void SaveLastState(ServiceState state, double timestamp) = 0; static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type); void ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr()); void ExecuteCheck(); void ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin = MessageOrigin::Ptr()); Endpoint::Ptr GetCommandEndpoint(void) const; static boost::signals2::signal OnNewCheckResult; static boost::signals2::signal OnStateChange; static boost::signals2::signal, const MessageOrigin::Ptr&)> OnReachabilityChanged; static boost::signals2::signal OnNotificationsRequested; static boost::signals2::signal OnNotificationSentToUser; static boost::signals2::signal&, const NotificationType&, const CheckResult::Ptr&, const String&, const String&, const MessageOrigin::Ptr&)> OnNotificationSentToAllUsers; static boost::signals2::signal OnAcknowledgementSet; static boost::signals2::signal OnAcknowledgementCleared; static boost::signals2::signal OnNextCheckUpdated; static boost::signals2::signal OnEventCommandExecuted; /* Downtimes */ virtual int GetDowntimeDepth(void) const override; void RemoveAllDowntimes(void); void TriggerDowntimes(void); bool IsInDowntime(void) const; bool IsAcknowledged(void) const; std::set GetDowntimes(void) const; void RegisterDowntime(const Downtime::Ptr& downtime); void UnregisterDowntime(const Downtime::Ptr& downtime); /* Comments */ void RemoveAllComments(void); void RemoveCommentsByType(int type); std::set GetComments(void) const; void RegisterComment(const Comment::Ptr& comment); void UnregisterComment(const Comment::Ptr& comment); /* Notifications */ void SendNotifications(NotificationType type, const CheckResult::Ptr& cr, const String& author = "", const String& text = ""); std::set GetNotifications(void) const; void RegisterNotification(const Notification::Ptr& notification); void UnregisterNotification(const Notification::Ptr& notification); void ResetNotificationNumbers(void); /* Event Handler */ void ExecuteEventHandler(const Dictionary::Ptr& resolvedMacros = Dictionary::Ptr(), bool useResolvedMacros = false); intrusive_ptr GetEventCommand(void) const; /* Flapping Detection */ double GetFlappingCurrent(void) const; bool IsFlapping(void) const; void UpdateFlappingStatus(bool stateChange); /* Dependencies */ void AddDependency(const intrusive_ptr& dep); void RemoveDependency(const intrusive_ptr& dep); std::set > GetDependencies(void) const; void AddReverseDependency(const intrusive_ptr& dep); void RemoveReverseDependency(const intrusive_ptr& dep); std::set > GetReverseDependencies(void) const; virtual void ValidateCheckInterval(double value, const ValidationUtils& utils) override; virtual void ValidateMaxCheckAttempts(int value, const ValidationUtils& utils) override; static void IncreasePendingChecks(void); static void DecreasePendingChecks(void); static int GetPendingChecks(void); static Object::Ptr GetPrototype(void); protected: virtual void Start(bool runtimeCreated) override; virtual void OnAllConfigLoaded(void) override; private: mutable boost::mutex m_CheckableMutex; bool m_CheckRunning; long m_SchedulingOffset; static boost::mutex m_StatsMutex; static int m_PendingChecks; /* Downtimes */ std::set m_Downtimes; mutable boost::mutex m_DowntimeMutex; 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); /* Comments */ std::set m_Comments; mutable boost::mutex m_CommentMutex; /* Notifications */ std::set m_Notifications; mutable boost::mutex m_NotificationMutex; /* Dependencies */ mutable boost::mutex m_DependencyMutex; std::set > m_Dependencies; std::set > m_ReverseDependencies; void GetAllChildrenInternal(std::set& children, int level = 0) const; }; } #endif /* CHECKABLE_H */ #include "icinga/dependency.hpp"