diff --git a/lib/config/aexpression.cpp b/lib/config/aexpression.cpp index 09b055ec8..307c05d80 100644 --- a/lib/config/aexpression.cpp +++ b/lib/config/aexpression.cpp @@ -53,66 +53,6 @@ Value AExpression::Evaluate(const Dictionary::Ptr& locals) const } } -void AExpression::ExtractPath(const std::vector& path, const Array::Ptr& result) const -{ - ASSERT(!path.empty()); - - if (m_Operator == &AExpression::OpDict) { - Array::Ptr exprl = m_Operand1; - ObjectLock olock(exprl); - BOOST_FOREACH(const AExpression::Ptr& expr, exprl) { - expr->ExtractPath(path, result); - } - } else if ((m_Operator == &AExpression::OpSet || m_Operator == &AExpression::OpSetPlus || - m_Operator == &AExpression::OpSetMinus || m_Operator == &AExpression::OpSetMultiply || - m_Operator == &AExpression::OpSetDivide) && path[0] == m_Operand1) { - AExpression::Ptr exprl = m_Operand2; - - if (path.size() == 1) { - if (m_Operator == &AExpression::OpSet) - result->Clear(); - - if (exprl->m_Operator != &AExpression::OpDict) - BOOST_THROW_EXCEPTION(ConfigError("The '" + path[0] + "' attribute must be a dictionary.") << errinfo_debuginfo(m_DebugInfo)); - - Array::Ptr subexprl = exprl->m_Operand1; - ObjectLock olock(subexprl); - BOOST_FOREACH(const AExpression::Ptr& expr, subexprl) { - result->Add(expr); - } - - return; - } - - std::vector sub_path(path.begin() + 1, path.end()); - exprl->ExtractPath(sub_path, result); - } -} - -void AExpression::FindDebugInfoPath(const std::vector& path, DebugInfo& result) const -{ - ASSERT(!path.empty()); - - if (m_Operator == &AExpression::OpDict) { - Array::Ptr exprl = m_Operand1; - ObjectLock olock(exprl); - BOOST_FOREACH(const AExpression::Ptr& expr, exprl) { - expr->FindDebugInfoPath(path, result); - } - } else if ((m_Operator == &AExpression::OpSet || m_Operator == &AExpression::OpSetPlus || - m_Operator == &AExpression::OpSetMinus || m_Operator == &AExpression::OpSetMultiply || - m_Operator == &AExpression::OpSetDivide) && path[0] == m_Operand1) { - AExpression::Ptr exprl = m_Operand2; - - if (path.size() == 1) { - result = m_DebugInfo; - } else { - std::vector sub_path(path.begin() + 1, path.end()); - exprl->FindDebugInfoPath(sub_path, result); - } - } -} - void AExpression::MakeInline(void) { if (m_Operator == &AExpression::OpDict) diff --git a/lib/config/aexpression.h b/lib/config/aexpression.h index 05bf14500..5ad540220 100644 --- a/lib/config/aexpression.h +++ b/lib/config/aexpression.h @@ -42,8 +42,6 @@ public: AExpression(OpCallback op, const Value& operand1, const Value& operand2, const DebugInfo& di); Value Evaluate(const Dictionary::Ptr& locals) const; - void ExtractPath(const std::vector& path, const Array::Ptr& result) const; - void FindDebugInfoPath(const std::vector& path, DebugInfo& result) const; void MakeInline(void); diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 2306c762a..cf40a2a06 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -57,8 +57,6 @@ void Host::OnConfigLoaded(void) hg->AddMember(GetSelf()); } } - - UpdateSlaveServices(); } void Host::Stop(void) @@ -92,81 +90,6 @@ bool Host::IsReachable(DependencyType dt, shared_ptr *failedDependen return hc->IsReachable(dt, failedDependency); } -void Host::UpdateSlaveServices(void) -{ - ASSERT(!OwnsLock()); - - Dictionary::Ptr service_descriptions = GetServiceDescriptions(); - - if (!service_descriptions ||service_descriptions->GetLength() == 0) - return; - - ConfigItem::Ptr item = ConfigItem::GetObject("Host", GetName()); - - ObjectLock olock(service_descriptions); - BOOST_FOREACH(const Dictionary::Pair& kv, service_descriptions) { - std::ostringstream namebuf; - namebuf << GetName() << "!" << kv.first; - String name = namebuf.str(); - - std::vector path; - path.push_back("services"); - path.push_back(kv.first); - - AExpression::Ptr exprl; - - { - ObjectLock ilock(item); - - exprl = item->GetExpressionList(); - } - - DebugInfo di; - exprl->FindDebugInfoPath(path, di); - - if (di.Path.IsEmpty()) - di = item->GetDebugInfo(); - - ConfigItemBuilder::Ptr builder = make_shared(di); - builder->SetType("Service"); - builder->SetName(name); - - Dictionary::Ptr service = kv.second; - - Array::Ptr templates = service->Get("templates"); - - if (templates) { - ObjectLock olock(templates); - - BOOST_FOREACH(const Value& tmpl, templates) { - AExpression::Ptr atype = make_shared(&AExpression::OpLiteral, "Service", di); - AExpression::Ptr atmpl = make_shared(&AExpression::OpLiteral, tmpl, di); - builder->AddExpression(make_shared(&AExpression::OpImport, atype, atmpl, di)); - } - } - - builder->AddExpression(make_shared(&AExpression::OpSet, "host", make_shared(&AExpression::OpLiteral, GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "display_name", make_shared(&AExpression::OpLiteral, kv.first, di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "short_name", make_shared(&AExpression::OpLiteral, kv.first, di), di)); - - if (!kv.second.IsObjectType()) - BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary.")); - - /* Clone attributes from the service expression list. */ - Array::Ptr svc_exprl = make_shared(); - exprl->ExtractPath(path, svc_exprl); - - builder->AddExpression(make_shared(&AExpression::OpDict, svc_exprl, true, di)); - - builder->SetScope(item->GetScope()); - - ConfigItem::Ptr serviceItem = builder->Compile(); - serviceItem->Register(); - DynamicObject::Ptr dobj = serviceItem->Commit(); - dobj->OnConfigLoaded(); - } -} - std::set Host::GetServices(void) const { boost::mutex::scoped_lock lock(m_ServicesMutex); diff --git a/lib/icinga/host.h b/lib/icinga/host.h index c49fab286..bf1ae422e 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -114,8 +114,6 @@ private: mutable boost::mutex m_ServicesMutex; std::map > m_Services; - void UpdateSlaveServices(void); - static void RefreshServicesCache(void); }; diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index a969f9e59..79ce65faf 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -23,25 +23,6 @@ type Host { %attribute array "groups" { %attribute name(HostGroup) "*" }, - %attribute dictionary "services" { - %attribute dictionary "*" { - %attribute array "templates" { - %attribute name(Service) "*" - }, - - %attribute any "*" - } - }, - - %attribute dictionary "dependencies" { - %attribute dictionary "*" { - %attribute array "templates" { - %attribute name(Dependency) "*" - }, - - %attribute any "*" - } - }, %attribute dictionary "macros" { %attribute string "*" @@ -93,42 +74,10 @@ type Service { %attribute number "volatile", - %attribute dictionary "dependencies" { - %attribute dictionary "*" { - %attribute array "templates" { - %attribute name(Dependency) "*" - }, - - %attribute any "*" - } - }, - %attribute array "groups" { %attribute name(ServiceGroup) "*" }, - %attribute dictionary "notifications" { - %attribute dictionary "*" { - %attribute array "templates" { - %attribute name(Notification) "*" - }, - - %attribute any "*" - } - }, - - %attribute dictionary "scheduled_downtimes" { - %attribute dictionary "*" { - %attribute array "templates" { - %attribute name(ScheduledDowntime) "*" - }, - - %attribute any "*" - } - }, - - %attribute any "templates", - %attribute array "authorities" { %attribute name(Endpoint) "*" }, @@ -170,8 +119,6 @@ type Notification { %attribute number "notification_type_filter", %attribute number "notification_state_filter", - %attribute any "templates", - %attribute array "authorities" { %attribute name(Endpoint) "*" }, @@ -278,8 +225,6 @@ type ScheduledDowntime { %attribute dictionary "ranges" { %attribute string "*" }, - - %attribute any "templates" } type Dependency { diff --git a/lib/icinga/service-dependency.cpp b/lib/icinga/service-dependency.cpp index ea41d83c6..d17e99501 100644 --- a/lib/icinga/service-dependency.cpp +++ b/lib/icinga/service-dependency.cpp @@ -154,93 +154,3 @@ std::set Service::GetChildServices(void) const return parents; } -void Service::UpdateSlaveDependencies(void) -{ - /* - * pass == 0 -> steal host's dependency definitions - * pass == 1 -> service's dependencies - */ - for (int pass = 0; pass < 2; pass++) { - /* Service dependency descs */ - Dictionary::Ptr descs; - - if (pass == 0 && !IsHostCheck()) - continue; - - if (pass == 0) - descs = GetHost()->GetDependencyDescriptions(); - else - descs = GetDependencyDescriptions(); - - if (!descs || descs->GetLength() == 0) - continue; - - ConfigItem::Ptr item; - - if (pass == 0) - item = ConfigItem::GetObject("Host", GetHost()->GetName()); - else - item = ConfigItem::GetObject("Service", GetName()); - - ObjectLock olock(descs); - - BOOST_FOREACH(const Dictionary::Pair& kv, descs) { - std::ostringstream namebuf; - namebuf << GetName() << "!" << kv.first; - String name = namebuf.str(); - - std::vector path; - path.push_back("dependencies"); - path.push_back(kv.first); - - AExpression::Ptr exprl; - - { - ObjectLock ilock(item); - - exprl = item->GetExpressionList(); - } - - DebugInfo di; - exprl->FindDebugInfoPath(path, di); - - if (di.Path.IsEmpty()) - di = item->GetDebugInfo(); - - ConfigItemBuilder::Ptr builder = make_shared(di); - builder->SetType("Dependency"); - builder->SetName(name); - - - Dictionary::Ptr dependency = kv.second; - - Array::Ptr templates = dependency->Get("templates"); - - if (templates) { - ObjectLock tlock(templates); - - BOOST_FOREACH(const Value& tmpl, templates) { - AExpression::Ptr atype = make_shared(&AExpression::OpLiteral, "Dependency", di); - AExpression::Ptr atmpl = make_shared(&AExpression::OpLiteral, tmpl, di); - builder->AddExpression(make_shared(&AExpression::OpImport, atype, atmpl, di)); - } - } - - builder->AddExpression(make_shared(&AExpression::OpSet, "child_host", make_shared(&AExpression::OpLiteral, GetHost()->GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "child_service", make_shared(&AExpression::OpLiteral, GetShortName(), di), di)); - - /* Clone attributes from the scheduled downtime expression list. */ - Array::Ptr sd_exprl = make_shared(); - exprl->ExtractPath(path, sd_exprl); - - builder->AddExpression(make_shared(&AExpression::OpDict, sd_exprl, true, di)); - - builder->SetScope(item->GetScope()); - - ConfigItem::Ptr dependencyItem = builder->Compile(); - dependencyItem->Register(); - DynamicObject::Ptr dobj = dependencyItem->Commit(); - dobj->OnConfigLoaded(); - } - } -} diff --git a/lib/icinga/service-downtime.cpp b/lib/icinga/service-downtime.cpp index aa11fd797..93df0d8e2 100644 --- a/lib/icinga/service-downtime.cpp +++ b/lib/icinga/service-downtime.cpp @@ -321,73 +321,3 @@ int Service::GetDowntimeDepth(void) const return downtime_depth; } -void Service::UpdateSlaveScheduledDowntimes(void) -{ - /* Service scheduled downtime descs */ - Dictionary::Ptr descs = GetScheduledDowntimeDescriptions(); - - if (!descs || descs->GetLength() == 0) - return; - - ConfigItem::Ptr item = ConfigItem::GetObject("Service", GetName()); - - ObjectLock olock(descs); - - BOOST_FOREACH(const Dictionary::Pair& kv, descs) { - std::ostringstream namebuf; - namebuf << GetName() << "!" << kv.first; - String name = namebuf.str(); - - std::vector path; - path.push_back("scheduled_downtimes"); - path.push_back(kv.first); - - AExpression::Ptr exprl; - - { - ObjectLock ilock(item); - - exprl = item->GetExpressionList(); - } - - DebugInfo di; - exprl->FindDebugInfoPath(path, di); - - if (di.Path.IsEmpty()) - di = item->GetDebugInfo(); - - ConfigItemBuilder::Ptr builder = make_shared(di); - builder->SetType("ScheduledDowntime"); - builder->SetName(name); - - Dictionary::Ptr scheduledDowntime = kv.second; - - Array::Ptr templates = scheduledDowntime->Get("templates"); - - if (templates) { - ObjectLock tlock(templates); - - BOOST_FOREACH(const Value& tmpl, templates) { - AExpression::Ptr atype = make_shared(&AExpression::OpLiteral, "ScheduledDowntime", di); - AExpression::Ptr atmpl = make_shared(&AExpression::OpLiteral, tmpl, di); - builder->AddExpression(make_shared(&AExpression::OpImport, atype, atmpl, di)); - } - } - - builder->AddExpression(make_shared(&AExpression::OpSet, "host", make_shared(&AExpression::OpLiteral, GetHost()->GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "service", make_shared(&AExpression::OpLiteral, GetShortName(), di), di)); - - /* Clone attributes from the scheduled downtime expression list. */ - Array::Ptr sd_exprl = make_shared(); - exprl->ExtractPath(path, sd_exprl); - - builder->AddExpression(make_shared(&AExpression::OpDict, sd_exprl, true, di)); - - builder->SetScope(item->GetScope()); - - ConfigItem::Ptr scheduledDowntimeItem = builder->Compile(); - scheduledDowntimeItem->Register(); - DynamicObject::Ptr dobj = scheduledDowntimeItem->Commit(); - dobj->OnConfigLoaded(); - } -} diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 6a4942ac9..ed49fb8f8 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -100,77 +100,6 @@ void Service::RemoveNotification(const Notification::Ptr& notification) m_Notifications.erase(notification); } -void Service::UpdateSlaveNotifications(void) -{ - /* Service notification descs */ - Dictionary::Ptr descs = GetNotificationDescriptions(); - - if (!descs || descs->GetLength() == 0) - return; - - ConfigItem::Ptr item = ConfigItem::GetObject("Service", GetName()); - - ObjectLock olock(descs); - - BOOST_FOREACH(const Dictionary::Pair& kv, descs) { - std::ostringstream namebuf; - namebuf << GetName() << "!" << kv.first; - String name = namebuf.str(); - - std::vector path; - path.push_back("notifications"); - path.push_back(kv.first); - - AExpression::Ptr exprl; - - { - ObjectLock ilock(item); - - exprl = item->GetExpressionList(); - } - - DebugInfo di; - exprl->FindDebugInfoPath(path, di); - - if (di.Path.IsEmpty()) - di = item->GetDebugInfo(); - - ConfigItemBuilder::Ptr builder = make_shared(di); - builder->SetType("Notification"); - builder->SetName(name); - - Dictionary::Ptr notification = kv.second; - - Array::Ptr templates = notification->Get("templates"); - - if (templates) { - ObjectLock tlock(templates); - - BOOST_FOREACH(const Value& tmpl, templates) { - AExpression::Ptr atype = make_shared(&AExpression::OpLiteral, "Notification", di); - AExpression::Ptr atmpl = make_shared(&AExpression::OpLiteral, tmpl, di); - builder->AddExpression(make_shared(&AExpression::OpImport, atype, atmpl, di)); - } - } - - builder->AddExpression(make_shared(&AExpression::OpSet, "host", make_shared(&AExpression::OpLiteral, GetHost()->GetName(), di), di)); - builder->AddExpression(make_shared(&AExpression::OpSet, "service", make_shared(&AExpression::OpLiteral, GetShortName(), di), di)); - - /* Clone attributes from the notification expression list. */ - Array::Ptr nfc_exprl = make_shared(); - exprl->ExtractPath(path, nfc_exprl); - - builder->AddExpression(make_shared(&AExpression::OpDict, nfc_exprl, true, di)); - - builder->SetScope(item->GetScope()); - - ConfigItem::Ptr notificationItem = builder->Compile(); - notificationItem->Register(); - DynamicObject::Ptr dobj = notificationItem->Commit(); - dobj->OnConfigLoaded(); - } -} - bool Service::GetEnableNotifications(void) const { if (!GetOverrideEnableNotifications().IsEmpty()) diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index a0c933cbd..c2b0de52c 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -76,10 +76,6 @@ void Service::OnConfigLoaded(void) if (m_Host) m_Host->AddService(GetSelf()); - UpdateSlaveNotifications(); - UpdateSlaveScheduledDowntimes(); - UpdateSlaveDependencies(); - SetSchedulingOffset(Utility::Random()); } diff --git a/lib/icinga/service.h b/lib/icinga/service.h index f4deaf5b7..3a76626f1 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -220,8 +220,6 @@ public: bool IsInDowntime(void) const; bool IsAcknowledged(void); - void UpdateSlaveScheduledDowntimes(void); - /* Comments */ static int GetNextCommentID(void); @@ -251,8 +249,6 @@ public: void ResetNotificationNumbers(void); - void UpdateSlaveNotifications(void); - /* Event Handler */ void ExecuteEventHandler(void); @@ -284,8 +280,6 @@ public: void RemoveReverseDependency(const shared_ptr& dep); std::set > GetReverseDependencies(void) const; - void UpdateSlaveDependencies(void); - protected: virtual void Start(void);