mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 07:04:37 +02:00
Implement 'force' option for SEND_CUSTOM_*_NOTIFICATION.
This commit is contained in:
parent
db8ac1431c
commit
8037612e72
@ -1104,11 +1104,19 @@ void ExternalCommandProcessor::SendCustomHostNotification(double, const std::vec
|
|||||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 4 arguments."));
|
||||||
|
|
||||||
Host::Ptr host = Host::GetByName(arguments[0]);
|
Host::Ptr host = Host::GetByName(arguments[0]);
|
||||||
|
int options = Convert::ToLong(arguments[1]);
|
||||||
|
|
||||||
Log(LogInformation, "icinga", "Sending custom notification for host " + host->GetName());
|
Log(LogInformation, "icinga", "Sending custom notification for host " + host->GetName());
|
||||||
Service::Ptr service = host->GetHostCheckService();
|
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());
|
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalCommandProcessor::SendCustomSvcNotification(double, const std::vector<String>& arguments)
|
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."));
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Expected 5 arguments."));
|
||||||
|
|
||||||
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
|
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());
|
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());
|
service->RequestNotifications(NotificationCustom, service->GetLastCheckResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,12 @@ void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr&
|
|||||||
void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr)
|
void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr)
|
||||||
{
|
{
|
||||||
if (!GetEnableNotifications()) {
|
if (!GetEnableNotifications()) {
|
||||||
Log(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
|
if (!GetForceNextNotification()) {
|
||||||
return;
|
Log(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetForceNextNotification(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
|
Log(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
|
||||||
@ -309,3 +313,23 @@ void Service::SetEnableNotifications(bool enabled)
|
|||||||
m_EnableNotifications = enabled;
|
m_EnableNotifications = enabled;
|
||||||
Touch("enable_notifications");
|
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");
|
||||||
|
}
|
||||||
|
@ -75,6 +75,7 @@ Service::Service(const Dictionary::Ptr& serializedObject)
|
|||||||
RegisterAttribute("downtimes", Attribute_Replicated, &m_Downtimes);
|
RegisterAttribute("downtimes", Attribute_Replicated, &m_Downtimes);
|
||||||
|
|
||||||
RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications);
|
RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications);
|
||||||
|
RegisterAttribute("force_next_notification", Attribute_Replicated, &m_ForceNextNotification);
|
||||||
|
|
||||||
SetSchedulingOffset(rand());
|
SetSchedulingOffset(rand());
|
||||||
}
|
}
|
||||||
|
@ -233,6 +233,9 @@ public:
|
|||||||
|
|
||||||
std::set<Notification::Ptr> GetNotifications(void) const;
|
std::set<Notification::Ptr> GetNotifications(void) const;
|
||||||
|
|
||||||
|
void SetForceNextNotification(bool force);
|
||||||
|
bool GetForceNextNotification(void) const;
|
||||||
|
|
||||||
static void InvalidateNotificationsCache(void);
|
static void InvalidateNotificationsCache(void);
|
||||||
|
|
||||||
void UpdateSlaveNotifications(void);
|
void UpdateSlaveNotifications(void);
|
||||||
@ -305,6 +308,7 @@ private:
|
|||||||
|
|
||||||
/* Notifications */
|
/* Notifications */
|
||||||
Attribute<bool> m_EnableNotifications;
|
Attribute<bool> m_EnableNotifications;
|
||||||
|
Attribute<bool> m_ForceNextNotification;
|
||||||
|
|
||||||
static void RefreshNotificationsCache(void);
|
static void RefreshNotificationsCache(void);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user