From a401d871eb672426ebf3dd80eeb5d73f3dc949b9 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 25 Sep 2013 08:51:55 +0200 Subject: [PATCH] config: Don't clone host/service attributes. --- lib/icinga/host.cpp | 18 ---- lib/icinga/icinga-type.conf | 64 ++----------- lib/icinga/service-notification.cpp | 134 ++++++++++------------------ lib/icinga/service.cpp | 2 + 4 files changed, 52 insertions(+), 166 deletions(-) diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 37e789090..06eb90c84 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -227,24 +227,6 @@ void Host::UpdateSlaveServices(void) } } - /* Clone attributes from the host object. */ - std::set keys; - keys.insert("check_interval"); - keys.insert("retry_interval"); - keys.insert("servicegroups"); - keys.insert("notification_interval"); - keys.insert("notification_type_filter"); - keys.insert("notification_state_filter"); - keys.insert("check_period"); - keys.insert("servicedependencies"); - keys.insert("hostdependencies"); - keys.insert("authorities"); - keys.insert("domains"); - - ExpressionList::Ptr host_exprl = boost::make_shared(); - item->GetLinkedExpressionList()->ExtractFiltered(keys, host_exprl); - builder->AddExpressionList(host_exprl); - /* Clone attributes from the service expression list. */ ExpressionList::Ptr svc_exprl = boost::make_shared(); item->GetLinkedExpressionList()->ExtractPath(path, svc_exprl); diff --git a/lib/icinga/icinga-type.conf b/lib/icinga/icinga-type.conf index dfb8dcc2a..93974874b 100644 --- a/lib/icinga/icinga-type.conf +++ b/lib/icinga/icinga-type.conf @@ -45,59 +45,16 @@ type Host { } }, - %attribute dictionary "notifications" { - %attribute dictionary "*" { - %attribute array "templates" { - %attribute name(Notification) "*" - }, - - %attribute any "*" - } - }, - - /* service attributes */ - %attribute number "max_check_attempts", - %attribute name(TimePeriod) "check_period", - %attribute number "check_interval", - %attribute number "retry_interval", - - %attribute number "enable_notifications", - %attribute number "notification_interval", - %attribute name(TimePeriod) "notification_period", - - %attribute number "enable_flapping", - %attribute number "flapping_threshold", - - %attribute number "notification_type_filter", - %attribute number "notification_state_filter", - %attribute dictionary "macros" { %attribute string "*" }, - - %attribute dictionary "custom" { - %attribute string "*" - }, - - %attribute array "servicegroups" { - %attribute name(ServiceGroup) "*" - }, - %attribute array "checkers" { - %attribute string "*" - } } type HostGroup { - %attribute string "display_name", - %attribute string "notes_url", - %attribute string "action_url" + %attribute string "display_name" } type IcingaApplication { - %attribute string "pid_path", - %attribute dictionary "macros" { - %attribute string "*" - } } type Service { @@ -107,11 +64,8 @@ type Service { %attribute string "short_name", %attribute string "display_name", - %attribute dictionary "macros" { - %attribute string "*" - }, - %attribute dictionary "custom" { + %attribute dictionary "macros" { %attribute string "*" }, @@ -147,9 +101,6 @@ type Service { %attribute array "servicegroups" { %attribute name(ServiceGroup) "*" }, - %attribute array "checkers" { - %attribute string "*" - }, %attribute dictionary "notifications" { %attribute dictionary "*" { @@ -163,14 +114,12 @@ type Service { } type ServiceGroup { - %attribute string "display_name", - %attribute string "notes_url", - %attribute string "action_url" + %attribute string "display_name" } type Notification { %require "host_name", - %attribute string "host_name", + %attribute name(Host) "host_name", %attribute string "service", %attribute dictionary "macros" { @@ -215,13 +164,10 @@ type User { %attribute number "notification_type_filter", %attribute number "notification_state_filter", %attribute name(TimePeriod) "notification_period" - } type UserGroup { - %attribute string "display_name", - %attribute string "action_url", - %attribute string "notes_url" + %attribute string "display_name" } type TimePeriod { diff --git a/lib/icinga/service-notification.cpp b/lib/icinga/service-notification.cpp index 4ff4d1ca4..74ba4e6f6 100644 --- a/lib/icinga/service-notification.cpp +++ b/lib/icinga/service-notification.cpp @@ -98,116 +98,72 @@ void Service::RemoveNotification(const Notification::Ptr& notification) void Service::UpdateSlaveNotifications(void) { - ConfigItem::Ptr serviceItem, hostItem; - - serviceItem = ConfigItem::GetObject("Service", GetName()); + ConfigItem::Ptr item = ConfigItem::GetObject("Service", GetName()); /* Don't create slave notifications unless we own this object */ - if (!serviceItem) - return; - - Host::Ptr host = GetHost(); - - if (!host) + if (!item) return; - hostItem = ConfigItem::GetObject("Host", host->GetName()); + /* Service notification descs */ + Dictionary::Ptr descs = GetNotificationDescriptions(); - /* Don't create slave notifications unless we own the host */ - if (!hostItem) + if (!descs) return; - std::vector descLists; - - descLists.push_back(GetNotificationDescriptions()); - descLists.push_back(host->GetNotificationDescriptions()); + ObjectLock olock(descs); - for (int i = 0; i < 2; i++) { - Dictionary::Ptr descs; - ConfigItem::Ptr item; + String nfcname; + Value nfcdesc; + BOOST_FOREACH(boost::tie(nfcname, nfcdesc), descs) { + std::ostringstream namebuf; + namebuf << GetName() << ":" << nfcname; + String name = namebuf.str(); - if (i == 0) { - /* Host notification descs */ - descs = host->GetNotificationDescriptions(); - item = hostItem; - } else { - /* Service notification descs */ - descs = GetNotificationDescriptions(); - item = serviceItem; - } + std::vector path; + path.push_back("notifications"); + path.push_back(nfcname); - if (!descs) - continue; + DebugInfo di; + item->GetLinkedExpressionList()->FindDebugInfoPath(path, di); - ObjectLock olock(descs); + if (di.Path.IsEmpty()) + di = item->GetDebugInfo(); - String nfcname; - Value nfcdesc; - BOOST_FOREACH(boost::tie(nfcname, nfcdesc), descs) { - std::ostringstream namebuf; - namebuf << GetName() << ":" << nfcname; - String name = namebuf.str(); + ConfigItemBuilder::Ptr builder = boost::make_shared(di); + builder->SetType("Notification"); + builder->SetName(name); + builder->AddExpression("host_name", OperatorSet, GetHost()->GetName()); + builder->AddExpression("service", OperatorSet, GetShortName()); - std::vector path; - path.push_back("notifications"); - path.push_back(nfcname); + if (!nfcdesc.IsObjectType()) + BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary.")); - DebugInfo di; - item->GetLinkedExpressionList()->FindDebugInfoPath(path, di); + Dictionary::Ptr notification = nfcdesc; - if (di.Path.IsEmpty()) - di = item->GetDebugInfo(); + Array::Ptr templates = notification->Get("templates"); - ConfigItemBuilder::Ptr builder = boost::make_shared(di); - builder->SetType("Notification"); - builder->SetName(name); - builder->AddExpression("host_name", OperatorSet, host->GetName()); - builder->AddExpression("service", OperatorSet, GetShortName()); + if (templates) { + ObjectLock tlock(templates); - if (!nfcdesc.IsObjectType()) - BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary.")); + BOOST_FOREACH(const Value& tmpl, templates) { + builder->AddParent(tmpl); + } + } - Dictionary::Ptr notification = nfcdesc; + /* Clone attributes from the notification expression list. */ + ExpressionList::Ptr nfc_exprl = boost::make_shared(); + item->GetLinkedExpressionList()->ExtractPath(path, nfc_exprl); - Array::Ptr templates = notification->Get("templates"); + std::vector dpath; + dpath.push_back("templates"); + nfc_exprl->ErasePath(dpath); - if (templates) { - ObjectLock tlock(templates); + builder->AddExpressionList(nfc_exprl); - BOOST_FOREACH(const Value& tmpl, templates) { - builder->AddParent(tmpl); - } - } - - /* Clone attributes from the host/service object. */ - std::set keys; - keys.insert("users"); - keys.insert("groups"); - keys.insert("notification_interval"); - keys.insert("notification_period"); - keys.insert("notification_type_filter"); - keys.insert("notification_state_filter"); - keys.insert("export_macros"); - - ExpressionList::Ptr svc_exprl = boost::make_shared(); - item->GetLinkedExpressionList()->ExtractFiltered(keys, svc_exprl); - builder->AddExpressionList(svc_exprl); - - /* Clone attributes from the notification expression list. */ - ExpressionList::Ptr nfc_exprl = boost::make_shared(); - item->GetLinkedExpressionList()->ExtractPath(path, nfc_exprl); - - std::vector dpath; - dpath.push_back("templates"); - nfc_exprl->ErasePath(dpath); - - builder->AddExpressionList(nfc_exprl); - - ConfigItem::Ptr notificationItem = builder->Compile(); - notificationItem->Register(); - DynamicObject::Ptr dobj = notificationItem->Commit(); - dobj->OnConfigLoaded(); - } + ConfigItem::Ptr notificationItem = builder->Compile(); + notificationItem->Register(); + DynamicObject::Ptr dobj = notificationItem->Commit(); + dobj->OnConfigLoaded(); } } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index d09ff5f01..09eb2ef7b 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -46,6 +46,8 @@ void Service::Start(void) { DynamicObject::Start(); + VERIFY(GetHost()); + SetSchedulingOffset(rand()); UpdateNextCheck(); -- 2.40.0