mirror of https://github.com/Icinga/icinga2.git
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;
|
||||
}
|
||||
|
||||
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;
|
||||
Dictionary::Ptr GetGroups(void) const;
|
||||
set<string> GetParents(void) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -140,6 +140,10 @@ bool Service::IsReachable(void) const
|
|||
if (service.GetName() == GetName())
|
||||
continue;
|
||||
|
||||
/* ignore pending services */
|
||||
if (!service.HasLastCheckResult())
|
||||
continue;
|
||||
|
||||
if (service.GetStateType() == StateTypeHard && service.GetState() != StateOK &&
|
||||
service.GetState() != StateWarning)
|
||||
return false;
|
||||
|
|
|
@ -116,12 +116,22 @@ void CompatComponent::DumpHostObject(ofstream& fp, Host host)
|
|||
{
|
||||
fp << "define host {" << "\n"
|
||||
<< "\t" << "host_name" << "\t" << host.GetName() << "\n"
|
||||
<< "\t" << "alias" << "\t" << host.GetAlias() << "\n"
|
||||
<< "\t" << "check_interval" << "\t" << 1 << "\n"
|
||||
<< "\t" << "retry_interval" << "\t" << 1 << "\n"
|
||||
<< "\t" << "max_check_attempts" << "\t" << 1 << "\n"
|
||||
<< "\t" << "active_checks_enabled" << "\t" << 1 << "\n"
|
||||
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n"
|
||||
<< "\t" << "}" << "\n"
|
||||
<< "\t" << "passive_checks_enabled" << "\t" << 1 << "\n";
|
||||
|
||||
set<string> parents = host.GetParents();
|
||||
|
||||
if (!parents.empty()) {
|
||||
fp << "\t" << "parents" << "\t";
|
||||
DumpStringList(fp, parents);
|
||||
fp << "\n";
|
||||
}
|
||||
|
||||
fp << "\t" << "}" << "\n"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
|
@ -201,20 +211,6 @@ void CompatComponent::DumpServiceObject(ofstream& fp, Service service)
|
|||
<< "\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.
|
||||
*/
|
||||
|
|
|
@ -39,7 +39,21 @@ private:
|
|||
void DumpHostStatus(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 DumpServiceObject(ofstream& fp, Service service);
|
||||
|
|
|
@ -80,6 +80,11 @@ void ConvenienceComponent::CopyServiceAttributes(const ConfigObject::Ptr& host,
|
|||
if (service->GetProperty("dependencies", &dependencies))
|
||||
builder->AddExpression("dependencies", OperatorPlus,
|
||||
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)
|
||||
|
|
|
@ -211,7 +211,7 @@ int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
|
|||
void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
|
||||
{
|
||||
stringstream message;
|
||||
message << *locp;
|
||||
message << *locp << ": " << err;
|
||||
throw runtime_error(message.str());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue