mirror of https://github.com/Icinga/icinga2.git
config: Don't clone host/service attributes.
This commit is contained in:
parent
bf1a800e39
commit
a401d871eb
|
@ -227,24 +227,6 @@ void Host::UpdateSlaveServices(void)
|
|||
}
|
||||
}
|
||||
|
||||
/* Clone attributes from the host object. */
|
||||
std::set<String, string_iless> 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<ExpressionList>();
|
||||
item->GetLinkedExpressionList()->ExtractFiltered(keys, host_exprl);
|
||||
builder->AddExpressionList(host_exprl);
|
||||
|
||||
/* Clone attributes from the service expression list. */
|
||||
ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
|
||||
item->GetLinkedExpressionList()->ExtractPath(path, svc_exprl);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
Host::Ptr host = GetHost();
|
||||
/* Service notification descs */
|
||||
Dictionary::Ptr descs = GetNotificationDescriptions();
|
||||
|
||||
if (!host)
|
||||
if (!descs)
|
||||
return;
|
||||
|
||||
hostItem = ConfigItem::GetObject("Host", host->GetName());
|
||||
ObjectLock olock(descs);
|
||||
|
||||
/* Don't create slave notifications unless we own the host */
|
||||
if (!hostItem)
|
||||
return;
|
||||
String nfcname;
|
||||
Value nfcdesc;
|
||||
BOOST_FOREACH(boost::tie(nfcname, nfcdesc), descs) {
|
||||
std::ostringstream namebuf;
|
||||
namebuf << GetName() << ":" << nfcname;
|
||||
String name = namebuf.str();
|
||||
|
||||
std::vector<Dictionary::Ptr> descLists;
|
||||
std::vector<String> path;
|
||||
path.push_back("notifications");
|
||||
path.push_back(nfcname);
|
||||
|
||||
descLists.push_back(GetNotificationDescriptions());
|
||||
descLists.push_back(host->GetNotificationDescriptions());
|
||||
DebugInfo di;
|
||||
item->GetLinkedExpressionList()->FindDebugInfoPath(path, di);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Dictionary::Ptr descs;
|
||||
ConfigItem::Ptr item;
|
||||
if (di.Path.IsEmpty())
|
||||
di = item->GetDebugInfo();
|
||||
|
||||
if (i == 0) {
|
||||
/* Host notification descs */
|
||||
descs = host->GetNotificationDescriptions();
|
||||
item = hostItem;
|
||||
} else {
|
||||
/* Service notification descs */
|
||||
descs = GetNotificationDescriptions();
|
||||
item = serviceItem;
|
||||
}
|
||||
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(di);
|
||||
builder->SetType("Notification");
|
||||
builder->SetName(name);
|
||||
builder->AddExpression("host_name", OperatorSet, GetHost()->GetName());
|
||||
builder->AddExpression("service", OperatorSet, GetShortName());
|
||||
|
||||
if (!descs)
|
||||
continue;
|
||||
if (!nfcdesc.IsObjectType<Dictionary>())
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary."));
|
||||
|
||||
ObjectLock olock(descs);
|
||||
Dictionary::Ptr notification = nfcdesc;
|
||||
|
||||
String nfcname;
|
||||
Value nfcdesc;
|
||||
BOOST_FOREACH(boost::tie(nfcname, nfcdesc), descs) {
|
||||
std::ostringstream namebuf;
|
||||
namebuf << GetName() << ":" << nfcname;
|
||||
String name = namebuf.str();
|
||||
Array::Ptr templates = notification->Get("templates");
|
||||
|
||||
std::vector<String> path;
|
||||
path.push_back("notifications");
|
||||
path.push_back(nfcname);
|
||||
if (templates) {
|
||||
ObjectLock tlock(templates);
|
||||
|
||||
DebugInfo di;
|
||||
item->GetLinkedExpressionList()->FindDebugInfoPath(path, di);
|
||||
|
||||
if (di.Path.IsEmpty())
|
||||
di = item->GetDebugInfo();
|
||||
|
||||
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(di);
|
||||
builder->SetType("Notification");
|
||||
builder->SetName(name);
|
||||
builder->AddExpression("host_name", OperatorSet, host->GetName());
|
||||
builder->AddExpression("service", OperatorSet, GetShortName());
|
||||
|
||||
if (!nfcdesc.IsObjectType<Dictionary>())
|
||||
BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary."));
|
||||
|
||||
Dictionary::Ptr notification = nfcdesc;
|
||||
|
||||
Array::Ptr templates = notification->Get("templates");
|
||||
|
||||
if (templates) {
|
||||
ObjectLock tlock(templates);
|
||||
|
||||
BOOST_FOREACH(const Value& tmpl, templates) {
|
||||
builder->AddParent(tmpl);
|
||||
}
|
||||
BOOST_FOREACH(const Value& tmpl, templates) {
|
||||
builder->AddParent(tmpl);
|
||||
}
|
||||
|
||||
/* Clone attributes from the host/service object. */
|
||||
std::set<String, string_iless> 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<ExpressionList>();
|
||||
item->GetLinkedExpressionList()->ExtractFiltered(keys, svc_exprl);
|
||||
builder->AddExpressionList(svc_exprl);
|
||||
|
||||
/* Clone attributes from the notification expression list. */
|
||||
ExpressionList::Ptr nfc_exprl = boost::make_shared<ExpressionList>();
|
||||
item->GetLinkedExpressionList()->ExtractPath(path, nfc_exprl);
|
||||
|
||||
std::vector<String> 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();
|
||||
}
|
||||
|
||||
/* Clone attributes from the notification expression list. */
|
||||
ExpressionList::Ptr nfc_exprl = boost::make_shared<ExpressionList>();
|
||||
item->GetLinkedExpressionList()->ExtractPath(path, nfc_exprl);
|
||||
|
||||
std::vector<String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ void Service::Start(void)
|
|||
{
|
||||
DynamicObject::Start();
|
||||
|
||||
VERIFY(GetHost());
|
||||
|
||||
SetSchedulingOffset(rand());
|
||||
UpdateNextCheck();
|
||||
|
||||
|
|
Loading…
Reference in New Issue