mirror of https://github.com/Icinga/icinga2.git
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") {
|
||||
*result = GetName();
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "base/scriptfunction.h"
|
||||
#include "base/convert.h"
|
||||
#include "base/exception.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/logger_fwd.h"
|
||||
#include <boost/smart_ptr/make_shared.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
@ -140,6 +141,7 @@ Array::Ptr LegacyTimePeriod::ScriptFunc(const TimePeriod::Ptr& tp, double begin,
|
|||
|
||||
if (ranges) {
|
||||
for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
|
||||
ObjectLock olock(ranges);
|
||||
String key;
|
||||
Value value;
|
||||
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);
|
||||
}
|
||||
|
||||
reference.tm_wday++;
|
||||
reference.tm_mday++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -280,7 +280,7 @@ void Notification::OnAttributeChanged(const String& name)
|
|||
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();
|
||||
|
||||
|
|
|
@ -55,7 +55,8 @@ void TimePeriod::Start(void)
|
|||
{
|
||||
/* Pre-fill the time period for the next 24 hours. */
|
||||
double now = Utility::GetTime();
|
||||
UpdateRegion(now, now + 24 * 3600);
|
||||
UpdateRegion(now, now + 24 * 3600, true);
|
||||
Dump();
|
||||
}
|
||||
|
||||
TimePeriod::Ptr TimePeriod::GetByName(const String& name)
|
||||
|
@ -196,13 +197,15 @@ void TimePeriod::PurgeSegments(double end)
|
|||
Touch("segments");
|
||||
}
|
||||
|
||||
void TimePeriod::UpdateRegion(double begin, double end)
|
||||
void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
|
||||
{
|
||||
if (!clearExisting) {
|
||||
if (begin < m_ValidEnd)
|
||||
begin = m_ValidEnd;
|
||||
|
||||
if (end < m_ValidEnd)
|
||||
return;
|
||||
}
|
||||
|
||||
TimePeriod::Ptr self = GetSelf();
|
||||
|
||||
|
@ -288,18 +291,18 @@ void TimePeriod::UpdateTimerHandler(void)
|
|||
valid_end = tp->m_ValidEnd;
|
||||
}
|
||||
|
||||
if (valid_end < now + 3 * 3600)
|
||||
tp->UpdateRegion(valid_end, now + 24 * 3600);
|
||||
tp->UpdateRegion(valid_end, now + 24 * 3600, false);
|
||||
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>();
|
||||
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>();
|
||||
|
||||
|
@ -315,3 +318,21 @@ Array::Ptr TimePeriod::EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr tp, dou
|
|||
|
||||
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);
|
||||
|
||||
void UpdateRegion(double begin, double end);
|
||||
void UpdateRegion(double begin, double end, bool clearExisting);
|
||||
|
||||
bool IsInside(double ts) const;
|
||||
double FindNextTransition(double begin);
|
||||
|
||||
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 EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
|
||||
static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
|
||||
|
||||
private:
|
||||
Attribute<double> m_ValidBegin;
|
||||
|
@ -62,6 +62,8 @@ private:
|
|||
void RemoveSegment(double begin, double end);
|
||||
void PurgeSegments(double end);
|
||||
|
||||
void Dump(void);
|
||||
|
||||
static void UpdateTimerHandler(void);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue