2012-07-02 12:34:54 +02:00
|
|
|
#include "i2-cib.h"
|
2012-06-13 13:42:55 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-06-30 13:39:55 +02:00
|
|
|
string Host::GetAlias(void) const
|
2012-06-13 13:42:55 +02:00
|
|
|
{
|
|
|
|
string value;
|
|
|
|
|
2012-07-09 16:44:46 +02:00
|
|
|
if (GetProperty("alias", &value))
|
2012-06-13 13:42:55 +02:00
|
|
|
return value;
|
|
|
|
|
|
|
|
return GetName();
|
|
|
|
}
|
|
|
|
|
2012-06-30 13:39:55 +02:00
|
|
|
bool Host::Exists(const string& name)
|
|
|
|
{
|
|
|
|
return (ConfigObject::GetObject("host", name));
|
|
|
|
}
|
|
|
|
|
|
|
|
Host Host::GetByName(const string& name)
|
2012-06-13 13:42:55 +02:00
|
|
|
{
|
|
|
|
ConfigObject::Ptr configObject = ConfigObject::GetObject("host", name);
|
|
|
|
|
|
|
|
if (!configObject)
|
|
|
|
throw invalid_argument("Host '" + name + "' does not exist.");
|
|
|
|
|
|
|
|
return Host(configObject);
|
|
|
|
}
|
2012-06-30 13:39:55 +02:00
|
|
|
|
|
|
|
Dictionary::Ptr Host::GetGroups(void) const
|
|
|
|
{
|
|
|
|
Dictionary::Ptr value;
|
2012-07-09 16:44:46 +02:00
|
|
|
GetProperty("hostgroups", &value);
|
2012-06-30 13:39:55 +02:00
|
|
|
return value;
|
|
|
|
}
|
2012-07-09 10:09:53 +02:00
|
|
|
|
2012-07-09 12:44:31 +02:00
|
|
|
set<string> Host::GetParents(void) const
|
|
|
|
{
|
|
|
|
set<string> parents;
|
|
|
|
|
|
|
|
Dictionary::Ptr dependencies;
|
|
|
|
|
2012-07-09 16:44:46 +02:00
|
|
|
if (GetProperty("dependencies", &dependencies)) {
|
2012-07-09 12:44:31 +02:00
|
|
|
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;
|
|
|
|
}
|
2012-07-09 13:27:02 +02:00
|
|
|
|
|
|
|
bool Host::IsReachable(void) const
|
|
|
|
{
|
|
|
|
Dictionary::Ptr dependencies;
|
2012-07-09 16:44:46 +02:00
|
|
|
if (GetProperty("dependencies", &dependencies)) {
|
2012-07-09 13:27:02 +02:00
|
|
|
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;
|
2012-07-09 16:44:46 +02:00
|
|
|
if (GetProperty("hostchecks", &hostchecks)) {
|
2012-07-09 13:27:02 +02:00
|
|
|
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;
|
|
|
|
}
|