mirror of https://github.com/Icinga/icinga2.git
parent
a0e7f751cd
commit
b3e7dc32e9
|
@ -21,6 +21,9 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
map<String, vector<String> > Host::m_ServicesCache;
|
||||
bool Host::m_ServicesCacheValid = true;
|
||||
|
||||
static AttributeDescription hostAttributes[] = {
|
||||
{ "alias", Attribute_Config },
|
||||
{ "hostgroups", Attribute_Config }
|
||||
|
@ -286,3 +289,43 @@ void Host::OnAttributeChanged(const String& name, const Value& oldValue)
|
|||
HostGroup::InvalidateMembersCache();
|
||||
}
|
||||
|
||||
set<Service::Ptr> Host::GetServices(void) const
|
||||
{
|
||||
set<Service::Ptr> services;
|
||||
|
||||
ValidateServicesCache();
|
||||
|
||||
BOOST_FOREACH(const String& svc, m_ServicesCache[GetName()]) {
|
||||
if (!Service::Exists(svc))
|
||||
continue;
|
||||
|
||||
Service::Ptr service = Service::GetByName(svc);
|
||||
services.insert(service);
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
void Host::InvalidateServicesCache(void)
|
||||
{
|
||||
m_ServicesCacheValid = false;
|
||||
m_ServicesCache.clear();
|
||||
}
|
||||
|
||||
void Host::ValidateServicesCache(void)
|
||||
{
|
||||
if (m_ServicesCacheValid)
|
||||
return;
|
||||
|
||||
m_ServicesCache.clear();
|
||||
|
||||
DynamicObject::Ptr object;
|
||||
BOOST_FOREACH(tie(tuples::ignore, object), DynamicType::GetByName("Service")->GetObjects()) {
|
||||
const Service::Ptr& service = static_pointer_cast<Service>(object);
|
||||
|
||||
m_ServicesCache[service->GetHost()->GetName()].push_back(service->GetName());
|
||||
}
|
||||
|
||||
m_ServicesCacheValid = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
namespace icinga
|
||||
{
|
||||
|
||||
class Service;
|
||||
|
||||
/**
|
||||
* An Icinga host.
|
||||
*
|
||||
|
@ -48,14 +50,22 @@ public:
|
|||
bool IsReachable(void);
|
||||
bool IsUp(void);
|
||||
|
||||
set<shared_ptr<Service> > GetServices(void) const;
|
||||
static void InvalidateServicesCache(void);
|
||||
|
||||
protected:
|
||||
void OnAttributeChanged(const String& name, const Value& oldValue);
|
||||
|
||||
private:
|
||||
static bool m_InitializerDone;
|
||||
|
||||
static map<String, vector<String> > m_ServicesCache;
|
||||
static bool m_ServicesCacheValid;
|
||||
|
||||
static void ObjectCommittedHandler(const ConfigItem::Ptr& item);
|
||||
static void ObjectRemovedHandler(const ConfigItem::Ptr& item);
|
||||
|
||||
static void ValidateServicesCache(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -64,11 +64,13 @@ Service::Service(const Dictionary::Ptr& serializedObject)
|
|||
: DynamicObject(serializedObject)
|
||||
{
|
||||
ServiceGroup::InvalidateMembersCache();
|
||||
Host::InvalidateServicesCache();
|
||||
}
|
||||
|
||||
Service::~Service(void)
|
||||
{
|
||||
ServiceGroup::InvalidateMembersCache();
|
||||
Host::InvalidateServicesCache();
|
||||
}
|
||||
|
||||
String Service::GetAlias(void) const
|
||||
|
@ -592,6 +594,8 @@ void Service::OnAttributeChanged(const String& name, const Value& oldValue)
|
|||
OnNextCheckChanged(GetSelf(), oldValue);
|
||||
else if (name == "servicegroups")
|
||||
ServiceGroup::InvalidateMembersCache();
|
||||
else if (name == "host_name")
|
||||
Host::InvalidateServicesCache();
|
||||
}
|
||||
|
||||
void Service::BeginExecuteCheck(const function<void (void)>& callback)
|
||||
|
|
Loading…
Reference in New Issue