From b5dbc66b22ceacbcd427e3b12636675f83fc2548 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 23 Feb 2015 14:06:32 +0100 Subject: [PATCH] Implement the 'is_inside' attribute for the TimePeriod type refs #8467 --- doc/6-object-types.md | 5 +++++ lib/icinga/timeperiod.cpp | 5 +++++ lib/icinga/timeperiod.hpp | 2 ++ lib/icinga/timeperiod.ti | 3 +++ 4 files changed, 15 insertions(+) diff --git a/doc/6-object-types.md b/doc/6-object-types.md index bf2e2d141..b71d004b9 100644 --- a/doc/6-object-types.md +++ b/doc/6-object-types.md @@ -586,6 +586,11 @@ Configuration Attributes: The `/etc/icinga2/conf.d/timeperiods.conf` file is usually used to define timeperiods including this one. +Runtime Attributes: + + Name | Type | Description + --------------------------|---------------|----------------- + is\_insidek | Boolean | Whether we're currently inside this timeperiod. ## ScheduledDowntime diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index e03e3a5b3..f3ee7ee9a 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -217,6 +217,11 @@ void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting) } } +bool TimePeriod::GetIsInside(void) const +{ + return IsInside(Utility::GetTime()); +} + bool TimePeriod::IsInside(double ts) const { ObjectLock olock(this); diff --git a/lib/icinga/timeperiod.hpp b/lib/icinga/timeperiod.hpp index 81b3d2de8..e4482f299 100644 --- a/lib/icinga/timeperiod.hpp +++ b/lib/icinga/timeperiod.hpp @@ -43,6 +43,8 @@ public: void UpdateRegion(double begin, double end, bool clearExisting); + virtual bool GetIsInside(void) const; + bool IsInside(double ts) const; double FindNextTransition(double begin); diff --git a/lib/icinga/timeperiod.ti b/lib/icinga/timeperiod.ti index 03971398d..50a950632 100644 --- a/lib/icinga/timeperiod.ti +++ b/lib/icinga/timeperiod.ti @@ -38,6 +38,9 @@ class TimePeriod : CustomVarObject [state] Value valid_begin; [state] Value valid_end; [state] Array::Ptr segments; + [no_storage] bool is_inside { + get; + }; }; } -- 2.49.0