mirror of https://github.com/Icinga/icinga2.git
62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
#include "i2-cib.h"
|
|
|
|
using namespace icinga;
|
|
|
|
string Host::GetAlias(void) const
|
|
{
|
|
string value;
|
|
|
|
if (GetConfigObject()->GetProperty("alias", &value))
|
|
return value;
|
|
|
|
return GetName();
|
|
}
|
|
|
|
bool Host::Exists(const string& name)
|
|
{
|
|
return (ConfigObject::GetObject("host", name));
|
|
}
|
|
|
|
Host Host::GetByName(const string& name)
|
|
{
|
|
ConfigObject::Ptr configObject = ConfigObject::GetObject("host", name);
|
|
|
|
if (!configObject)
|
|
throw invalid_argument("Host '" + name + "' does not exist.");
|
|
|
|
return Host(configObject);
|
|
}
|
|
|
|
Dictionary::Ptr Host::GetGroups(void) const
|
|
{
|
|
Dictionary::Ptr value;
|
|
GetConfigObject()->GetProperty("hostgroups", &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;
|
|
}
|