mirror of https://github.com/Icinga/icinga2.git
Allocate ConfigItemBuilder objects on the stack
This commit is contained in:
parent
c2fedb3076
commit
a36e847c6c
|
@ -148,11 +148,11 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
|
||||||
Type::Ptr appType = Type::GetByName(ScriptGlobal::Get("ApplicationType", &Empty));
|
Type::Ptr appType = Type::GetByName(ScriptGlobal::Get("ApplicationType", &Empty));
|
||||||
|
|
||||||
if (ConfigItem::GetItems(appType).empty()) {
|
if (ConfigItem::GetItems(appType).empty()) {
|
||||||
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder();
|
ConfigItemBuilder builder;
|
||||||
builder->SetType(appType);
|
builder.SetType(appType);
|
||||||
builder->SetName("app");
|
builder.SetName("app");
|
||||||
builder->AddExpression(new ImportDefaultTemplatesExpression());
|
builder.AddExpression(new ImportDefaultTemplatesExpression());
|
||||||
ConfigItem::Ptr item = builder->Compile();
|
ConfigItem::Ptr item = builder.Compile();
|
||||||
item->Register();
|
item->Register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace icinga
|
||||||
*
|
*
|
||||||
* @ingroup config
|
* @ingroup config
|
||||||
*/
|
*/
|
||||||
class ConfigItemBuilder final : public Object
|
class ConfigItemBuilder final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(ConfigItemBuilder);
|
DECLARE_PTR_TYPEDEFS(ConfigItemBuilder);
|
||||||
|
|
|
@ -146,7 +146,7 @@ public:
|
||||||
static inline Value NewObject(ScriptFrame& frame, bool abstract, const Type::Ptr& type, const String& name, const std::shared_ptr<Expression>& filter,
|
static inline Value NewObject(ScriptFrame& frame, bool abstract, const Type::Ptr& type, const String& name, const std::shared_ptr<Expression>& filter,
|
||||||
const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, const std::map<String, std::unique_ptr<Expression> >& closedVars, const std::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
const String& zone, const String& package, bool defaultTmpl, bool ignoreOnError, const std::map<String, std::unique_ptr<Expression> >& closedVars, const std::shared_ptr<Expression>& expression, const DebugInfo& debugInfo = DebugInfo())
|
||||||
{
|
{
|
||||||
ConfigItemBuilder::Ptr item = new ConfigItemBuilder(debugInfo);
|
ConfigItemBuilder item{debugInfo};
|
||||||
|
|
||||||
String checkName = name;
|
String checkName = name;
|
||||||
|
|
||||||
|
@ -173,21 +173,21 @@ public:
|
||||||
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debugInfo));
|
BOOST_THROW_EXCEPTION(ScriptError(msgbuf.str(), debugInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
item->SetType(type);
|
item.SetType(type);
|
||||||
item->SetName(name);
|
item.SetName(name);
|
||||||
|
|
||||||
if (!abstract)
|
if (!abstract)
|
||||||
item->AddExpression(new ImportDefaultTemplatesExpression());
|
item.AddExpression(new ImportDefaultTemplatesExpression());
|
||||||
|
|
||||||
item->AddExpression(new OwnedExpression(expression));
|
item.AddExpression(new OwnedExpression(expression));
|
||||||
item->SetAbstract(abstract);
|
item.SetAbstract(abstract);
|
||||||
item->SetScope(EvaluateClosedVars(frame, closedVars));
|
item.SetScope(EvaluateClosedVars(frame, closedVars));
|
||||||
item->SetZone(zone);
|
item.SetZone(zone);
|
||||||
item->SetPackage(package);
|
item.SetPackage(package);
|
||||||
item->SetFilter(filter);
|
item.SetFilter(filter);
|
||||||
item->SetDefaultTemplate(defaultTmpl);
|
item.SetDefaultTemplate(defaultTmpl);
|
||||||
item->SetIgnoreOnError(ignoreOnError);
|
item.SetIgnoreOnError(ignoreOnError);
|
||||||
item->Compile()->Register();
|
item.Compile()->Register();
|
||||||
|
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,34 +46,34 @@ bool Dependency::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, cons
|
||||||
<< "Applying dependency '" << name << "' to object '" << checkable->GetName() << "' for rule " << di;
|
<< "Applying dependency '" << name << "' to object '" << checkable->GetName() << "' for rule " << di;
|
||||||
#endif /* _DEBUG */
|
#endif /* _DEBUG */
|
||||||
|
|
||||||
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
|
ConfigItemBuilder builder{di};
|
||||||
builder->SetType(Dependency::TypeInstance);
|
builder.SetType(Dependency::TypeInstance);
|
||||||
builder->SetName(name);
|
builder.SetName(name);
|
||||||
builder->SetScope(frame.Locals->ShallowClone());
|
builder.SetScope(frame.Locals->ShallowClone());
|
||||||
builder->SetIgnoreOnError(rule.GetIgnoreOnError());
|
builder.SetIgnoreOnError(rule.GetIgnoreOnError());
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "parent_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "parent_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "child_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "child_host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "child_service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "child_service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
||||||
|
|
||||||
String zone = checkable->GetZoneName();
|
String zone = checkable->GetZoneName();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new ImportDefaultTemplatesExpression());
|
builder.AddExpression(new ImportDefaultTemplatesExpression());
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder.AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
ConfigItem::Ptr dependencyItem = builder->Compile();
|
ConfigItem::Ptr dependencyItem = builder.Compile();
|
||||||
dependencyItem->Register();
|
dependencyItem->Register();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -46,33 +46,33 @@ bool Notification::EvaluateApplyRuleInstance(const Checkable::Ptr& checkable, co
|
||||||
<< "Applying notification '" << name << "' to object '" << checkable->GetName() << "' for rule " << di;
|
<< "Applying notification '" << name << "' to object '" << checkable->GetName() << "' for rule " << di;
|
||||||
#endif /* _DEBUG */
|
#endif /* _DEBUG */
|
||||||
|
|
||||||
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
|
ConfigItemBuilder builder{di};
|
||||||
builder->SetType(Notification::TypeInstance);
|
builder.SetType(Notification::TypeInstance);
|
||||||
builder->SetName(name);
|
builder.SetName(name);
|
||||||
builder->SetScope(frame.Locals->ShallowClone());
|
builder.SetScope(frame.Locals->ShallowClone());
|
||||||
builder->SetIgnoreOnError(rule.GetIgnoreOnError());
|
builder.SetIgnoreOnError(rule.GetIgnoreOnError());
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
||||||
|
|
||||||
String zone = checkable->GetZoneName();
|
String zone = checkable->GetZoneName();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder.AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
builder->AddExpression(new ImportDefaultTemplatesExpression());
|
builder.AddExpression(new ImportDefaultTemplatesExpression());
|
||||||
|
|
||||||
ConfigItem::Ptr notificationItem = builder->Compile();
|
ConfigItem::Ptr notificationItem = builder.Compile();
|
||||||
notificationItem->Register();
|
notificationItem->Register();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -45,33 +45,33 @@ bool ScheduledDowntime::EvaluateApplyRuleInstance(const Checkable::Ptr& checkabl
|
||||||
<< "Applying scheduled downtime '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
<< "Applying scheduled downtime '" << rule.GetName() << "' to object '" << checkable->GetName() << "' for rule " << di;
|
||||||
#endif /* _DEBUG */
|
#endif /* _DEBUG */
|
||||||
|
|
||||||
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
|
ConfigItemBuilder builder{di};
|
||||||
builder->SetType(ScheduledDowntime::TypeInstance);
|
builder.SetType(ScheduledDowntime::TypeInstance);
|
||||||
builder->SetName(name);
|
builder.SetName(name);
|
||||||
builder->SetScope(frame.Locals->ShallowClone());
|
builder.SetScope(frame.Locals->ShallowClone());
|
||||||
builder->SetIgnoreOnError(rule.GetIgnoreOnError());
|
builder.SetIgnoreOnError(rule.GetIgnoreOnError());
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
if (service)
|
if (service)
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "service_name"), OpSetLiteral, MakeLiteral(service->GetShortName()), di));
|
||||||
|
|
||||||
String zone = checkable->GetZoneName();
|
String zone = checkable->GetZoneName();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder.AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
builder->AddExpression(new ImportDefaultTemplatesExpression());
|
builder.AddExpression(new ImportDefaultTemplatesExpression());
|
||||||
|
|
||||||
ConfigItem::Ptr downtimeItem = builder->Compile();
|
ConfigItem::Ptr downtimeItem = builder.Compile();
|
||||||
downtimeItem->Register();
|
downtimeItem->Register();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -45,28 +45,28 @@ bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& nam
|
||||||
<< "Applying service '" << name << "' to host '" << host->GetName() << "' for rule " << di;
|
<< "Applying service '" << name << "' to host '" << host->GetName() << "' for rule " << di;
|
||||||
#endif /* _DEBUG */
|
#endif /* _DEBUG */
|
||||||
|
|
||||||
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
|
ConfigItemBuilder builder{di};
|
||||||
builder->SetType(Service::TypeInstance);
|
builder.SetType(Service::TypeInstance);
|
||||||
builder->SetName(name);
|
builder.SetName(name);
|
||||||
builder->SetScope(frame.Locals->ShallowClone());
|
builder.SetScope(frame.Locals->ShallowClone());
|
||||||
builder->SetIgnoreOnError(rule.GetIgnoreOnError());
|
builder.SetIgnoreOnError(rule.GetIgnoreOnError());
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "name"), OpSetLiteral, MakeLiteral(name), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "name"), OpSetLiteral, MakeLiteral(name), di));
|
||||||
|
|
||||||
String zone = host->GetZoneName();
|
String zone = host->GetZoneName();
|
||||||
|
|
||||||
if (!zone.IsEmpty())
|
if (!zone.IsEmpty())
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
|
||||||
|
|
||||||
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
builder.AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
|
||||||
|
|
||||||
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
|
builder.AddExpression(new OwnedExpression(rule.GetExpression()));
|
||||||
|
|
||||||
builder->AddExpression(new ImportDefaultTemplatesExpression());
|
builder.AddExpression(new ImportDefaultTemplatesExpression());
|
||||||
|
|
||||||
ConfigItem::Ptr serviceItem = builder->Compile();
|
ConfigItem::Ptr serviceItem = builder.Compile();
|
||||||
serviceItem->Register();
|
serviceItem->Register();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue