mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 06:05:01 +02:00
parent
a0e7f751cd
commit
b3e7dc32e9
@ -21,6 +21,9 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
map<String, vector<String> > Host::m_ServicesCache;
|
||||||
|
bool Host::m_ServicesCacheValid = true;
|
||||||
|
|
||||||
static AttributeDescription hostAttributes[] = {
|
static AttributeDescription hostAttributes[] = {
|
||||||
{ "alias", Attribute_Config },
|
{ "alias", Attribute_Config },
|
||||||
{ "hostgroups", Attribute_Config }
|
{ "hostgroups", Attribute_Config }
|
||||||
@ -286,3 +289,43 @@ void Host::OnAttributeChanged(const String& name, const Value& oldValue)
|
|||||||
HostGroup::InvalidateMembersCache();
|
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
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Icinga host.
|
* An Icinga host.
|
||||||
*
|
*
|
||||||
@ -48,14 +50,22 @@ public:
|
|||||||
bool IsReachable(void);
|
bool IsReachable(void);
|
||||||
bool IsUp(void);
|
bool IsUp(void);
|
||||||
|
|
||||||
|
set<shared_ptr<Service> > GetServices(void) const;
|
||||||
|
static void InvalidateServicesCache(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnAttributeChanged(const String& name, const Value& oldValue);
|
void OnAttributeChanged(const String& name, const Value& oldValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool m_InitializerDone;
|
static bool m_InitializerDone;
|
||||||
|
|
||||||
|
static map<String, vector<String> > m_ServicesCache;
|
||||||
|
static bool m_ServicesCacheValid;
|
||||||
|
|
||||||
static void ObjectCommittedHandler(const ConfigItem::Ptr& item);
|
static void ObjectCommittedHandler(const ConfigItem::Ptr& item);
|
||||||
static void ObjectRemovedHandler(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)
|
: DynamicObject(serializedObject)
|
||||||
{
|
{
|
||||||
ServiceGroup::InvalidateMembersCache();
|
ServiceGroup::InvalidateMembersCache();
|
||||||
|
Host::InvalidateServicesCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
Service::~Service(void)
|
Service::~Service(void)
|
||||||
{
|
{
|
||||||
ServiceGroup::InvalidateMembersCache();
|
ServiceGroup::InvalidateMembersCache();
|
||||||
|
Host::InvalidateServicesCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
String Service::GetAlias(void) const
|
String Service::GetAlias(void) const
|
||||||
@ -592,6 +594,8 @@ void Service::OnAttributeChanged(const String& name, const Value& oldValue)
|
|||||||
OnNextCheckChanged(GetSelf(), oldValue);
|
OnNextCheckChanged(GetSelf(), oldValue);
|
||||||
else if (name == "servicegroups")
|
else if (name == "servicegroups")
|
||||||
ServiceGroup::InvalidateMembersCache();
|
ServiceGroup::InvalidateMembersCache();
|
||||||
|
else if (name == "host_name")
|
||||||
|
Host::InvalidateServicesCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::BeginExecuteCheck(const function<void (void)>& callback)
|
void Service::BeginExecuteCheck(const function<void (void)>& callback)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user