mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-28 16:14:09 +02:00
Implemented extended service template format.
This commit is contained in:
parent
0a6cf57f57
commit
4ad1789e33
@ -54,6 +54,29 @@ void ConvenienceComponent::HostAddedHandler(const ConfigItem::Ptr& item)
|
|||||||
HostCommittedHandler(item);
|
HostCommittedHandler(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConvenienceComponent::CopyServiceAttributes(const Dictionary::Ptr& service, const ConfigItemBuilder::Ptr& builder)
|
||||||
|
{
|
||||||
|
Dictionary::Ptr macros;
|
||||||
|
if (service->GetProperty("macros", ¯os))
|
||||||
|
builder->AddExpression("macros", OperatorPlus, macros);
|
||||||
|
|
||||||
|
long checkInterval;
|
||||||
|
if (service->GetProperty("check_interval", &checkInterval))
|
||||||
|
builder->AddExpression("check_interval", OperatorSet, checkInterval);
|
||||||
|
|
||||||
|
long retryInterval;
|
||||||
|
if (service->GetProperty("retry_interval", &retryInterval))
|
||||||
|
builder->AddExpression("retry_interval", OperatorSet, retryInterval);
|
||||||
|
|
||||||
|
Dictionary::Ptr sgroups;
|
||||||
|
if (service->GetProperty("servicegroups", &sgroups))
|
||||||
|
builder->AddExpression("servicegroups", OperatorPlus, sgroups);
|
||||||
|
|
||||||
|
Dictionary::Ptr checkers;
|
||||||
|
if (service->GetProperty("checkers", &checkers))
|
||||||
|
builder->AddExpression("checkers", OperatorSet, checkers);
|
||||||
|
}
|
||||||
|
|
||||||
void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
{
|
{
|
||||||
if (item->GetType() != "host")
|
if (item->GetType() != "host")
|
||||||
@ -77,51 +100,44 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
|||||||
if (serviceDescs) {
|
if (serviceDescs) {
|
||||||
Dictionary::Iterator it;
|
Dictionary::Iterator it;
|
||||||
for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) {
|
for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) {
|
||||||
Variant desc = it->second;
|
string svcname = it->first;
|
||||||
|
Variant svcdesc = it->second;
|
||||||
|
|
||||||
|
stringstream namebuf;
|
||||||
|
namebuf << item->GetName() << "-" << svcname;
|
||||||
|
string name = namebuf.str();
|
||||||
|
|
||||||
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(item->GetDebugInfo());
|
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(item->GetDebugInfo());
|
||||||
|
builder->SetType("service");
|
||||||
|
builder->SetName(name);
|
||||||
|
builder->AddExpression("host_name", OperatorSet, item->GetName());
|
||||||
|
builder->AddExpression("alias", OperatorSet, svcname);
|
||||||
|
|
||||||
string name;
|
CopyServiceAttributes(host->GetProperties(), builder);
|
||||||
|
|
||||||
if (desc.GetType() == VariantString) {
|
if (svcdesc.GetType() == VariantString) {
|
||||||
stringstream namebuf;
|
builder->AddParent(svcdesc);
|
||||||
namebuf << item->GetName() << "-" << string(desc);
|
} else if (svcdesc.GetType() == VariantObject) {
|
||||||
name = namebuf.str();
|
Dictionary::Ptr service = dynamic_pointer_cast<Dictionary>(svcdesc.GetObject());
|
||||||
|
|
||||||
builder->SetType("service");
|
if (!service)
|
||||||
builder->SetName(name);
|
throw invalid_argument("Service description invalid.");
|
||||||
|
|
||||||
builder->AddParent(desc);
|
string parent;
|
||||||
builder->AddExpression("host_name", OperatorSet, item->GetName());
|
if (!service->GetProperty("service", &parent))
|
||||||
builder->AddExpression("alias", OperatorSet, string(desc));
|
parent = string(svcdesc);
|
||||||
|
|
||||||
Dictionary::Ptr macros;
|
builder->AddParent(parent);
|
||||||
if (host->GetProperty("macros", ¯os))
|
|
||||||
builder->AddExpression("macros", OperatorPlus, macros);
|
|
||||||
|
|
||||||
long checkInterval;
|
CopyServiceAttributes(service, builder);
|
||||||
if (host->GetProperty("check_interval", &checkInterval))
|
|
||||||
builder->AddExpression("check_interval", OperatorSet, checkInterval);
|
|
||||||
|
|
||||||
long retryInterval;
|
|
||||||
if (host->GetProperty("retry_interval", &retryInterval))
|
|
||||||
builder->AddExpression("retry_interval", OperatorSet, retryInterval);
|
|
||||||
|
|
||||||
Dictionary::Ptr sgroups;
|
|
||||||
if (host->GetProperty("servicegroups", &sgroups))
|
|
||||||
builder->AddExpression("servicegroups", OperatorPlus, sgroups);
|
|
||||||
|
|
||||||
Dictionary::Ptr checkers;
|
|
||||||
if (host->GetProperty("checkers", &checkers))
|
|
||||||
builder->AddExpression("checkers", OperatorSet, checkers);
|
|
||||||
|
|
||||||
ConfigItem::Ptr serviceItem = builder->Compile();
|
|
||||||
ConfigObject::Ptr service = serviceItem->Commit();
|
|
||||||
|
|
||||||
newServices->SetProperty(name, serviceItem);
|
|
||||||
} else {
|
} else {
|
||||||
throw runtime_error("Not supported.");
|
throw invalid_argument("Service description must be either a string or a dictionary.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigItem::Ptr serviceItem = builder->Compile();
|
||||||
|
serviceItem->Commit();
|
||||||
|
|
||||||
|
newServices->SetProperty(name, serviceItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void CopyServiceAttributes(const Dictionary::Ptr& service, const ConfigItemBuilder::Ptr& builder);
|
||||||
void HostAddedHandler(const ConfigItem::Ptr& item);
|
void HostAddedHandler(const ConfigItem::Ptr& item);
|
||||||
void HostCommittedHandler(const ConfigItem::Ptr& item);
|
void HostCommittedHandler(const ConfigItem::Ptr& item);
|
||||||
void HostRemovedHandler(const ConfigItem::Ptr& item);
|
void HostRemovedHandler(const ConfigItem::Ptr& item);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user