mirror of https://github.com/Icinga/icinga2.git
parent
c6a753b67e
commit
e28f30a727
|
@ -74,7 +74,7 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr&
|
||||||
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
|
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
|
||||||
try {
|
try {
|
||||||
if (!notification->IsPaused())
|
if (!notification->IsPaused())
|
||||||
notification->BeginExecuteNotification(type, cr, force, author, text);
|
notification->BeginExecuteNotification(type, cr, force, false, author, text);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Log(LogWarning, "Checkable")
|
Log(LogWarning, "Checkable")
|
||||||
<< "Exception occured during notification for service '"
|
<< "Exception occured during notification for service '"
|
||||||
|
|
|
@ -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")
|
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();
|
Checkable::Ptr checkable = GetCheckable();
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
||||||
|
|
||||||
if (tp && !tp->IsInside(Utility::GetTime())) {
|
if (tp && !tp->IsInside(Utility::GetTime())) {
|
||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Not sending notifications for notification object '" << GetName()
|
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName()
|
||||||
<< "': not in timeperiod '" << tp->GetName() << "'";
|
<< "': not in timeperiod '" << tp->GetName() << "'";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
||||||
|
|
||||||
if (timesBegin != Empty && timesBegin >= 0 && now < checkable->GetLastHardStateChange() + timesBegin) {
|
if (timesBegin != Empty && timesBegin >= 0 && now < checkable->GetLastHardStateChange() + timesBegin) {
|
||||||
Log(LogNotice, "Notification")
|
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) << ")";
|
<< "': before specified begin time (" << Utility::FormatDuration(timesBegin) << ")";
|
||||||
|
|
||||||
/* we need to adjust the next notification time
|
/* 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) {
|
if (timesEnd != Empty && timesEnd >= 0 && now > checkable->GetLastHardStateChange() + timesEnd) {
|
||||||
Log(LogNotice, "Notification")
|
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) << ")";
|
<< "': after specified end time (" << Utility::FormatDuration(timesEnd) << ")";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
||||||
|
|
||||||
if (!(ftype & GetTypeFilter())) {
|
if (!(ftype & GetTypeFilter())) {
|
||||||
Log(LogNotice, "Notification")
|
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: "
|
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
|
||||||
<< NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << ".";
|
<< NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << ".";
|
||||||
return;
|
return;
|
||||||
|
@ -347,14 +347,14 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
||||||
|
|
||||||
if (!(fstate & GetStateFilter())) {
|
if (!(fstate & GetStateFilter())) {
|
||||||
Log(LogNotice, "Notification")
|
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()) << ".";
|
<< "' does not match state filter: " << NotificationFilterToString(GetStateFilter(), GetStateFilterMap()) << ".";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log(LogNotice, "Notification")
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CheckNotificationUserFilters(type, user, force)) {
|
if (!CheckNotificationUserFilters(type, user, force, reminder)) {
|
||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Notification filters for user '" << userName << "' not matched. Not sending notification.";
|
<< "Notification filters for user '" << userName << "' not matched. Not sending notification.";
|
||||||
continue;
|
continue;
|
||||||
|
@ -409,7 +409,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "Notification")
|
Log(LogInformation, "Notification")
|
||||||
<< "Sending '" << NotificationTypeToStringInternal(type) << "' notification '"
|
<< "Sending " << (reminder ? "reminder " : " ") << "'" << NotificationTypeToStringInternal(type) << "' notification '"
|
||||||
<< GetName() << " for user '" << userName << "'";
|
<< GetName() << " for user '" << userName << "'";
|
||||||
|
|
||||||
Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text));
|
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());
|
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) {
|
if (!force) {
|
||||||
TimePeriod::Ptr tp = user->GetPeriod();
|
TimePeriod::Ptr tp = user->GetPeriod();
|
||||||
|
|
||||||
if (tp && !tp->IsInside(Utility::GetTime())) {
|
if (tp && !tp->IsInside(Utility::GetTime())) {
|
||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Not sending notifications for notification object '"
|
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '"
|
||||||
<< GetName() << " and user '" << user->GetName()
|
<< GetName() << " and user '" << user->GetName()
|
||||||
<< "': user period not in timeperiod '" << tp->GetName() << "'";
|
<< "': user period not in timeperiod '" << tp->GetName() << "'";
|
||||||
return false;
|
return false;
|
||||||
|
@ -453,7 +453,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
|
||||||
|
|
||||||
if (!(ftype & user->GetTypeFilter())) {
|
if (!(ftype & user->GetTypeFilter())) {
|
||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Not sending notifications for notification object '"
|
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '"
|
||||||
<< GetName() << " and user '" << user->GetName() << "': type '"
|
<< GetName() << " and user '" << user->GetName() << "': type '"
|
||||||
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
|
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
|
||||||
<< NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << ".";
|
<< NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << ".";
|
||||||
|
@ -485,7 +485,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
|
||||||
|
|
||||||
if (!(fstate & user->GetStateFilter())) {
|
if (!(fstate & user->GetStateFilter())) {
|
||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Not sending notifications for notification object '"
|
<< "Not " << (reminder ? "reminder " : " ") << "sending notifications for notification object '"
|
||||||
<< GetName() << " and user '" << user->GetName() << "': state '" << stateStr
|
<< GetName() << " and user '" << user->GetName() << "': state '" << stateStr
|
||||||
<< "' does not match state filter: " << NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap()) << ".";
|
<< "' does not match state filter: " << NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap()) << ".";
|
||||||
return false;
|
return false;
|
||||||
|
@ -493,7 +493,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log(LogNotice, "Notification")
|
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.";
|
<< GetName() << "' and user '" << user->GetName() << "': Notification was forced.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,9 +94,8 @@ public:
|
||||||
void UpdateNotificationNumber(void);
|
void UpdateNotificationNumber(void);
|
||||||
void ResetNotificationNumber(void);
|
void ResetNotificationNumber(void);
|
||||||
|
|
||||||
void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
|
void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force,
|
||||||
|
bool reminder = false, const String& author = "", const String& text = "");
|
||||||
bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force);
|
|
||||||
|
|
||||||
Endpoint::Ptr GetCommandEndpoint(void) const;
|
Endpoint::Ptr GetCommandEndpoint(void) const;
|
||||||
|
|
||||||
|
@ -127,6 +126,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
ObjectImpl<Checkable>::Ptr m_Checkable;
|
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 = "");
|
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);
|
static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
|
||||||
|
|
|
@ -116,7 +116,7 @@ void NotificationComponent::NotificationTimerHandler(void)
|
||||||
try {
|
try {
|
||||||
Log(LogNotice, "NotificationComponent")
|
Log(LogNotice, "NotificationComponent")
|
||||||
<< "Attempting to send reminder notification for object '" << checkable->GetName() << "'";
|
<< "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) {
|
} catch (const std::exception& ex) {
|
||||||
Log(LogWarning, "NotificationComponent")
|
Log(LogWarning, "NotificationComponent")
|
||||||
<< "Exception occured during notification for object '"
|
<< "Exception occured during notification for object '"
|
||||||
|
|
Loading…
Reference in New Issue