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;
|
||||
}
|
||||
|
||||
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;
|
||||
Dictionary::Ptr GetGroups(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;
|
||||
for (it = dependencies->Begin(); it != dependencies->End(); it++) {
|
||||
string name;
|
||||
|
||||
if (services && services->Contains(it->first))
|
||||
result->AddUnnamedProperty(host.GetName() + "-" + it->first);
|
||||
name = host.GetName() + "-" + it->first;
|
||||
else
|
||||
result->AddUnnamedProperty(it->first);
|
||||
name = it->first;
|
||||
|
||||
result->SetProperty(name, name);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -61,38 +61,13 @@ void CompatComponent::Stop(void)
|
|||
|
||||
void CompatComponent::DumpHostStatus(ofstream& fp, Host host)
|
||||
{
|
||||
int state = 0; /* up */
|
||||
|
||||
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 */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int state;
|
||||
if (!host.IsReachable())
|
||||
state = 2; /* unreachable */
|
||||
else if (!host.IsUp())
|
||||
state = 1; /* down */
|
||||
else
|
||||
state = 0; /* up */
|
||||
|
||||
fp << "hoststatus {" << "\n"
|
||||
<< "\t" << "host_name=" << host.GetName() << "\n"
|
||||
|
@ -108,6 +83,7 @@ void CompatComponent::DumpHostStatus(ofstream& fp, Host host)
|
|||
<< "\t" << "max_attempts=1" << "\n"
|
||||
<< "\t" << "active_checks_enabled=1" << "\n"
|
||||
<< "\t" << "passive_checks_enabled=1" << "\n"
|
||||
<< "\t" << "last_update=" << time(NULL) << "\n"
|
||||
<< "\t" << "}" << "\n"
|
||||
<< "\n";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue