mirror of https://github.com/Icinga/icinga2.git
Moved host reachability/state code into the cib library.
This commit is contained in:
parent
c8261fa8f2
commit
8d27f66b83
38
cib/host.cpp
38
cib/host.cpp
|
@ -59,3 +59,41 @@ set<string> Host::GetParents(void) const
|
||||||
|
|
||||||
return parents;
|
return parents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Host::IsReachable(void) const
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (!service.IsReachable() ||
|
||||||
|
(service.GetState() != StateOK && service.GetState() != StateWarning)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Host::IsUp(void) const
|
||||||
|
{
|
||||||
|
Dictionary::Ptr hostchecks;
|
||||||
|
if (GetConfigObject()->GetProperty("hostchecks", &hostchecks)) {
|
||||||
|
hostchecks = Service::ResolveDependencies(*this, hostchecks);
|
||||||
|
|
||||||
|
Dictionary::Iterator it;
|
||||||
|
for (it = hostchecks->Begin(); it != hostchecks->End(); it++) {
|
||||||
|
Service service = Service::GetByName(it->second);
|
||||||
|
if (service.GetState() != StateOK && service.GetState() != StateWarning) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ public:
|
||||||
string GetAlias(void) const;
|
string GetAlias(void) const;
|
||||||
Dictionary::Ptr GetGroups(void) const;
|
Dictionary::Ptr GetGroups(void) const;
|
||||||
set<string> GetParents(void) const;
|
set<string> GetParents(void) const;
|
||||||
|
|
||||||
|
bool IsReachable(void) const;
|
||||||
|
bool IsUp(void) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,10 +376,14 @@ Dictionary::Ptr Service::ResolveDependencies(Host host, const Dictionary::Ptr& d
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
Dictionary::Iterator it;
|
||||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
||||||
|
string name;
|
||||||
|
|
||||||
if (services && services->Contains(it->first))
|
if (services && services->Contains(it->first))
|
||||||
result->AddUnnamedProperty(host.GetName() + "-" + it->first);
|
name = host.GetName() + "-" + it->first;
|
||||||
else
|
else
|
||||||
result->AddUnnamedProperty(it->first);
|
name = it->first;
|
||||||
|
|
||||||
|
result->SetProperty(name, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -61,38 +61,13 @@ void CompatComponent::Stop(void)
|
||||||
|
|
||||||
void CompatComponent::DumpHostStatus(ofstream& fp, Host host)
|
void CompatComponent::DumpHostStatus(ofstream& fp, Host host)
|
||||||
{
|
{
|
||||||
int state = 0; /* up */
|
int state;
|
||||||
|
if (!host.IsReachable())
|
||||||
Dictionary::Ptr dependencies;
|
|
||||||
if (host.GetConfigObject()->GetProperty("dependencies", &dependencies)) {
|
|
||||||
dependencies = Service::ResolveDependencies(host, dependencies);
|
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
|
||||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
|
||||||
Service service = Service::GetByName(it->second);
|
|
||||||
|
|
||||||
if (!service.IsReachable() ||
|
|
||||||
(service.GetState() != StateOK && service.GetState() != StateWarning)) {
|
|
||||||
std::cerr << service.GetName() << " is unreachable." << std::endl;
|
|
||||||
state = 2; /* unreachable */
|
state = 2; /* unreachable */
|
||||||
break;
|
else if (!host.IsUp())
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary::Ptr hostchecks;
|
|
||||||
if (state == 0 && host.GetConfigObject()->GetProperty("hostchecks", &hostchecks)) {
|
|
||||||
hostchecks = Service::ResolveDependencies(host, hostchecks);
|
|
||||||
|
|
||||||
Dictionary::Iterator it;
|
|
||||||
for (it = hostchecks->Begin(); it != hostchecks->End(); it++) {
|
|
||||||
Service service = Service::GetByName(it->second);
|
|
||||||
if (service.GetState() != StateOK && service.GetState() != StateWarning) {
|
|
||||||
state = 1; /* down */
|
state = 1; /* down */
|
||||||
break;
|
else
|
||||||
}
|
state = 0; /* up */
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fp << "hoststatus {" << "\n"
|
fp << "hoststatus {" << "\n"
|
||||||
<< "\t" << "host_name=" << host.GetName() << "\n"
|
<< "\t" << "host_name=" << host.GetName() << "\n"
|
||||||
|
@ -108,6 +83,7 @@ void CompatComponent::DumpHostStatus(ofstream& fp, Host host)
|
||||||
<< "\t" << "max_attempts=1" << "\n"
|
<< "\t" << "max_attempts=1" << "\n"
|
||||||
<< "\t" << "active_checks_enabled=1" << "\n"
|
<< "\t" << "active_checks_enabled=1" << "\n"
|
||||||
<< "\t" << "passive_checks_enabled=1" << "\n"
|
<< "\t" << "passive_checks_enabled=1" << "\n"
|
||||||
|
<< "\t" << "last_update=" << time(NULL) << "\n"
|
||||||
<< "\t" << "}" << "\n"
|
<< "\t" << "}" << "\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue