void CompatComponent::DumpHostObject(ostream& fp, const Host::Ptr& host)
{
- ObjectLock olock(host);
-
- 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";
-
- set<Host::Ptr> parents = host->GetParentHosts();
-
- if (!parents.empty()) {
- fp << "\t" << "parents" << "\t";
- DumpNameList(fp, parents);
- fp << "\n";
+ Service::Ptr hc;
+
+ {
+ ObjectLock olock(host);
+
+ fp << "define host {" << "\n"
+ << "\t" << "host_name" << "\t" << host->GetName() << "\n"
+ << "\t" << "display_name" << "\t" << host->GetDisplayName() << "\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"
<< "\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";
}
}
<< "\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";
}
<< "\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"
<< "# 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);
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);
}
/**
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);
+}
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);
};
}
{
if (m_EnableActiveChecks.IsEmpty())
return true;
-
- return static_cast<bool>(m_EnableActiveChecks);
+ else
+ return m_EnableActiveChecks;
}
void Service::SetEnableActiveChecks(bool enabled)
{
if (m_EnablePassiveChecks.IsEmpty())
return true;
-
- return static_cast<bool>(m_EnablePassiveChecks);
+ else
+ return m_EnablePassiveChecks;
}
void Service::SetEnablePassiveChecks(bool enabled)
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();
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)
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");
}
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());
}
static void ValidateCommentsCache(void);
/* Notifications */
+ bool GetEnableNotifications(void) const;
+ void SetEnableNotifications(bool enabled);
+
void RequestNotifications(NotificationType type) const;
void SendNotifications(NotificationType type);
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);
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;