send_notification = reachable && !service->IsInDowntime() && !service->IsAcknowledged();
}
+ notification->SetNextNotification(Utility::GetTime() + notification->GetNotificationInterval());
+
if (!send_notification)
continue;
try {
Log(LogInformation, "notification", "Sending reminder notification for service '" + service->GetName() + "'");
- notification->BeginExecuteNotification(NotificationProblem, service->GetLastCheckResult());
+ notification->BeginExecuteNotification(NotificationProblem, service->GetLastCheckResult(), false);
} catch (const std::exception& ex) {
std::ostringstream msgbuf;
msgbuf << "Exception occured during notification for service '"
Log(LogWarning, "icinga", message);
}
-
- notification->SetNextNotification(Utility::GetTime() + notification->GetNotificationInterval());
}
}
%attribute number "check_interval",
%attribute number "retry_interval",
+ %attribute number "notification_interval",
+ %attribute string "notification_period",
+
%attribute array "servicegroups" {
%attribute string "*"
},
%attribute string "check_period",
%attribute number "check_interval",
%attribute number "retry_interval",
+
%attribute number "notification_interval",
+ %attribute string "notification_period",
+
%attribute dictionary "macros" {
%attribute string "*"
},
%attribute string "check_period",
%attribute number "check_interval",
%attribute number "retry_interval",
+
+ %attribute number "notification_interval",
+ %attribute string "notification_period",
+
%attribute array "hostdependencies" {
%attribute string "*"
},
%attribute string "*"
}
}
- },
-
- %attribute number "notification_interval"
+ }
}
type ServiceGroup {
},
%attribute string "notification_command",
- %attribute number "notification_interval"
+ %attribute number "notification_interval",
+ %attribute string "notification_period"
}
type User {
{
RegisterAttribute("notification_command", Attribute_Config, &m_NotificationCommand);
RegisterAttribute("notification_interval", Attribute_Config, &m_NotificationInterval);
+ RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification);
RegisterAttribute("next_notification", Attribute_Replicated, &m_NextNotification);
RegisterAttribute("macros", Attribute_Config, &m_Macros);
return m_NotificationInterval;
}
+/**
+ * @threadsafety Always.
+ */
+TimePeriod::Ptr Notification::GetNotificationPeriod(void) const
+{
+ return TimePeriod::GetByName(m_NotificationPeriod);
+}
+
/**
* @threadsafety Always.
*/
/**
* @threadsafety Always.
*/
-void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr)
+void Notification::BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool ignore_timeperiod)
{
ASSERT(!OwnsLock());
+ if (!ignore_timeperiod) {
+ TimePeriod::Ptr tp = GetNotificationPeriod();
+
+ if (tp && !tp->IsInside(Utility::GetTime())) {
+ Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': not in timeperiod");
+ return;
+ }
+ }
+
{
ObjectLock olock(this);
BOOST_FOREACH(const User::Ptr& user, allUsers) {
Log(LogDebug, "icinga", "Sending notification for user " + user->GetName());
- BeginExecuteNotificationHelper(macros, type, user);
- }
-
- if (allUsers.empty()) {
- /* Send a notification even if there are no users specified. */
- BeginExecuteNotificationHelper(macros, type, User::Ptr());
+ BeginExecuteNotificationHelper(macros, type, user, ignore_timeperiod);
}
}
/**
* @threadsafety Always.
*/
-void Notification::BeginExecuteNotificationHelper(const Dictionary::Ptr& notificationMacros, NotificationType type, const User::Ptr& user)
+void Notification::BeginExecuteNotificationHelper(const Dictionary::Ptr& notificationMacros,
+ NotificationType type, const User::Ptr& user, bool ignore_timeperiod)
{
ASSERT(!OwnsLock());
- std::vector<Dictionary::Ptr> macroDicts;
+ if (!ignore_timeperiod) {
+ TimePeriod::Ptr tp = user->GetNotificationPeriod();
- if (user) {
- macroDicts.push_back(user->GetMacros());
- macroDicts.push_back(user->CalculateDynamicMacros());
+ if (tp && !tp->IsInside(Utility::GetTime())) {
+ Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
+ GetName() + " and user '" + user->GetName() + "': user not in timeperiod");
+ return;
+ }
}
+ std::vector<Dictionary::Ptr> macroDicts;
+
+ macroDicts.push_back(user->GetMacros());
+ macroDicts.push_back(user->CalculateDynamicMacros());
+
macroDicts.push_back(notificationMacros);
Dictionary::Ptr macros = MacroProcessor::MergeMacroDicts(macroDicts);
#include "icinga/i2-icinga.h"
#include "icinga/user.h"
#include "icinga/usergroup.h"
+#include "icinga/timeperiod.h"
#include "base/array.h"
namespace icinga
shared_ptr<Service> GetService(void) const;
Value GetNotificationCommand(void) const;
double GetNotificationInterval(void) const;
+ TimePeriod::Ptr GetNotificationPeriod(void) const;
Dictionary::Ptr GetMacros(void) const;
std::set<User::Ptr> GetUsers(void) const;
std::set<UserGroup::Ptr> GetGroups(void) const;
double GetNextNotification(void) const;
void SetNextNotification(double time);
- void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr);
+ void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr, bool ignore_timeperiod);
static String NotificationTypeToString(NotificationType type);
private:
Attribute<Value> m_NotificationCommand;
Attribute<double> m_NotificationInterval;
+ Attribute<String> m_NotificationPeriod;
Attribute<double> m_LastNotification;
Attribute<double> m_NextNotification;
Attribute<Dictionary::Ptr> m_Macros;
void NotificationCompletedHandler(const ScriptTask::Ptr& task);
void BeginExecuteNotificationHelper(const Dictionary::Ptr& notificationMacros,
- NotificationType type, const User::Ptr& user);
+ NotificationType type, const User::Ptr& user, bool ignore_timeperiod);
};
}
*/
void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr)
{
+ bool force = false;
+
if (!GetEnableNotifications()) {
if (!GetForceNextNotification()) {
Log(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
return;
}
+ force = true;
SetForceNextNotification(false);
}
BOOST_FOREACH(const Notification::Ptr& notification, notifications) {
try {
- notification->BeginExecuteNotification(type, cr);
+ notification->BeginExecuteNotification(type, cr, force);
} catch (const std::exception& ex) {
std::ostringstream msgbuf;
msgbuf << "Exception occured during notification for service '"
keys.insert("users");
keys.insert("groups");
keys.insert("notification_interval");
+ keys.insert("notification_period");
ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
item->GetLinkedExpressionList()->ExtractFiltered(keys, svc_exprl);
RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
RegisterAttribute("macros", Attribute_Config, &m_Macros);
RegisterAttribute("groups", Attribute_Config, &m_Groups);
+ RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
}
User::~User(void)
return m_Macros;
}
+TimePeriod::Ptr User::GetNotificationPeriod(void) const
+{
+ return TimePeriod::GetByName(m_NotificationPeriod);
+}
+
/**
* @threadsafety Always.
*/
#define USER_H
#include "icinga/i2-icinga.h"
+#include "icinga/timeperiod.h"
#include "base/dynamicobject.h"
#include "base/array.h"
String GetDisplayName(void) const;
Array::Ptr GetGroups(void) const;
+ TimePeriod::Ptr GetNotificationPeriod(void) const;
Dictionary::Ptr GetMacros(void) const;
Dictionary::Ptr CalculateDynamicMacros(void) const;
private:
Attribute<String> m_DisplayName;
Attribute<Dictionary::Ptr> m_Macros;
+ Attribute<String> m_NotificationPeriod;
Attribute<Array::Ptr> m_Groups;
};