Skip to content

Commit 90848f6

Browse files
committed
Checkable: Add test for state notifications after a suppression ends
1 parent cbc0b21 commit 90848f6

9 files changed

+256
-30
lines changed

lib/icinga/checkable-notification.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -129,34 +129,34 @@ void Checkable::UnregisterNotification(const Notification::Ptr& notification)
129129
m_Notifications.erase(notification);
130130
}
131131

132-
static void FireSuppressedNotifications(Checkable* checkable)
132+
void Checkable::FireSuppressedNotifications()
133133
{
134-
if (!checkable->IsActive())
134+
if (!IsActive())
135135
return;
136136

137-
if (checkable->IsPaused())
137+
if (IsPaused())
138138
return;
139139

140-
if (!checkable->GetEnableNotifications())
140+
if (!GetEnableNotifications())
141141
return;
142142

143-
int suppressed_types (checkable->GetSuppressedNotifications());
143+
int suppressed_types (GetSuppressedNotifications());
144144
if (!suppressed_types)
145145
return;
146146

147147
int subtract = 0;
148148

149149
{
150-
LazyInit<bool> wasLastParentRecoveryRecent ([&checkable]() {
151-
auto cr (checkable->GetLastCheckResult());
150+
LazyInit<bool> wasLastParentRecoveryRecent ([this]() {
151+
auto cr (GetLastCheckResult());
152152

153153
if (!cr) {
154154
return true;
155155
}
156156

157157
auto threshold (cr->GetExecutionStart());
158158

159-
for (auto& dep : checkable->GetDependencies()) {
159+
for (auto& dep : GetDependencies()) {
160160
auto parent (dep->GetParent());
161161
ObjectLock oLock (parent);
162162

@@ -169,9 +169,9 @@ static void FireSuppressedNotifications(Checkable* checkable)
169169
});
170170

171171
if (suppressed_types & (NotificationProblem|NotificationRecovery)) {
172-
CheckResult::Ptr cr = checkable->GetLastCheckResult();
173-
NotificationType type = cr && checkable->IsStateOK(cr->GetState()) ? NotificationRecovery : NotificationProblem;
174-
bool state_suppressed = checkable->NotificationReasonSuppressed(NotificationProblem) || checkable->NotificationReasonSuppressed(NotificationRecovery);
172+
CheckResult::Ptr cr = GetLastCheckResult();
173+
NotificationType type = cr && IsStateOK(cr->GetState()) ? NotificationRecovery : NotificationProblem;
174+
bool state_suppressed = NotificationReasonSuppressed(NotificationProblem) || NotificationReasonSuppressed(NotificationRecovery);
175175

176176
/* Only process (i.e. send or dismiss) suppressed state notifications if the following conditions are met:
177177
*
@@ -191,21 +191,21 @@ static void FireSuppressedNotifications(Checkable* checkable)
191191
*
192192
* If any of these conditions is not met, processing the suppressed notification is further delayed.
193193
*/
194-
if (!state_suppressed && checkable->GetStateType() == StateTypeHard && !checkable->IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) {
195-
if (checkable->NotificationReasonApplies(type)) {
196-
Checkable::OnNotificationsRequested(checkable, type, cr, "", "", nullptr);
194+
if (!state_suppressed && GetStateType() == StateTypeHard && !IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) {
195+
if (NotificationReasonApplies(type)) {
196+
Checkable::OnNotificationsRequested(this, type, cr, "", "", nullptr);
197197
}
198198
subtract |= NotificationRecovery|NotificationProblem;
199199
}
200200
}
201201

202202
for (auto type : {NotificationFlappingStart, NotificationFlappingEnd}) {
203203
if (suppressed_types & type) {
204-
bool still_applies = checkable->NotificationReasonApplies(type);
204+
bool still_applies = NotificationReasonApplies(type);
205205

206206
if (still_applies) {
207-
if (!checkable->NotificationReasonSuppressed(type) && !checkable->IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) {
208-
Checkable::OnNotificationsRequested(checkable, type, checkable->GetLastCheckResult(), "", "", nullptr);
207+
if (!NotificationReasonSuppressed(type) && !IsLikelyToBeCheckedSoon() && !wasLastParentRecoveryRecent.Get()) {
208+
Checkable::OnNotificationsRequested(this, type, GetLastCheckResult(), "", "", nullptr);
209209

210210
subtract |= type;
211211
}
@@ -217,28 +217,28 @@ static void FireSuppressedNotifications(Checkable* checkable)
217217
}
218218

219219
if (subtract) {
220-
ObjectLock olock (checkable);
220+
ObjectLock olock (this);
221221

222-
int suppressed_types_before (checkable->GetSuppressedNotifications());
222+
int suppressed_types_before (GetSuppressedNotifications());
223223
int suppressed_types_after (suppressed_types_before & ~subtract);
224224

225225
if (suppressed_types_after != suppressed_types_before) {
226-
checkable->SetSuppressedNotifications(suppressed_types_after);
226+
SetSuppressedNotifications(suppressed_types_after);
227227
}
228228
}
229229
}
230230

231231
/**
232232
* Re-sends all notifications previously suppressed by e.g. downtimes if the notification reason still applies.
233233
*/
234-
void Checkable::FireSuppressedNotifications(const Timer * const&)
234+
void Checkable::FireSuppressedNotificationsTimer(const Timer * const&)
235235
{
236236
for (auto& host : ConfigType::GetObjectsByType<Host>()) {
237-
::FireSuppressedNotifications(host.get());
237+
host->FireSuppressedNotifications();
238238
}
239239

240240
for (auto& service : ConfigType::GetObjectsByType<Service>()) {
241-
::FireSuppressedNotifications(service.get());
241+
service->FireSuppressedNotifications();
242242
}
243243
}
244244

lib/icinga/checkable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void Checkable::Start(bool runtimeCreated)
103103
boost::call_once(once, []() {
104104
l_CheckablesFireSuppressedNotifications = new Timer();
105105
l_CheckablesFireSuppressedNotifications->SetInterval(5);
106-
l_CheckablesFireSuppressedNotifications->OnTimerExpired.connect(&Checkable::FireSuppressedNotifications);
106+
l_CheckablesFireSuppressedNotifications->OnTimerExpired.connect(&Checkable::FireSuppressedNotificationsTimer);
107107
l_CheckablesFireSuppressedNotifications->Start();
108108

109109
l_CleanDeadlinedExecutions = new Timer();

lib/icinga/checkable.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ class Checkable : public ObjectImpl<Checkable>
191191
bool NotificationReasonSuppressed(NotificationType type);
192192
bool IsLikelyToBeCheckedSoon();
193193

194+
void FireSuppressedNotifications();
195+
194196
static void IncreasePendingChecks();
195197
static void DecreasePendingChecks();
196198
static int GetPendingChecks();
@@ -222,7 +224,7 @@ class Checkable : public ObjectImpl<Checkable>
222224

223225
static void NotifyDowntimeEnd(const Downtime::Ptr& downtime);
224226

225-
static void FireSuppressedNotifications(const Timer * const&);
227+
static void FireSuppressedNotificationsTimer(const Timer * const&);
226228
static void CleanDeadlinedExecutions(const Timer * const&);
227229

228230
/* Comments */

lib/icinga/downtime.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ class Downtime final : public ObjectImpl<Downtime>
6262
void TriggerDowntime(double triggerTime);
6363
void SetRemovalInfo(const String& removedBy, double removeTime, const MessageOrigin::Ptr& origin = nullptr);
6464

65+
void OnAllConfigLoaded() override;
66+
6567
static String GetDowntimeIDFromLegacyID(int id);
6668

6769
static DowntimeChildOptions ChildOptionsFromValue(const Value& options);
6870

6971
protected:
70-
void OnAllConfigLoaded() override;
7172
void Start(bool runtimeCreated) override;
7273
void Stop(bool runtimeRemoved) override;
7374

lib/icinga/downtime.ti

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class Downtime : ConfigObject < DowntimeNameComposer
2525
load_after Host;
2626
load_after Service;
2727

28-
[config, protected, required, navigation(host)] name(Host) host_name {
28+
[config, required, navigation(host)] name(Host) host_name {
2929
navigate {{{
3030
return Host::GetByName(GetHostName());
3131
}}}
3232
};
33-
[config, protected, navigation(service)] String service_name {
33+
[config, navigation(service)] String service_name {
3434
track {{{
3535
if (!oldValue.IsEmpty()) {
3636
Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);

lib/icinga/host.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ class Host final : public ObjectImpl<Host>, public MacroResolver
5050

5151
bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override;
5252

53+
void OnAllConfigLoaded() override;
54+
5355
protected:
5456
void Stop(bool runtimeRemoved) override;
5557

56-
void OnAllConfigLoaded() override;
5758
void CreateChildObjects(const Type::Ptr& childType) override;
5859

5960
private:

lib/icinga/service.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ class Service final : public ObjectImpl<Service>, public MacroResolver
4444

4545
static void EvaluateApplyRules(const Host::Ptr& host);
4646

47+
void OnAllConfigLoaded() override;
48+
4749
static boost::signals2::signal<void (const Service::Ptr&, const CheckResult::Ptr&, const MessageOrigin::Ptr&)> OnHostProblemChanged;
4850

4951
protected:
50-
void OnAllConfigLoaded() override;
5152
void CreateChildObjects(const Type::Ptr& childType) override;
5253

5354
private:

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ add_boost_test(base
133133
icinga_checkresult/service_3attempts
134134
icinga_checkresult/host_flapping_notification
135135
icinga_checkresult/service_flapping_notification
136+
icinga_checkresult/suppressed_notification
136137
icinga_dependencies/multi_parent
137138
icinga_notification/strings
138139
icinga_notification/state_filter

0 commit comments

Comments
 (0)