mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
Auto-detect host parents.
This commit is contained in:
parent
9f56ce6c46
commit
c8261fa8f2
25
cib/host.cpp
25
cib/host.cpp
@ -34,3 +34,28 @@ Dictionary::Ptr Host::GetGroups(void) const
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set<string> Host::GetParents(void) const
|
||||||
|
{
|
||||||
|
set<string> parents;
|
||||||
|
|
||||||
|
Dictionary::Ptr dependencies;
|
||||||
|
|
||||||
|
if (GetConfigObject()->GetProperty("dependencies", &dependencies)) {
|
||||||
|
dependencies = Service::ResolveDependencies(*this, dependencies);
|
||||||
|
|
||||||
|
Dictionary::Iterator it;
|
||||||
|
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
||||||
|
Service service = Service::GetByName(it->second);
|
||||||
|
|
||||||
|
string parent = service.GetHost().GetName();
|
||||||
|
|
||||||
|
/* ignore ourselves */
|
||||||
|
if (parent == GetName())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
parents.insert(parent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parents;
|
||||||
|
}
|
||||||
|
@ -16,6 +16,7 @@ public:
|
|||||||
|
|
||||||
string GetAlias(void) const;
|
string GetAlias(void) const;
|
||||||
Dictionary::Ptr GetGroups(void) const;
|
Dictionary::Ptr GetGroups(void) const;
|
||||||
|
set<string> GetParents(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,10 @@ bool Service::IsReachable(void) const
|
|||||||
if (service.GetName() == GetName())
|
if (service.GetName() == GetName())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* ignore pending services */
|
||||||
|
if (!service.HasLastCheckResult())
|
||||||
|
continue;
|
||||||
|
|
||||||
if (service.GetStateType() == StateTypeHard && service.GetState() != StateOK &&
|
if (service.GetStateType() == StateTypeHard && service.GetState() != StateOK &&
|
||||||
service.GetState() != StateWarning)
|
service.GetState() != StateWarning)
|
||||||
return false;
|
return false;
|
||||||
|
@ -116,12 +116,22 @@ void CompatComponent::DumpHostObject(ofstream& fp, Host host)
|
|||||||
{
|
{
|
||||||
fp << "define host {" << "\n"
|
fp << "define host {" << "\n"
|
||||||
<< "\t" << "host_name" << "\t" << host.GetName() << "\n"
|
<< "\t" << "host_name" << "\t" << host.GetName() << "\n"
|
||||||
|
<< "\t" << "alias" << "\t" << host.GetAlias() << "\n"
|
||||||
<< "\t" << "check_interval" << "\t" << 1 << "\n"
|
<< "\t" << "check_interval" << "\t" << 1 << "\n"
|
||||||
<< "\t" << "retry_interval" << "\t" << 1 << "\n"
|
<< "\t" << "retry_interval" << "\t" << 1 << "\n"
|
||||||
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
||||||
<< "\t" << "active_checks_enabled" << "\t" << 1 << "\n"
|
<< "\t" << "active_checks_enabled" << "\t" << 1 << "\n"
|
||||||
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n"
|
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n";
|
||||||
<< "\t" << "}" << "\n"
|
|
||||||
|
set<string> parents = host.GetParents();
|
||||||
|
|
||||||
|
if (!parents.empty()) {
|
||||||
|
fp << "\t" << "parents" << "\t";
|
||||||
|
DumpStringList(fp, parents);
|
||||||
|
fp << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
fp << "\t" << "}" << "\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,20 +211,6 @@ void CompatComponent::DumpServiceObject(ofstream& fp, Service service)
|
|||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompatComponent::DumpStringList(ofstream& fp, const vector<string>& list)
|
|
||||||
{
|
|
||||||
vector<string>::const_iterator it;
|
|
||||||
bool first = true;
|
|
||||||
for (it = list.begin(); it != list.end(); it++) {
|
|
||||||
if (!first)
|
|
||||||
fp << ",";
|
|
||||||
else
|
|
||||||
first = false;
|
|
||||||
|
|
||||||
fp << *it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Periodically writes the status.dat and objects.cache files.
|
* Periodically writes the status.dat and objects.cache files.
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +39,21 @@ private:
|
|||||||
void DumpHostStatus(ofstream& fp, Host host);
|
void DumpHostStatus(ofstream& fp, Host host);
|
||||||
void DumpHostObject(ofstream& fp, Host host);
|
void DumpHostObject(ofstream& fp, Host host);
|
||||||
|
|
||||||
void DumpStringList(ofstream& fp, const vector<string>& list);
|
template<typename T>
|
||||||
|
void DumpStringList(ofstream& fp, const T& list)
|
||||||
|
{
|
||||||
|
typename T::const_iterator it;
|
||||||
|
bool first = true;
|
||||||
|
for (it = list.begin(); it != list.end(); it++) {
|
||||||
|
if (!first)
|
||||||
|
fp << ",";
|
||||||
|
else
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
fp << *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DumpServiceStatus(ofstream& fp, Service service);
|
void DumpServiceStatus(ofstream& fp, Service service);
|
||||||
void DumpServiceObject(ofstream& fp, Service service);
|
void DumpServiceObject(ofstream& fp, Service service);
|
||||||
|
@ -80,6 +80,11 @@ void ConvenienceComponent::CopyServiceAttributes(const ConfigObject::Ptr& host,
|
|||||||
if (service->GetProperty("dependencies", &dependencies))
|
if (service->GetProperty("dependencies", &dependencies))
|
||||||
builder->AddExpression("dependencies", OperatorPlus,
|
builder->AddExpression("dependencies", OperatorPlus,
|
||||||
Service::ResolveDependencies(host, dependencies));
|
Service::ResolveDependencies(host, dependencies));
|
||||||
|
|
||||||
|
Dictionary::Ptr hostchecks;
|
||||||
|
if (service->GetProperty("hostchecks", &hostchecks))
|
||||||
|
builder->AddExpression("dependencies", OperatorPlus,
|
||||||
|
Service::ResolveDependencies(host, hostchecks));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
|
@ -211,7 +211,7 @@ int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
|
|||||||
void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
|
void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
|
||||||
{
|
{
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << *locp;
|
message << *locp << ": " << err;
|
||||||
throw runtime_error(message.str());
|
throw runtime_error(message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user