1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #ifndef DOWNTIME_H 4 #define DOWNTIME_H 5 6 #include "icinga/i2-icinga.hpp" 7 #include "icinga/downtime-ti.hpp" 8 #include "icinga/checkable-ti.hpp" 9 #include "remote/messageorigin.hpp" 10 11 namespace icinga 12 { 13 14 enum DowntimeChildOptions 15 { 16 DowntimeNoChildren, 17 DowntimeTriggeredChildren, 18 DowntimeNonTriggeredChildren 19 }; 20 21 /** 22 * A downtime. 23 * 24 * @ingroup icinga 25 */ 26 class Downtime final : public ObjectImpl<Downtime> 27 { 28 public: 29 DECLARE_OBJECT(Downtime); 30 DECLARE_OBJECTNAME(Downtime); 31 32 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeAdded; 33 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeRemoved; 34 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeStarted; 35 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeTriggered; 36 37 intrusive_ptr<Checkable> GetCheckable() const; 38 39 bool IsInEffect() const; 40 bool IsTriggered() const; 41 bool IsExpired() const; 42 bool HasValidConfigOwner() const; 43 44 static void StaticInitialize(); 45 46 static int GetNextDowntimeID(); 47 48 static Ptr AddDowntime(const intrusive_ptr<Checkable>& checkable, const String& author, 49 const String& comment, double startTime, double endTime, bool fixed, 50 const String& triggeredBy, double duration, const String& scheduledDowntime = String(), 51 const String& scheduledBy = String(), const String& parent = String(), const String& id = String(), 52 const MessageOrigin::Ptr& origin = nullptr); 53 54 static void RemoveDowntime(const String& id, bool includeChildren, bool cancelled, bool expired = false, const MessageOrigin::Ptr& origin = nullptr); 55 56 void RegisterChild(const Downtime::Ptr& downtime); 57 void UnregisterChild(const Downtime::Ptr& downtime); 58 std::set<Downtime::Ptr> GetChildren() const; 59 60 void TriggerDowntime(); 61 62 static String GetDowntimeIDFromLegacyID(int id); 63 64 static DowntimeChildOptions ChildOptionsFromValue(const Value& options); 65 66 protected: 67 void OnAllConfigLoaded() override; 68 void Start(bool runtimeCreated) override; 69 void Stop(bool runtimeRemoved) override; 70 71 void ValidateStartTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override; 72 void ValidateEndTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override; 73 74 private: 75 ObjectImpl<Checkable>::Ptr m_Checkable; 76 77 std::set<Downtime::Ptr> m_Children; 78 mutable std::mutex m_ChildrenMutex; 79 80 bool CanBeTriggered(); 81 82 static void DowntimesStartTimerHandler(); 83 static void DowntimesExpireTimerHandler(); 84 }; 85 86 } 87 88 #endif /* DOWNTIME_H */ 89