2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-11-09 22:08:26 +01:00
|
|
|
|
|
|
|
#ifndef DOWNTIME_H
|
|
|
|
#define DOWNTIME_H
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/i2-icinga.hpp"
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "icinga/downtime-ti.hpp"
|
|
|
|
#include "icinga/checkable-ti.hpp"
|
2015-08-20 17:18:48 +02:00
|
|
|
#include "remote/messageorigin.hpp"
|
2013-11-09 22:08:26 +01:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2018-08-08 14:42:18 +02:00
|
|
|
enum DowntimeChildOptions
|
|
|
|
{
|
|
|
|
DowntimeNoChildren,
|
|
|
|
DowntimeTriggeredChildren,
|
|
|
|
DowntimeNonTriggeredChildren
|
|
|
|
};
|
|
|
|
|
2013-11-09 22:08:26 +01:00
|
|
|
/**
|
2015-08-20 17:18:48 +02:00
|
|
|
* A downtime.
|
2013-11-09 22:08:26 +01:00
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
2018-01-04 06:11:04 +01:00
|
|
|
class Downtime final : public ObjectImpl<Downtime>
|
2013-11-09 22:08:26 +01:00
|
|
|
{
|
|
|
|
public:
|
2014-11-03 00:44:04 +01:00
|
|
|
DECLARE_OBJECT(Downtime);
|
2015-08-20 17:18:48 +02:00
|
|
|
DECLARE_OBJECTNAME(Downtime);
|
|
|
|
|
|
|
|
static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeAdded;
|
|
|
|
static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeRemoved;
|
2016-11-11 19:36:19 +01:00
|
|
|
static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeStarted;
|
2015-08-20 17:18:48 +02:00
|
|
|
static boost::signals2::signal<void (const Downtime::Ptr&)> OnDowntimeTriggered;
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
intrusive_ptr<Checkable> GetCheckable() const;
|
2013-11-09 22:16:53 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
bool IsInEffect() const;
|
|
|
|
bool IsTriggered() const;
|
|
|
|
bool IsExpired() const;
|
|
|
|
bool HasValidConfigOwner() const;
|
2013-11-09 22:16:53 +01:00
|
|
|
|
2018-08-08 14:42:18 +02:00
|
|
|
static void StaticInitialize();
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static int GetNextDowntimeID();
|
2015-08-20 17:18:48 +02:00
|
|
|
|
2021-01-07 17:48:01 +01:00
|
|
|
static Ptr AddDowntime(const intrusive_ptr<Checkable>& checkable, const String& author,
|
2017-12-19 15:50:05 +01:00
|
|
|
const String& comment, double startTime, double endTime, bool fixed,
|
|
|
|
const String& triggeredBy, double duration, const String& scheduledDowntime = String(),
|
2021-07-22 17:43:03 +02:00
|
|
|
const String& scheduledBy = String(), const String& parent = String(), const String& id = String(),
|
2017-12-19 15:50:05 +01:00
|
|
|
const MessageOrigin::Ptr& origin = nullptr);
|
2015-08-20 17:18:48 +02:00
|
|
|
|
2021-07-22 17:43:03 +02:00
|
|
|
static void RemoveDowntime(const String& id, bool includeChildren, bool cancelled, bool expired = false, const MessageOrigin::Ptr& origin = nullptr);
|
|
|
|
|
|
|
|
void RegisterChild(const Downtime::Ptr& downtime);
|
|
|
|
void UnregisterChild(const Downtime::Ptr& downtime);
|
|
|
|
std::set<Downtime::Ptr> GetChildren() const;
|
2015-08-20 17:18:48 +02:00
|
|
|
|
2021-12-08 11:49:42 +01:00
|
|
|
void TriggerDowntime(double triggerTime);
|
2015-08-20 17:18:48 +02:00
|
|
|
|
|
|
|
static String GetDowntimeIDFromLegacyID(int id);
|
|
|
|
|
2018-08-08 14:42:18 +02:00
|
|
|
static DowntimeChildOptions ChildOptionsFromValue(const Value& options);
|
|
|
|
|
2015-08-20 17:18:48 +02:00
|
|
|
protected:
|
2018-01-04 05:12:56 +01:00
|
|
|
void OnAllConfigLoaded() override;
|
|
|
|
void Start(bool runtimeCreated) override;
|
|
|
|
void Stop(bool runtimeRemoved) override;
|
2015-08-20 17:18:48 +02:00
|
|
|
|
2018-01-11 07:08:09 +01:00
|
|
|
void ValidateStartTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
|
|
|
|
void ValidateEndTime(const Lazy<Timestamp>& lvalue, const ValidationUtils& utils) override;
|
2015-08-20 17:18:48 +02:00
|
|
|
|
|
|
|
private:
|
2015-10-29 08:06:03 +01:00
|
|
|
ObjectImpl<Checkable>::Ptr m_Checkable;
|
2015-08-20 17:18:48 +02:00
|
|
|
|
2021-07-22 17:43:03 +02:00
|
|
|
std::set<Downtime::Ptr> m_Children;
|
|
|
|
mutable std::mutex m_ChildrenMutex;
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
bool CanBeTriggered();
|
2016-11-11 19:36:19 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static void DowntimesStartTimerHandler();
|
|
|
|
static void DowntimesExpireTimerHandler();
|
2013-11-09 22:08:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DOWNTIME_H */
|