1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
23 #include "icinga/i2-icinga.hpp"
24 #include "icinga/downtime-ti.hpp"
25 #include "icinga/checkable-ti.hpp"
26 #include "remote/messageorigin.hpp"
31 enum DowntimeChildOptions
34 DowntimeTriggeredChildren,
35 DowntimeNonTriggeredChildren
43 class Downtime final : public ObjectImpl<Downtime>
46 DECLARE_OBJECT(Downtime);
47 DECLARE_OBJECTNAME(Downtime);
49 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeAdded;
50 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeRemoved;
51 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeStarted;
52 static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeTriggered;
54 intrusive_ptr<Checkable> GetCheckable() const;
56 bool IsInEffect() const;
57 bool IsTriggered() const;
58 bool IsExpired() const;
59 bool HasValidConfigOwner() const;
61 static void StaticInitialize();
63 static int GetNextDowntimeID();
65 static String AddDowntime(const intrusive_ptr<Checkable>& checkable, const String& author,
66 const String& comment, double startTime, double endTime, bool fixed,
67 const String& triggeredBy, double duration, const String& scheduledDowntime = String(),
68 const String& scheduledBy = String(), const String& id = String(),
69 const MessageOrigin::Ptr& origin = nullptr);
71 static void RemoveDowntime(const String& id, bool cancelled, bool expired = false, const MessageOrigin::Ptr& origin = nullptr);
73 void TriggerDowntime();
75 static String GetDowntimeIDFromLegacyID(int id);
77 static DowntimeChildOptions ChildOptionsFromValue(const Value& options);
80 void OnAllConfigLoaded() override;
81 void Start(bool runtimeCreated) override;
82 void Stop(bool runtimeRemoved) override;
84 void ValidateStartTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
85 void ValidateEndTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
88 ObjectImpl<Checkable>::Ptr m_Checkable;
90 bool CanBeTriggered();
92 static void DowntimesStartTimerHandler();
93 static void DowntimesExpireTimerHandler();
98 #endif /* DOWNTIME_H */