Implement 'force' option for SEND_CUSTOM_*_NOTIFICATION.

This commit is contained in:
Gunnar Beutner 2013-03-21 13:22:26 +01:00
parent db8ac1431c
commit 8037612e72
4 changed files with 48 additions and 3 deletions

View File

@ -1104,11 +1104,19 @@ void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vec
BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
Host::Ptr host = Host::GetByName(arguments[0]);
int options = Convert::ToLong(arguments[1]);
Log(LogInformation, "icinga", "Sending custom notification for host " + host->GetName());
Service::Ptr service = host->GetHostCheckService();
if (service)
if (service) {
if (options & 2) {
ObjectLock olock(service);
service->SetForceNextNotification(true);
service->Flush();
}
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
}
}
void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector<String>& arguments)
@ -1117,8 +1125,16 @@ void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vect
BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments."));
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
int options = Convert::ToLong(arguments[2]);
Log(LogInformation, "icinga", "Sending custom notification for service " + service->GetName());
if (options & 2) {
ObjectLock olock(service);
service->SetForceNextNotification(true);
service->Flush();
}
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
}

View File

@ -61,8 +61,12 @@ void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr&
void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr)
{
if (!GetEnableNotifications()) {
Log(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
return;
if (!GetForceNextNotification()) {
Log(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
return;
}
SetForceNextNotification(false);
}
Log(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
@ -309,3 +313,23 @@ void Service::SetEnableNotifications(bool enabled)
m_EnableNotifications = enabled;
Touch("enable_notifications");
}
/**
* @threadsafety Always.
*/
bool Service::GetForceNextNotification(void) const
{
if (m_ForceNextNotification.IsEmpty())
return false;
return static_cast<bool>(m_ForceNextNotification);
}
/**
* @threadsafety Always.
*/
void Service::SetForceNextNotification(bool forced)
{
m_ForceNextNotification = forced ? 1 : 0;
Touch("force_next_notification");
}

View File

@ -75,6 +75,7 @@ Service::Service(const Dictionary::Ptr& serializedObject)
RegisterAttribute("downtimes", Attribute_Replicated, &m_Downtimes);
RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications);
RegisterAttribute("force_next_notification", Attribute_Replicated, &m_ForceNextNotification);
SetSchedulingOffset(rand());
}

View File

@ -233,6 +233,9 @@ public:
std::set<Notification::Ptr> GetNotifications(void) const;
void SetForceNextNotification(bool force);
bool GetForceNextNotification(void) const;
static void InvalidateNotificationsCache(void);
void UpdateSlaveNotifications(void);
@ -305,6 +308,7 @@ private:
/* Notifications */
Attribute<bool> m_EnableNotifications;
Attribute<bool> m_ForceNextNotification;
static void RefreshNotificationsCache(void);
};