mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 06:34:42 +02:00
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. */
|
/* Clone attributes from the service expression list. */
|
||||||
ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
|
ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
|
||||||
item->GetLinkedExpressionList()->ExtractPath(path, svc_exprl);
|
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 dictionary "macros" {
|
||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
%attribute dictionary "custom" {
|
|
||||||
%attribute string "*"
|
|
||||||
},
|
|
||||||
|
|
||||||
%attribute array "servicegroups" {
|
|
||||||
%attribute name(ServiceGroup) "*"
|
|
||||||
},
|
|
||||||
%attribute array "checkers" {
|
|
||||||
%attribute string "*"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HostGroup {
|
type HostGroup {
|
||||||
%attribute string "display_name",
|
%attribute string "display_name"
|
||||||
%attribute string "notes_url",
|
|
||||||
%attribute string "action_url"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type IcingaApplication {
|
type IcingaApplication {
|
||||||
%attribute string "pid_path",
|
|
||||||
%attribute dictionary "macros" {
|
|
||||||
%attribute string "*"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service {
|
type Service {
|
||||||
@ -107,11 +64,8 @@ type Service {
|
|||||||
%attribute string "short_name",
|
%attribute string "short_name",
|
||||||
|
|
||||||
%attribute string "display_name",
|
%attribute string "display_name",
|
||||||
%attribute dictionary "macros" {
|
|
||||||
%attribute string "*"
|
|
||||||
},
|
|
||||||
|
|
||||||
%attribute dictionary "custom" {
|
%attribute dictionary "macros" {
|
||||||
%attribute string "*"
|
%attribute string "*"
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -147,9 +101,6 @@ type Service {
|
|||||||
%attribute array "servicegroups" {
|
%attribute array "servicegroups" {
|
||||||
%attribute name(ServiceGroup) "*"
|
%attribute name(ServiceGroup) "*"
|
||||||
},
|
},
|
||||||
%attribute array "checkers" {
|
|
||||||
%attribute string "*"
|
|
||||||
},
|
|
||||||
|
|
||||||
%attribute dictionary "notifications" {
|
%attribute dictionary "notifications" {
|
||||||
%attribute dictionary "*" {
|
%attribute dictionary "*" {
|
||||||
@ -163,14 +114,12 @@ type Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ServiceGroup {
|
type ServiceGroup {
|
||||||
%attribute string "display_name",
|
%attribute string "display_name"
|
||||||
%attribute string "notes_url",
|
|
||||||
%attribute string "action_url"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Notification {
|
type Notification {
|
||||||
%require "host_name",
|
%require "host_name",
|
||||||
%attribute string "host_name",
|
%attribute name(Host) "host_name",
|
||||||
%attribute string "service",
|
%attribute string "service",
|
||||||
|
|
||||||
%attribute dictionary "macros" {
|
%attribute dictionary "macros" {
|
||||||
@ -215,13 +164,10 @@ type User {
|
|||||||
%attribute number "notification_type_filter",
|
%attribute number "notification_type_filter",
|
||||||
%attribute number "notification_state_filter",
|
%attribute number "notification_state_filter",
|
||||||
%attribute name(TimePeriod) "notification_period"
|
%attribute name(TimePeriod) "notification_period"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserGroup {
|
type UserGroup {
|
||||||
%attribute string "display_name",
|
%attribute string "display_name"
|
||||||
%attribute string "action_url",
|
|
||||||
%attribute string "notes_url"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TimePeriod {
|
type TimePeriod {
|
||||||
|
@ -98,116 +98,72 @@ void Service::RemoveNotification(const Notification::Ptr& notification)
|
|||||||
|
|
||||||
void Service::UpdateSlaveNotifications(void)
|
void Service::UpdateSlaveNotifications(void)
|
||||||
{
|
{
|
||||||
ConfigItem::Ptr serviceItem, hostItem;
|
ConfigItem::Ptr item = ConfigItem::GetObject("Service", GetName());
|
||||||
|
|
||||||
serviceItem = ConfigItem::GetObject("Service", GetName());
|
|
||||||
|
|
||||||
/* Don't create slave notifications unless we own this object */
|
/* Don't create slave notifications unless we own this object */
|
||||||
if (!serviceItem)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Host::Ptr host = GetHost();
|
/* Service notification descs */
|
||||||
|
Dictionary::Ptr descs = GetNotificationDescriptions();
|
||||||
|
|
||||||
if (!host)
|
if (!descs)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hostItem = ConfigItem::GetObject("Host", host->GetName());
|
ObjectLock olock(descs);
|
||||||
|
|
||||||
/* Don't create slave notifications unless we own the host */
|
String nfcname;
|
||||||
if (!hostItem)
|
Value nfcdesc;
|
||||||
return;
|
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());
|
DebugInfo di;
|
||||||
descLists.push_back(host->GetNotificationDescriptions());
|
item->GetLinkedExpressionList()->FindDebugInfoPath(path, di);
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
if (di.Path.IsEmpty())
|
||||||
Dictionary::Ptr descs;
|
di = item->GetDebugInfo();
|
||||||
ConfigItem::Ptr item;
|
|
||||||
|
|
||||||
if (i == 0) {
|
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(di);
|
||||||
/* Host notification descs */
|
builder->SetType("Notification");
|
||||||
descs = host->GetNotificationDescriptions();
|
builder->SetName(name);
|
||||||
item = hostItem;
|
builder->AddExpression("host_name", OperatorSet, GetHost()->GetName());
|
||||||
} else {
|
builder->AddExpression("service", OperatorSet, GetShortName());
|
||||||
/* Service notification descs */
|
|
||||||
descs = GetNotificationDescriptions();
|
|
||||||
item = serviceItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!descs)
|
if (!nfcdesc.IsObjectType<Dictionary>())
|
||||||
continue;
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Notification description must be a dictionary."));
|
||||||
|
|
||||||
ObjectLock olock(descs);
|
Dictionary::Ptr notification = nfcdesc;
|
||||||
|
|
||||||
String nfcname;
|
Array::Ptr templates = notification->Get("templates");
|
||||||
Value nfcdesc;
|
|
||||||
BOOST_FOREACH(boost::tie(nfcname, nfcdesc), descs) {
|
|
||||||
std::ostringstream namebuf;
|
|
||||||
namebuf << GetName() << ":" << nfcname;
|
|
||||||
String name = namebuf.str();
|
|
||||||
|
|
||||||
std::vector<String> path;
|
if (templates) {
|
||||||
path.push_back("notifications");
|
ObjectLock tlock(templates);
|
||||||
path.push_back(nfcname);
|
|
||||||
|
|
||||||
DebugInfo di;
|
BOOST_FOREACH(const Value& tmpl, templates) {
|
||||||
item->GetLinkedExpressionList()->FindDebugInfoPath(path, di);
|
builder->AddParent(tmpl);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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();
|
DynamicObject::Start();
|
||||||
|
|
||||||
|
VERIFY(GetHost());
|
||||||
|
|
||||||
SetSchedulingOffset(rand());
|
SetSchedulingOffset(rand());
|
||||||
UpdateNextCheck();
|
UpdateNextCheck();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user