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