mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Implemented support for disabling notifications.
This commit is contained in:
parent
f47e1991f2
commit
163f0a9f5c
@ -296,23 +296,38 @@ void CompatComponent::DumpHostStatus(ostream& fp, const Host::Ptr& host)
|
||||
|
||||
void CompatComponent::DumpHostObject(ostream& fp, const Host::Ptr& host)
|
||||
{
|
||||
ObjectLock olock(host);
|
||||
Service::Ptr hc;
|
||||
|
||||
fp << "define host {" << "\n"
|
||||
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
|
||||
<< "\t" << "display_name" << "\t" << host->GetDisplayName() << "\n"
|
||||
<< "\t" << "check_interval" << "\t" << 1 << "\n"
|
||||
<< "\t" << "retry_interval" << "\t" << 1 << "\n"
|
||||
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
||||
<< "\t" << "active_checks_enabled" << "\t" << 1 << "\n"
|
||||
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n";
|
||||
{
|
||||
ObjectLock olock(host);
|
||||
|
||||
set<Host::Ptr> parents = host->GetParentHosts();
|
||||
fp << "define host {" << "\n"
|
||||
<< "\t" << "host_name" << "\t" << host->GetName() << "\n"
|
||||
<< "\t" << "display_name" << "\t" << host->GetDisplayName() << "\n";
|
||||
|
||||
if (!parents.empty()) {
|
||||
fp << "\t" << "parents" << "\t";
|
||||
DumpNameList(fp, parents);
|
||||
fp << "\n";
|
||||
set<Host::Ptr> parents = host->GetParentHosts();
|
||||
|
||||
if (!parents.empty()) {
|
||||
fp << "\t" << "parents" << "\t";
|
||||
DumpNameList(fp, parents);
|
||||
fp << "\n";
|
||||
}
|
||||
|
||||
hc = host->GetHostCheckService();
|
||||
}
|
||||
|
||||
if (hc) {
|
||||
ObjectLock olock(hc);
|
||||
|
||||
fp << "\t" << "check_interval" << "\t" << hc->GetCheckInterval() << "\n"
|
||||
<< "\t" << "retry_interval" << "\t" << hc->GetRetryInterval() << "\n"
|
||||
<< "\t" << "max_check_attempts" << "\t" << hc->GetMaxCheckAttempts() << "\n"
|
||||
<< "\t" << "active_checks_enabled" << "\t" << (hc->GetEnableActiveChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "passive_checks_enabled" << "\t" << (hc->GetEnablePassiveChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "notifications_enabled" << "\t" << (hc->GetEnableNotifications() ? 1 : 0) << "\n"
|
||||
<< "\t" << "notification_options" << "\t" << "d,u,r" << "\n"
|
||||
<< "\t" << "notification_interval" << "\t" << "60" << "\n"
|
||||
<< "\t" << "notification_period" << "\t" << "24x7" << "\n";
|
||||
}
|
||||
|
||||
fp << "\t" << "}" << "\n"
|
||||
@ -377,14 +392,14 @@ void CompatComponent::DumpServiceStatusAttrs(ostream& fp, const Service::Ptr& se
|
||||
<< "\t" << "last_state_change=" << service->GetLastStateChange() << "\n"
|
||||
<< "\t" << "last_hard_state_change=" << service->GetLastHardStateChange() << "\n"
|
||||
<< "\t" << "last_update=" << time(NULL) << "\n"
|
||||
<< "\t" << "notifications_enabled=" << (service->GetEnableNotifications() ? 1 : 0) << "\n"
|
||||
<< "\t" << "active_checks_enabled=" << (service->GetEnableActiveChecks() ? 1 : 0) <<"\n"
|
||||
<< "\t" << "passive_checks_enabled=" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "problem_has_been_acknowledged=" << (service->GetAcknowledgement() != AcknowledgementNone ? 1 : 0) << "\n"
|
||||
<< "\t" << "acknowledgement_type=" << static_cast<int>(service->GetAcknowledgement()) << "\n"
|
||||
<< "\t" << "acknowledgement_end_time=" << service->GetAcknowledgementExpiry() << "\n"
|
||||
<< "\t" << "scheduled_downtime_depth=" << (service->IsInDowntime() ? 1 : 0) << "\n"
|
||||
<< "\t" << "last_notification=" << service->GetLastNotification() << "\n"
|
||||
<< "\t" << "next_notification=" << service->GetNextNotification() << "\n";
|
||||
<< "\t" << "last_notification=" << service->GetLastNotification() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,6 +463,10 @@ void CompatComponent::DumpServiceObject(ostream& fp, const Service::Ptr& service
|
||||
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
||||
<< "\t" << "active_checks_enabled" << "\t" << (service->GetEnableActiveChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "passive_checks_enabled" << "\t" << (service->GetEnablePassiveChecks() ? 1 : 0) << "\n"
|
||||
<< "\t" << "notifications_enabled" << "\t" << (service->GetEnableNotifications() ? 1 : 0) << "\n"
|
||||
<< "\t" << "notification_options" << "\t" << "u,w,c,r" << "\n"
|
||||
<< "\t" << "notification_interval" << "\t" << "60" << "\n"
|
||||
<< "\t" << "notification_period" << "\t" << "24x7" << "\n"
|
||||
<< "\t" << "}" << "\n"
|
||||
<< "\n";
|
||||
}
|
||||
@ -508,8 +527,8 @@ void CompatComponent::StatusTimerHandler(void)
|
||||
<< "\t" << "program_start=" << startTime << "\n"
|
||||
<< "\t" << "active_service_checks_enabled=1" << "\n"
|
||||
<< "\t" << "passive_service_checks_enabled=1" << "\n"
|
||||
<< "\t" << "active_host_checks_enabled=0" << "\n"
|
||||
<< "\t" << "passive_host_checks_enabled=0" << "\n"
|
||||
<< "\t" << "active_host_checks_enabled=1" << "\n"
|
||||
<< "\t" << "passive_host_checks_enabled=1" << "\n"
|
||||
<< "\t" << "check_service_freshness=0" << "\n"
|
||||
<< "\t" << "check_host_freshness=0" << "\n"
|
||||
<< "\t" << "enable_notifications=1" << "\n"
|
||||
@ -531,6 +550,18 @@ void CompatComponent::StatusTimerHandler(void)
|
||||
<< "# This file is auto-generated. Do not modify this file." << "\n"
|
||||
<< "\n";
|
||||
|
||||
objectfp << "define timeperiod {"
|
||||
<< "\t" << "timeperiod_name" << "\t" << "24x7" << "\n"
|
||||
<< "\t" << "sunday" << "\t" << "00:00-24:00" << "\n"
|
||||
<< "\t" << "monday" << "\t" << "00:00-24:00" << "\n"
|
||||
<< "\t" << "tuesday" << "\t" << "00:00-24:00" << "\n"
|
||||
<< "\t" << "wednesday" << "\t" << "00:00-24:00" << "\n"
|
||||
<< "\t" << "thursday" << "\t" << "00:00-24:00" << "\n"
|
||||
<< "\t" << "friday" << "\t" << "00:00-24:00" << "\n"
|
||||
<< "\t" << "saturday" << "\t" << "00:00-24:00" << "\n"
|
||||
<< "\t" << "}" << "\n";
|
||||
|
||||
|
||||
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
|
||||
Host::Ptr host = static_pointer_cast<Host>(object);
|
||||
|
||||
|
@ -138,6 +138,12 @@ void ExternalCommandProcessor::Initialize(void)
|
||||
RegisterCommand("DEL_ALL_SVC_COMMENTS", &ExternalCommandProcessor::DelAllSvcComments);
|
||||
RegisterCommand("SEND_CUSTOM_HOST_NOTIFICATION", &ExternalCommandProcessor::SendCustomHostNotification);
|
||||
RegisterCommand("SEND_CUSTOM_SVC_NOTIFICATION", &ExternalCommandProcessor::SendCustomSvcNotification);
|
||||
RegisterCommand("DELAY_HOST_NOTIFICATION", &ExternalCommandProcessor::DelayHostNotification);
|
||||
RegisterCommand("DELAY_SVC_NOTIFICATION", &ExternalCommandProcessor::DelaySvcNotification);
|
||||
RegisterCommand("ENABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::EnableHostNotifications);
|
||||
RegisterCommand("DISABLE_HOST_NOTIFICATIONS", &ExternalCommandProcessor::DisableHostNotifications);
|
||||
RegisterCommand("ENABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::EnableSvcNotifications);
|
||||
RegisterCommand("DISABLE_SVC_NOTIFICATIONS", &ExternalCommandProcessor::DisableSvcNotifications);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -971,3 +977,78 @@ void ExternalCommandProcessor::SendCustomSvcNotification(double time, const vect
|
||||
Logger::Write(LogInformation, "icinga", "Sending custom notification for service " + service->GetName());
|
||||
service->RequestNotifications(NotificationCustom);
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::DelayHostNotification(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
|
||||
|
||||
Host::Ptr host = Host::GetByName(arguments[0]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Delaying notifications for host " + host->GetName());
|
||||
Service::Ptr service = host->GetHostCheckService();
|
||||
if (service) {
|
||||
service->SetLastNotification(Convert::ToDouble(arguments[1]));
|
||||
}
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::DelaySvcNotification(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 3)
|
||||
BOOST_THROW_EXCEPTION(invalid_argument("Expected 3 arguments."));
|
||||
|
||||
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Delaying notifications for service " + service->GetName());
|
||||
service->SetLastNotification(Convert::ToDouble(arguments[2]));
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::EnableHostNotifications(double, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 1)
|
||||
BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
|
||||
|
||||
Host::Ptr host = Host::GetByName(arguments[0]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Enabling notifications for host '" + arguments[0] + "'");
|
||||
Service::Ptr hc = host->GetHostCheckService();
|
||||
|
||||
if (hc)
|
||||
hc->SetEnableNotifications(true);
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::DisableHostNotifications(double, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 1)
|
||||
BOOST_THROW_EXCEPTION(invalid_argument("Expected 1 argument."));
|
||||
|
||||
Host::Ptr host = Host::GetByName(arguments[0]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Disabling notifications for host '" + arguments[0] + "'");
|
||||
Service::Ptr hc = host->GetHostCheckService();
|
||||
|
||||
if (hc)
|
||||
hc->SetEnableNotifications(false);
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::EnableSvcNotifications(double, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
|
||||
|
||||
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Enabling notifications for service '" + arguments[1] + "'");
|
||||
service->SetEnableNotifications(true);
|
||||
}
|
||||
|
||||
void ExternalCommandProcessor::DisableSvcNotifications(double, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
BOOST_THROW_EXCEPTION(invalid_argument("Expected 2 arguments."));
|
||||
|
||||
Service::Ptr service = Service::GetByNamePair(arguments[0], arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Disabling notifications for service '" + arguments[1] + "'");
|
||||
service->SetEnableNotifications(false);
|
||||
}
|
||||
|
@ -92,6 +92,12 @@ private:
|
||||
static void DelAllSvcComments(double time, const vector<String>& arguments);
|
||||
static void SendCustomHostNotification(double time, const vector<String>& arguments);
|
||||
static void SendCustomSvcNotification(double time, const vector<String>& arguments);
|
||||
static void DelayHostNotification(double time, const vector<String>& arguments);
|
||||
static void DelaySvcNotification(double time, const vector<String>& arguments);
|
||||
static void EnableHostNotifications(double time, const vector<String>& arguments);
|
||||
static void DisableHostNotifications(double time, const vector<String>& arguments);
|
||||
static void EnableSvcNotifications(double time, const vector<String>& arguments);
|
||||
static void DisableSvcNotifications(double time, const vector<String>& arguments);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -206,8 +206,8 @@ bool Service::GetEnableActiveChecks(void) const
|
||||
{
|
||||
if (m_EnableActiveChecks.IsEmpty())
|
||||
return true;
|
||||
|
||||
return static_cast<bool>(m_EnableActiveChecks);
|
||||
else
|
||||
return m_EnableActiveChecks;
|
||||
}
|
||||
|
||||
void Service::SetEnableActiveChecks(bool enabled)
|
||||
@ -220,8 +220,8 @@ bool Service::GetEnablePassiveChecks(void) const
|
||||
{
|
||||
if (m_EnablePassiveChecks.IsEmpty())
|
||||
return true;
|
||||
|
||||
return static_cast<bool>(m_EnablePassiveChecks);
|
||||
else
|
||||
return m_EnablePassiveChecks;
|
||||
}
|
||||
|
||||
void Service::SetEnablePassiveChecks(bool enabled)
|
||||
|
@ -41,6 +41,11 @@ void Service::RequestNotifications(NotificationType type) const
|
||||
|
||||
void Service::SendNotifications(NotificationType type)
|
||||
{
|
||||
if (!GetEnableNotifications()) {
|
||||
Logger::Write(LogInformation, "icinga", "Notifications are disabled for service '" + GetName() + "'.");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Sending notifications for service '" + GetName() + "'");
|
||||
|
||||
set<Notification::Ptr> notifications = GetNotifications();
|
||||
@ -239,12 +244,10 @@ void Service::UpdateSlaveNotifications(const Service::Ptr& self)
|
||||
|
||||
double Service::GetLastNotification(void) const
|
||||
{
|
||||
Value value = m_LastNotification;
|
||||
|
||||
if (value.IsEmpty())
|
||||
value = 0;
|
||||
|
||||
return value;
|
||||
if (m_LastNotification.IsEmpty())
|
||||
return 0;
|
||||
else
|
||||
return m_LastNotification;
|
||||
}
|
||||
|
||||
void Service::SetLastNotification(double time)
|
||||
@ -253,18 +256,16 @@ void Service::SetLastNotification(double time)
|
||||
Touch("last_notification");
|
||||
}
|
||||
|
||||
double Service::GetNextNotification(void) const
|
||||
bool Service::GetEnableNotifications(void) const
|
||||
{
|
||||
Value value = m_NextNotification;
|
||||
|
||||
if (value.IsEmpty())
|
||||
value = 0;
|
||||
|
||||
return value;
|
||||
if (m_EnableNotifications.IsEmpty())
|
||||
return true;
|
||||
else
|
||||
return m_EnableNotifications;
|
||||
}
|
||||
|
||||
void Service::SetNextNotification(double time)
|
||||
void Service::SetEnableNotifications(bool enabled)
|
||||
{
|
||||
m_NextNotification = time;
|
||||
Touch("next_notification");
|
||||
m_EnableNotifications = enabled;
|
||||
Touch("enable_notifications");
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ Service::Service(const Dictionary::Ptr& serializedObject)
|
||||
|
||||
RegisterAttribute("downtimes", Attribute_Replicated, &m_Downtimes);
|
||||
|
||||
RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications);
|
||||
RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification);
|
||||
RegisterAttribute("next_notification", Attribute_Replicated, &m_NextNotification);
|
||||
|
||||
SetSchedulingOffset(rand());
|
||||
}
|
||||
|
@ -235,6 +235,9 @@ public:
|
||||
static void ValidateCommentsCache(void);
|
||||
|
||||
/* Notifications */
|
||||
bool GetEnableNotifications(void) const;
|
||||
void SetEnableNotifications(bool enabled);
|
||||
|
||||
void RequestNotifications(NotificationType type) const;
|
||||
void SendNotifications(NotificationType type);
|
||||
|
||||
@ -248,9 +251,6 @@ public:
|
||||
double GetLastNotification(void) const;
|
||||
void SetLastNotification(double time);
|
||||
|
||||
double GetNextNotification(void) const;
|
||||
void SetNextNotification(double time);
|
||||
|
||||
protected:
|
||||
virtual void OnRegistrationCompleted(void);
|
||||
virtual void OnAttributeChanged(const String& name, const Value& oldValue);
|
||||
@ -324,8 +324,8 @@ private:
|
||||
void RemoveExpiredComments(void);
|
||||
|
||||
/* Notifications */
|
||||
Attribute<bool> m_EnableNotifications;
|
||||
Attribute<double> m_LastNotification;
|
||||
Attribute<double> m_NextNotification;
|
||||
|
||||
static map<String, set<Notification::WeakPtr> > m_NotificationsCache;
|
||||
static bool m_NotificationsCacheValid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user