Enhance log messages for {,reminder} notifications

refs #12402
This commit is contained in:
Michael Friedrich 2016-08-12 14:49:29 +02:00
parent c6a753b67e
commit e28f30a727
4 changed files with 21 additions and 20 deletions

View File

@ -74,7 +74,7 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr&
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
try {
if (!notification->IsPaused())
notification->BeginExecuteNotification(type, cr, force, author, text);
notification->BeginExecuteNotification(type, cr, force, false, author, text);
} catch (const std::exception& ex) {
Log(LogWarning, "Checkable")
<< "Exception occured during notification for service '"

View File

@ -262,10 +262,10 @@ String Notification::NotificationTypeToString(NotificationType type)
}
}
void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author, const String& text)
void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, bool reminder, const String& author, const String& text)
{
Log(LogNotice, "Notification")
<< "Attempting to send notifications for notification object '" << GetName() << "'.";
<< "Attempting to send " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "'.";
Checkable::Ptr checkable = GetCheckable();
@ -274,7 +274,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
if (tp && !tp->IsInside(Utility::GetTime())) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '" << GetName()
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName()
<< "': not in timeperiod '" << tp->GetName() << "'";
return;
}
@ -288,7 +288,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
if (timesBegin != Empty && timesBegin >= 0 && now < checkable->GetLastHardStateChange() + timesBegin) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '" << GetName()
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName()
<< "': before specified begin time (" << Utility::FormatDuration(timesBegin) << ")";
/* we need to adjust the next notification time
@ -303,7 +303,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
if (timesEnd != Empty && timesEnd >= 0 && now > checkable->GetLastHardStateChange() + timesEnd) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '" << GetName()
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName()
<< "': after specified end time (" << Utility::FormatDuration(timesEnd) << ")";
return;
}
@ -318,7 +318,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
if (!(ftype & GetTypeFilter())) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '" << GetName() << "': type '"
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': type '"
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
<< NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << ".";
return;
@ -347,14 +347,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
if (!(fstate & GetStateFilter())) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '" << GetName() << "': state '" << stateStr
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': state '" << stateStr
<< "' does not match state filter: " << NotificationFilterToString(GetStateFilter(), GetStateFilterMap()) << ".";
return;
}
}
} else {
Log(LogNotice, "Notification")
<< "Not checking notification filters for notification object '" << GetName() << "': Notification was forced.";
<< "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '" << GetName() << "': Notification was forced.";
}
{
@ -393,7 +393,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
continue;
}
if (!CheckNotificationUserFilters(type, user, force)) {
if (!CheckNotificationUserFilters(type, user, force, reminder)) {
Log(LogNotice, "Notification")
<< "Notification filters for user '" << userName << "' not matched. Not sending notification.";
continue;
@ -409,7 +409,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
}
Log(LogInformation, "Notification")
<< "Sending '" << NotificationTypeToStringInternal(type) << "' notification '"
<< "Sending " << (reminder ? "reminder " : " ") << "'" << NotificationTypeToStringInternal(type) << "' notification '"
<< GetName() << " for user '" << userName << "'";
Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text));
@ -430,14 +430,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
Service::OnNotificationSentToAllUsers(this, checkable, allNotifiedUsers, type, cr, author, text, MessageOrigin::Ptr());
}
bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force)
bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder)
{
if (!force) {
TimePeriod::Ptr tp = user->GetPeriod();
if (tp && !tp->IsInside(Utility::GetTime())) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '"
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '"
<< GetName() << " and user '" << user->GetName()
<< "': user period not in timeperiod '" << tp->GetName() << "'";
return false;
@ -453,7 +453,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
if (!(ftype & user->GetTypeFilter())) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '"
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '"
<< GetName() << " and user '" << user->GetName() << "': type '"
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
<< NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << ".";
@ -485,7 +485,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
if (!(fstate & user->GetStateFilter())) {
Log(LogNotice, "Notification")
<< "Not sending notifications for notification object '"
<< "Not " << (reminder ? "reminder " : " ") << "sending notifications for notification object '"
<< GetName() << " and user '" << user->GetName() << "': state '" << stateStr
<< "' does not match state filter: " << NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap()) << ".";
return false;
@ -493,7 +493,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
}
} else {
Log(LogNotice, "Notification")
<< "Not checking notification filters for notification object '"
<< "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '"
<< GetName() << "' and user '" << user->GetName() << "': Notification was forced.";
}

View File

@ -94,9 +94,8 @@ public:
void UpdateNotificationNumber(void);
void ResetNotificationNumber(void);
void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force);
void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force,
bool reminder = false, const String& author = "", const String& text = "");
Endpoint::Ptr GetCommandEndpoint(void) const;
@ -127,6 +126,8 @@ protected:
private:
ObjectImpl<Checkable>::Ptr m_Checkable;
bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder);
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);

View File

@ -116,7 +116,7 @@ void NotificationComponent::NotificationTimerHandler(void)
try {
Log(LogNotice, "NotificationComponent")
<< "Attempting to send reminder notification for object '" << checkable->GetName() << "'";
notification->BeginExecuteNotification(NotificationProblem, checkable->GetLastCheckResult(), false);
notification->BeginExecuteNotification(NotificationProblem, checkable->GetLastCheckResult(), false, true);
} catch (const std::exception& ex) {
Log(LogWarning, "NotificationComponent")
<< "Exception occured during notification for object '"