]> granicus.if.org Git - icinga2/blob - lib/icinga/downtime.hpp
Merge pull request #6503 from peteeckel/fix/reduce-loglevel-plugin-env-6460
[icinga2] / lib / icinga / downtime.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
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.                     *
9  *                                                                            *
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.                               *
14  *                                                                            *
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  ******************************************************************************/
19
20 #ifndef DOWNTIME_H
21 #define DOWNTIME_H
22
23 #include "icinga/i2-icinga.hpp"
24 #include "icinga/downtime-ti.hpp"
25 #include "icinga/checkable-ti.hpp"
26 #include "remote/messageorigin.hpp"
27
28 namespace icinga
29 {
30
31 enum DowntimeChildOptions
32 {
33         DowntimeNoChildren,
34         DowntimeTriggeredChildren,
35         DowntimeNonTriggeredChildren
36 };
37
38 /**
39  * A downtime.
40  *
41  * @ingroup icinga
42  */
43 class Downtime final : public ObjectImpl<Downtime>
44 {
45 public:
46         DECLARE_OBJECT(Downtime);
47         DECLARE_OBJECTNAME(Downtime);
48
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;
53
54         intrusive_ptr<Checkable> GetCheckable() const;
55
56         bool IsInEffect() const;
57         bool IsTriggered() const;
58         bool IsExpired() const;
59         bool HasValidConfigOwner() const;
60
61         static void StaticInitialize();
62
63         static int GetNextDowntimeID();
64
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);
70
71         static void RemoveDowntime(const String& id, bool cancelled, bool expired = false, const MessageOrigin::Ptr& origin = nullptr);
72
73         void TriggerDowntime();
74
75         static String GetDowntimeIDFromLegacyID(int id);
76
77         static DowntimeChildOptions ChildOptionsFromValue(const Value& options);
78
79 protected:
80         void OnAllConfigLoaded() override;
81         void Start(bool runtimeCreated) override;
82         void Stop(bool runtimeRemoved) override;
83
84         void ValidateStartTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
85         void ValidateEndTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
86
87 private:
88         ObjectImpl<Checkable>::Ptr m_Checkable;
89
90         bool CanBeTriggered();
91
92         static void DowntimesStartTimerHandler();
93         static void DowntimesExpireTimerHandler();
94 };
95
96 }
97
98 #endif /* DOWNTIME_H */