mirror of https://github.com/Icinga/icinga2.git
commit
2ad2e7f6db
|
@ -108,6 +108,20 @@ size_t Array::GetLength(void) const
|
|||
return m_Data.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the array contains the specified value.
|
||||
*
|
||||
* @param value The value.
|
||||
* @returns true if the array contains the value, false otherwise.
|
||||
*/
|
||||
bool Array::Contains(const String& value) const
|
||||
{
|
||||
ASSERT(!OwnsLock());
|
||||
ObjectLock olock(this);
|
||||
|
||||
return (std::find(m_Data.begin(), m_Data.end(), value) != m_Data.end());
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the given value at the specified index
|
||||
*
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
Iterator End(void);
|
||||
|
||||
size_t GetLength(void) const;
|
||||
bool Contains(const String& value) const;
|
||||
|
||||
void Insert(unsigned int index, const Value& value);
|
||||
void Remove(unsigned int index);
|
||||
|
|
|
@ -75,7 +75,7 @@ bool ApplyRule::EvaluateFilter(const Dictionary::Ptr& scope) const
|
|||
return result;
|
||||
}
|
||||
|
||||
void ApplyRule::EvaluateRules(void)
|
||||
void ApplyRule::EvaluateRules(bool clear)
|
||||
{
|
||||
std::set<String> completedTypes;
|
||||
|
||||
|
@ -113,7 +113,8 @@ void ApplyRule::EvaluateRules(void)
|
|||
}
|
||||
}
|
||||
|
||||
m_Rules.clear();
|
||||
if (clear)
|
||||
m_Rules.clear();
|
||||
}
|
||||
|
||||
void ApplyRule::RegisterType(const String& sourceType, const std::vector<String>& targetTypes, const ApplyRule::Callback& callback)
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
|
||||
static void AddRule(const String& sourceType, const String& targetType, const String& name, const AExpression::Ptr& expression,
|
||||
const AExpression::Ptr& filter, const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||
static void EvaluateRules(void);
|
||||
static void EvaluateRules(bool clear);
|
||||
|
||||
static void RegisterType(const String& sourceType, const std::vector<String>& targetTypes, const ApplyRule::Callback& callback);
|
||||
static bool IsValidSourceType(const String& sourceType);
|
||||
|
|
|
@ -316,11 +316,14 @@ bool ConfigItem::ValidateItems(void)
|
|||
|
||||
upq.Join();
|
||||
|
||||
Log(LogInformation, "config", "Evaluating 'apply' rules...");
|
||||
ApplyRule::EvaluateRules();
|
||||
Log(LogInformation, "config", "Evaluating 'object' rules (step 1)...");
|
||||
ObjectRule::EvaluateRules(false);
|
||||
|
||||
Log(LogInformation, "config", "Evaluating 'object' rules...");
|
||||
ObjectRule::EvaluateRules();
|
||||
Log(LogInformation, "config", "Evaluating 'apply' rules...");
|
||||
ApplyRule::EvaluateRules(true);
|
||||
|
||||
Log(LogInformation, "config", "Evaluating 'object' rules (step 2)...");
|
||||
ObjectRule::EvaluateRules(true);
|
||||
|
||||
Log(LogInformation, "config", "Validating config items (step 2)...");
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ bool ObjectRule::EvaluateFilter(const Dictionary::Ptr& scope) const
|
|||
return result;
|
||||
}
|
||||
|
||||
void ObjectRule::EvaluateRules(void)
|
||||
void ObjectRule::EvaluateRules(bool clear)
|
||||
{
|
||||
std::pair<String, Callback> kv;
|
||||
BOOST_FOREACH(kv, m_Callbacks) {
|
||||
|
@ -84,7 +84,8 @@ void ObjectRule::EvaluateRules(void)
|
|||
callback(it->second);
|
||||
}
|
||||
|
||||
m_Rules.clear();
|
||||
if (clear)
|
||||
m_Rules.clear();
|
||||
}
|
||||
|
||||
void ObjectRule::RegisterType(const String& sourceType, const ObjectRule::Callback& callback)
|
||||
|
|
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
static void AddRule(const String& sourceType, const String& name, const AExpression::Ptr& expression,
|
||||
const AExpression::Ptr& filter, const DebugInfo& di, const Dictionary::Ptr& scope);
|
||||
static void EvaluateRules(void);
|
||||
static void EvaluateRules(bool clear);
|
||||
|
||||
static void RegisterType(const String& sourceType, const ObjectRule::Callback& callback);
|
||||
static bool IsValidSourceType(const String& sourceType);
|
||||
|
|
|
@ -88,6 +88,21 @@ void Checkable::OnStateLoaded(void)
|
|||
}
|
||||
}
|
||||
|
||||
void Checkable::AddGroup(const String& name)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_CheckableMutex);
|
||||
|
||||
Array::Ptr groups = GetGroups();
|
||||
|
||||
if (groups && groups->Contains(name))
|
||||
return;
|
||||
|
||||
if (!groups)
|
||||
groups = make_shared<Array>();
|
||||
|
||||
groups->Add(name);
|
||||
}
|
||||
|
||||
AcknowledgementType Checkable::GetAcknowledgement(void)
|
||||
{
|
||||
ASSERT(OwnsLock());
|
||||
|
|
|
@ -89,6 +89,8 @@ public:
|
|||
std::set<Checkable::Ptr> GetParents(void) const;
|
||||
std::set<Checkable::Ptr> GetChildren(void) const;
|
||||
|
||||
void AddGroup(const String& name);
|
||||
|
||||
//bool IsHostCheck(void) const;
|
||||
|
||||
bool IsReachable(DependencyType dt = DependencyState, shared_ptr<Dependency> *failedDependency = NULL, int rstack = 0) const;
|
||||
|
@ -270,6 +272,7 @@ protected:
|
|||
virtual void OnStateLoaded(void);
|
||||
|
||||
private:
|
||||
mutable boost::mutex m_CheckableMutex;
|
||||
bool m_CheckRunning;
|
||||
long m_SchedulingOffset;
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "icinga/icingaapplication.h"
|
||||
#include "base/dynamicobject.h"
|
||||
#include "base/array.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
@ -20,7 +21,9 @@ enum AcknowledgementType
|
|||
|
||||
abstract class Checkable : DynamicObject
|
||||
{
|
||||
[config] Array::Ptr groups;
|
||||
[config] Array::Ptr groups {
|
||||
default {{{ return make_shared<Array>(); }}}
|
||||
};
|
||||
[config, protected] String check_command (CheckCommandRaw);
|
||||
[config] int max_check_attempts (MaxCheckAttemptsRaw) {
|
||||
default {{{ return 3; }}}
|
||||
|
|
|
@ -14,7 +14,6 @@ class Host : Checkable
|
|||
return m_DisplayName;
|
||||
}}}
|
||||
};
|
||||
[config] Array::Ptr groups;
|
||||
|
||||
[config] String address;
|
||||
[config] String address6;
|
||||
|
|
|
@ -66,6 +66,9 @@ bool HostGroup::EvaluateObjectRule(const Host::Ptr host, const ObjectRule& rule)
|
|||
/* assign host group membership */
|
||||
group->ResolveGroupMembership(host, true);
|
||||
|
||||
/* update groups attribute for apply */
|
||||
host->AddGroup(group_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ bool ServiceGroup::EvaluateObjectRule(const Service::Ptr service, const ObjectRu
|
|||
/* assign service group membership */
|
||||
group->ResolveGroupMembership(service, true);
|
||||
|
||||
/* update groups attribute for apply */
|
||||
service->AddGroup(group_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,21 @@ void User::Stop(void)
|
|||
}
|
||||
}
|
||||
|
||||
void User::AddGroup(const String& name)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_UserMutex);
|
||||
|
||||
Array::Ptr groups = GetGroups();
|
||||
|
||||
if (groups && groups->Contains(name))
|
||||
return;
|
||||
|
||||
if (!groups)
|
||||
groups = make_shared<Array>();
|
||||
|
||||
groups->Add(name);
|
||||
}
|
||||
|
||||
TimePeriod::Ptr User::GetPeriod(void) const
|
||||
{
|
||||
return TimePeriod::GetByName(GetPeriodRaw());
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
DECLARE_PTR_TYPEDEFS(User);
|
||||
DECLARE_TYPENAME(User);
|
||||
|
||||
void AddGroup(const String& name);
|
||||
|
||||
/* Notifications */
|
||||
TimePeriod::Ptr GetPeriod(void) const;
|
||||
|
||||
|
@ -52,6 +54,8 @@ protected:
|
|||
virtual void Stop(void);
|
||||
|
||||
virtual void OnConfigLoaded(void);
|
||||
private:
|
||||
mutable boost::mutex m_UserMutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "base/dynamicobject.h"
|
||||
#include "base/array.h"
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
@ -13,7 +14,9 @@ class User : DynamicObject
|
|||
return m_DisplayName;
|
||||
}}}
|
||||
};
|
||||
[config] Array::Ptr groups;
|
||||
[config] Array::Ptr groups {
|
||||
default {{{ return make_shared<Array>(); }}}
|
||||
};
|
||||
[config] String period (PeriodRaw);
|
||||
[config] Array::Ptr types;
|
||||
int type_filter_real (TypeFilter);
|
||||
|
|
|
@ -66,6 +66,9 @@ bool UserGroup::EvaluateObjectRule(const User::Ptr user, const ObjectRule& rule)
|
|||
/* assign user group membership */
|
||||
group->ResolveGroupMembership(user, true);
|
||||
|
||||
/* update groups attribute for apply */
|
||||
user->AddGroup(group_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue