]> granicus.if.org Git - icinga2/blob - lib/icinga/scheduleddowntime.hpp
Merge pull request #6727 from Icinga/feature/cluster-config-sync-stage
[icinga2] / lib / icinga / scheduleddowntime.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef SCHEDULEDDOWNTIME_H
4 #define SCHEDULEDDOWNTIME_H
5
6 #include "icinga/i2-icinga.hpp"
7 #include "icinga/scheduleddowntime-ti.hpp"
8 #include "icinga/checkable.hpp"
9 #include <atomic>
10
11 namespace icinga
12 {
13
14 class ApplyRule;
15 struct ScriptFrame;
16 class Host;
17 class Service;
18
19 /**
20  * An Icinga scheduled downtime specification.
21  *
22  * @ingroup icinga
23  */
24 class ScheduledDowntime final : public ObjectImpl<ScheduledDowntime>
25 {
26 public:
27         DECLARE_OBJECT(ScheduledDowntime);
28         DECLARE_OBJECTNAME(ScheduledDowntime);
29
30         Checkable::Ptr GetCheckable() const;
31
32         static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
33         static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
34         static bool AllConfigIsLoaded();
35
36         void ValidateRanges(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
37         void ValidateChildOptions(const Lazy<Value>& lvalue, const ValidationUtils& utils) override;
38
39 protected:
40         void OnAllConfigLoaded() override;
41         void Start(bool runtimeCreated) override;
42
43 private:
44         static void TimerProc();
45
46         std::pair<double, double> FindRunningSegment(double minEnd = 0);
47         std::pair<double, double> FindNextSegment();
48         void CreateNextDowntime();
49
50         static std::atomic<bool> m_AllConfigLoaded;
51
52         static bool EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
53         static bool EvaluateApplyRule(const Checkable::Ptr& checkable, const ApplyRule& rule);
54 };
55
56 }
57
58 #endif /* SCHEDULEDDOWNTIME_H */