mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-27 07:34:15 +02:00
Bugfixes for the timeperiod feature.
This commit is contained in:
parent
9fa628af82
commit
836c26da66
@ -539,7 +539,7 @@ String Host::StateToString(HostState state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
|
bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
|
||||||
{
|
{
|
||||||
if (macro == "HOSTNAME" || macro == "HOSTALIAS") {
|
if (macro == "HOSTNAME" || macro == "HOSTALIAS") {
|
||||||
*result = GetName();
|
*result = GetName();
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "base/scriptfunction.h"
|
#include "base/scriptfunction.h"
|
||||||
#include "base/convert.h"
|
#include "base/convert.h"
|
||||||
#include "base/exception.h"
|
#include "base/exception.h"
|
||||||
|
#include "base/objectlock.h"
|
||||||
#include "base/logger_fwd.h"
|
#include "base/logger_fwd.h"
|
||||||
#include <boost/smart_ptr/make_shared.hpp>
|
#include <boost/smart_ptr/make_shared.hpp>
|
||||||
#include <boost/algorithm/string/split.hpp>
|
#include <boost/algorithm/string/split.hpp>
|
||||||
@ -140,6 +141,7 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin,
|
|||||||
|
|
||||||
if (ranges) {
|
if (ranges) {
|
||||||
for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
|
for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
|
||||||
|
ObjectLock olock(ranges);
|
||||||
String key;
|
String key;
|
||||||
Value value;
|
Value value;
|
||||||
BOOST_FOREACH(boost::tie(key, value), ranges) {
|
BOOST_FOREACH(boost::tie(key, value), ranges) {
|
||||||
@ -149,7 +151,7 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin,
|
|||||||
ProcessTimeRanges(value, &reference, segments);
|
ProcessTimeRanges(value, &reference, segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
reference.tm_wday++;
|
reference.tm_mday++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ void Notification::OnAttributeChanged(const String& name)
|
|||||||
Service::InvalidateNotificationsCache();
|
Service::InvalidateNotificationsCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
|
bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
|
||||||
{
|
{
|
||||||
Dictionary::Ptr macros = GetMacros();
|
Dictionary::Ptr macros = GetMacros();
|
||||||
|
|
||||||
|
@ -55,7 +55,8 @@ void TimePeriod::Start(void)
|
|||||||
{
|
{
|
||||||
/* Pre-fill the time period for the next 24 hours. */
|
/* Pre-fill the time period for the next 24 hours. */
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
UpdateRegion(now, now + 24 * 3600);
|
UpdateRegion(now, now + 24 * 3600, true);
|
||||||
|
Dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
TimePeriod::Ptr TimePeriod::GetByName(const String& name)
|
TimePeriod::Ptr TimePeriod::GetByName(const String& name)
|
||||||
@ -196,13 +197,15 @@ void TimePeriod::PurgeSegments(double end)
|
|||||||
Touch("segments");
|
Touch("segments");
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimePeriod::UpdateRegion(double begin, double end)
|
void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
|
||||||
{
|
{
|
||||||
if (begin < m_ValidEnd)
|
if (!clearExisting) {
|
||||||
begin = m_ValidEnd;
|
if (begin < m_ValidEnd)
|
||||||
|
begin = m_ValidEnd;
|
||||||
|
|
||||||
if (end < m_ValidEnd)
|
if (end < m_ValidEnd)
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TimePeriod::Ptr self = GetSelf();
|
TimePeriod::Ptr self = GetSelf();
|
||||||
|
|
||||||
@ -288,18 +291,18 @@ void TimePeriod::UpdateTimerHandler(void)
|
|||||||
valid_end = tp->m_ValidEnd;
|
valid_end = tp->m_ValidEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid_end < now + 3 * 3600)
|
tp->UpdateRegion(valid_end, now + 24 * 3600, false);
|
||||||
tp->UpdateRegion(valid_end, now + 24 * 3600);
|
tp->Dump();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Ptr TimePeriod::EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
|
Array::Ptr TimePeriod::EmptyTimePeriodUpdate(const TimePeriod::Ptr&, double, double)
|
||||||
{
|
{
|
||||||
Array::Ptr segments = boost::make_shared<Array>();
|
Array::Ptr segments = boost::make_shared<Array>();
|
||||||
return segments;
|
return segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end)
|
Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr&, double begin, double end)
|
||||||
{
|
{
|
||||||
Array::Ptr segments = boost::make_shared<Array>();
|
Array::Ptr segments = boost::make_shared<Array>();
|
||||||
|
|
||||||
@ -315,3 +318,21 @@ Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, dou
|
|||||||
|
|
||||||
return segments;
|
return segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimePeriod::Dump(void)
|
||||||
|
{
|
||||||
|
Array::Ptr segments = m_Segments;
|
||||||
|
|
||||||
|
Log(LogDebug, "icinga", "Dumping TimePeriod '" + GetName() + "'");
|
||||||
|
|
||||||
|
if (segments) {
|
||||||
|
ObjectLock dlock(segments);
|
||||||
|
BOOST_FOREACH(const Dictionary::Ptr& segment, segments) {
|
||||||
|
Log(LogDebug, "icinga", "Segment: " +
|
||||||
|
Utility::FormatDateTime("%c", segment->Get("begin")) + " <-> " +
|
||||||
|
Utility::FormatDateTime("%c", segment->Get("end")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log(LogDebug, "icinga", "---");
|
||||||
|
}
|
||||||
|
@ -44,13 +44,13 @@ public:
|
|||||||
|
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
|
|
||||||
void UpdateRegion(double begin, double end);
|
void UpdateRegion(double begin, double end, bool clearExisting);
|
||||||
|
|
||||||
bool IsInside(double ts) const;
|
bool IsInside(double ts) const;
|
||||||
double FindNextTransition(double begin);
|
double FindNextTransition(double begin);
|
||||||
|
|
||||||
static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
|
static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
|
||||||
static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, double begin, double end);
|
static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Attribute<double> m_ValidBegin;
|
Attribute<double> m_ValidBegin;
|
||||||
@ -62,6 +62,8 @@ private:
|
|||||||
void RemoveSegment(double begin, double end);
|
void RemoveSegment(double begin, double end);
|
||||||
void PurgeSegments(double end);
|
void PurgeSegments(double end);
|
||||||
|
|
||||||
|
void Dump(void);
|
||||||
|
|
||||||
static void UpdateTimerHandler(void);
|
static void UpdateTimerHandler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user