From 5228d7f10b290291d27948c33de45e5a6c7ede19 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 28 Feb 2013 10:50:20 +0100 Subject: [PATCH] Implemented compat support for users and user groups. --- components/compat/compatcomponent.cpp | 45 +++++++++++++++++++++++++++ itl/types.conf | 2 ++ lib/icinga/user.cpp | 9 ++++++ lib/icinga/user.h | 2 ++ lib/icinga/usergroup.cpp | 12 ------- lib/icinga/usergroup.h | 4 --- 6 files changed, 58 insertions(+), 16 deletions(-) diff --git a/components/compat/compatcomponent.cpp b/components/compat/compatcomponent.cpp index 8e4841ce2..0740d60f3 100644 --- a/components/compat/compatcomponent.cpp +++ b/components/compat/compatcomponent.cpp @@ -663,6 +663,51 @@ void CompatComponent::StatusTimerHandler(void) objectfp << tempobjectfp.str(); } + BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) { + User::Ptr user = static_pointer_cast(object); + + stringstream tempobjectfp; + tempobjectfp << std::fixed; + + { + ObjectLock olock(user); + + tempobjectfp << "define contact {" << "\n" + << "\t" << "contact_name" << "\t" << user->GetName() << "\n" + << "\t" << "alias" << "\t" << user->GetDisplayName() << "\n" + << "\t" << "service_notification_options" << "\t" << "w,u,c,r,f,s" << "\n" + << "\t" << "host_notification_options" << "\t" << "d,u,r,f,s" << "\n" + << "\t" << "host_notifications_enabled" << "\t" << 1 << "\n" + << "\t" << "service_notifications_enabled" << "\t" << 1 << "\n" + << "\t" << "}" << "\n" + << "\n"; + } + + objectfp << tempobjectfp.str(); + } + + BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) { + UserGroup::Ptr ug = static_pointer_cast(object); + + stringstream tempobjectfp; + tempobjectfp << std::fixed; + + { + ObjectLock olock(ug); + + tempobjectfp << "define contactgroup {" << "\n" + << "\t" << "contactgroup_name" << "\t" << ug->GetName() << "\n" + << "\t" << "alias" << "\t" << ug->GetDisplayName() << "\n"; + } + + tempobjectfp << "\t" << "members" << "\t"; + DumpNameList(tempobjectfp, UserGroup::GetMembers(ug)); + tempobjectfp << "\n" + << "\t" << "}" << "\n"; + + objectfp << tempobjectfp.str(); + } + statusfp.close(); objectfp.close(); diff --git a/itl/types.conf b/itl/types.conf index 0814e730e..3db61c0f8 100644 --- a/itl/types.conf +++ b/itl/types.conf @@ -277,6 +277,8 @@ type Script { } type User { + %attribute string "display_name", + %attribute dictionary "macros" { %attribute string "*" }, diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index 27b8cd4fc..6624c2fe7 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -26,6 +26,7 @@ REGISTER_TYPE(User, NULL); User::User(const Dictionary::Ptr& properties) : DynamicObject(properties) { + RegisterAttribute("display_name", Attribute_Config, &m_DisplayName); RegisterAttribute("macros", Attribute_Config, &m_Macros); RegisterAttribute("groups", Attribute_Config, &m_Groups); } @@ -48,6 +49,14 @@ User::Ptr User::GetByName(const String& name) return dynamic_pointer_cast(configObject); } +String User::GetDisplayName(void) const +{ + if (!m_DisplayName.IsEmpty()) + return m_DisplayName; + else + return GetName(); +} + Dictionary::Ptr User::GetGroups(void) const { return m_Groups; diff --git a/lib/icinga/user.h b/lib/icinga/user.h index f9b475ca0..9245cb0f4 100644 --- a/lib/icinga/user.h +++ b/lib/icinga/user.h @@ -39,6 +39,7 @@ public: static User::Ptr GetByName(const String& name); + String GetDisplayName(void) const; Dictionary::Ptr GetGroups(void) const; Dictionary::Ptr GetMacros(void) const; @@ -48,6 +49,7 @@ protected: void OnAttributeChanged(const String& name, const Value& oldValue); private: + Attribute m_DisplayName; Attribute m_Macros; Attribute m_Groups; }; diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index ec1e773c7..99a5cdf08 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -31,8 +31,6 @@ UserGroup::UserGroup(const Dictionary::Ptr& properties) : DynamicObject(properties) { RegisterAttribute("display_name", Attribute_Config, &m_DisplayName); - RegisterAttribute("notes_url", Attribute_Config, &m_NotesUrl); - RegisterAttribute("action_url", Attribute_Config, &m_ActionUrl); } UserGroup::~UserGroup(void) @@ -53,16 +51,6 @@ String UserGroup::GetDisplayName(void) const return GetName(); } -String UserGroup::GetNotesUrl(void) const -{ - return m_NotesUrl; -} - -String UserGroup::GetActionUrl(void) const -{ - return m_ActionUrl; -} - /** * @threadsafety Always. */ diff --git a/lib/icinga/usergroup.h b/lib/icinga/usergroup.h index 91a9cb7c8..8ad92b337 100644 --- a/lib/icinga/usergroup.h +++ b/lib/icinga/usergroup.h @@ -40,8 +40,6 @@ public: static UserGroup::Ptr GetByName(const String& name); String GetDisplayName(void) const; - String GetNotesUrl(void) const; - String GetActionUrl(void) const; static set GetMembers(const UserGroup::Ptr& self); @@ -52,8 +50,6 @@ protected: private: Attribute m_DisplayName; - Attribute m_NotesUrl; - Attribute m_ActionUrl; static boost::mutex m_Mutex; static map > m_MembersCache;