Implemented compat support for users and user groups.

This commit is contained in:
Gunnar Beutner 2013-02-28 10:50:20 +01:00
parent b674d46557
commit 5228d7f10b
6 changed files with 58 additions and 16 deletions

View File

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

View File

@ -277,6 +277,8 @@ type Script {
}
type User {
%attribute string "display_name",
%attribute dictionary "macros" {
%attribute string "*"
},

View File

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

View File

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

View File

@ -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.
*/

View File

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