Skip to content

Commit 8a1d9df

Browse files
authored
Merge pull request #10070 from Icinga/time-period-schedule-next-check-on-next-transition-9984
If skipped due to time period, schedule next check on next transition
2 parents be0ddb1 + daeab09 commit 8a1d9df

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

lib/checker/checkercomponent.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void CheckerComponent::CheckThreadProc()
135135
bool forced = checkable->GetForceNextCheck();
136136
bool check = true;
137137
bool notifyNextCheck = false;
138+
double nextCheck = -1;
138139

139140
if (!forced) {
140141
if (!checkable->IsReachable(DependencyCheckExecution)) {
@@ -162,13 +163,25 @@ void CheckerComponent::CheckThreadProc()
162163

163164
TimePeriod::Ptr tp = checkable->GetCheckPeriod();
164165

165-
if (tp && !tp->IsInside(Utility::GetTime())) {
166-
Log(LogNotice, "CheckerComponent")
167-
<< "Skipping check for object '" << checkable->GetName()
168-
<< "': not in check period '" << tp->GetName() << "'";
166+
if (tp) {
167+
auto ts (Utility::GetTime());
168+
ObjectLock oLock (tp);
169169

170-
check = false;
171-
notifyNextCheck = true;
170+
if (!tp->IsInside(ts)) {
171+
nextCheck = tp->FindNextTransition(ts);
172+
173+
if (nextCheck <= 0) {
174+
nextCheck = tp->GetValidEnd();
175+
}
176+
177+
Log(LogNotice, "CheckerComponent")
178+
<< "Skipping check for object '" << checkable->GetName()
179+
<< "', as not in check period '" << tp->GetName() << "', until "
180+
<< Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", nextCheck);
181+
182+
check = false;
183+
notifyNextCheck = true;
184+
}
172185
}
173186
}
174187

@@ -177,10 +190,14 @@ void CheckerComponent::CheckThreadProc()
177190
m_IdleCheckables.insert(GetCheckableScheduleInfo(checkable));
178191
lock.unlock();
179192

180-
Log(LogDebug, "CheckerComponent")
181-
<< "Checks for checkable '" << checkable->GetName() << "' are disabled. Rescheduling check.";
193+
if (nextCheck > 0) {
194+
checkable->SetNextCheck(nextCheck);
195+
} else {
196+
Log(LogDebug, "CheckerComponent")
197+
<< "Checks for checkable '" << checkable->GetName() << "' are disabled. Rescheduling check.";
182198

183-
checkable->UpdateNextCheck();
199+
checkable->UpdateNextCheck();
200+
}
184201

185202
if (notifyNextCheck) {
186203
// Trigger update event for Icinga DB

0 commit comments

Comments
 (0)