]> granicus.if.org Git - icinga2/blob - lib/icinga/downtime.hpp
Add 'third-party/utf8cpp/' from commit '82344d605146dca6b19abc21578482cecda7f5d7'
[icinga2] / lib / icinga / downtime.hpp
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 String 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& id = String(),
52                 const MessageOrigin::Ptr& origin = nullptr);
53
54         static void RemoveDowntime(const String& id, bool cancelled, bool expired = false, const MessageOrigin::Ptr& origin = nullptr);
55
56         void TriggerDowntime();
57
58         static String GetDowntimeIDFromLegacyID(int id);
59
60         static DowntimeChildOptions ChildOptionsFromValue(const Value& options);
61
62 protected:
63         void OnAllConfigLoaded() override;
64         void Start(bool runtimeCreated) override;
65         void Stop(bool runtimeRemoved) override;
66
67         void ValidateStartTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
68         void ValidateEndTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
69
70 private:
71         ObjectImpl<Checkable>::Ptr m_Checkable;
72
73         bool CanBeTriggered();
74
75         static void DowntimesStartTimerHandler();
76         static void DowntimesExpireTimerHandler();
77 };
78
79 }
80
81 #endif /* DOWNTIME_H */