[icinga-checkins] icinga.org: icinga2/master: Implemented compat support for users and user groups.

git at icinga.org git at icinga.org
Thu Feb 28 10:50:31 CET 2013


Module: icinga2
Branch: master
Commit: 5228d7f10b290291d27948c33de45e5a6c7ede19
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=5228d7f10b290291d27948c33de45e5a6c7ede19

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Feb 28 10:50:20 2013 +0100

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 8e4841c..0740d60 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<User>(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<UserGroup>(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 0814e73..3db61c0 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 27b8cd4..6624c2f 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<User>(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 f9b475c..9245cb0 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<String> m_DisplayName;
 	Attribute<Dictionary::Ptr> m_Macros;
 	Attribute<Dictionary::Ptr> m_Groups;
 };
diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp
index ec1e773..99a5cdf 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 91a9cb7..8ad92b3 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<User::Ptr> GetMembers(const UserGroup::Ptr& self);
 
@@ -52,8 +50,6 @@ protected:
 
 private:
 	Attribute<String> m_DisplayName;
-	Attribute<String> m_NotesUrl;
-	Attribute<String> m_ActionUrl;
 
 	static boost::mutex m_Mutex;
 	static map<String, vector<User::WeakPtr> > m_MembersCache;





More information about the icinga-checkins mailing list