Add AddGroup() for host, service, user objects.

Refs #6105
This commit is contained in:
Michael Friedrich 2014-05-01 23:53:08 +02:00
parent 3c2dae1804
commit 01a0496988
7 changed files with 39 additions and 3 deletions

View File

@ -88,6 +88,18 @@ void Checkable::OnStateLoaded(void)
} }
} }
void Checkable::AddGroup(const String& name)
{
boost::mutex::scoped_lock lock(m_CheckableMutex);
Array::Ptr groups = GetGroups();
if (!groups)
groups = make_shared<Array>();
groups->Add(name);
}
AcknowledgementType Checkable::GetAcknowledgement(void) AcknowledgementType Checkable::GetAcknowledgement(void)
{ {
ASSERT(OwnsLock()); ASSERT(OwnsLock());

View File

@ -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;

View File

@ -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; }}}

View File

@ -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;

View File

@ -69,6 +69,18 @@ void User::Stop(void)
} }
} }
void User::AddGroup(const String& name)
{
boost::mutex::scoped_lock lock(m_UserMutex);
Array::Ptr groups = GetGroups();
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());

View File

@ -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;
}; };
} }

View File

@ -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);