1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "icinga/user.hpp"
4 #include "icinga/user-ti.cpp"
5 #include "icinga/usergroup.hpp"
6 #include "icinga/notification.hpp"
7 #include "icinga/usergroup.hpp"
8 #include "base/objectlock.hpp"
9 #include "base/exception.hpp"
11 using namespace icinga;
15 void User::OnConfigLoaded()
17 ObjectImpl<User>::OnConfigLoaded();
19 SetTypeFilter(FilterArrayToInt(GetTypes(), Notification::GetTypeFilterMap(), ~0));
20 SetStateFilter(FilterArrayToInt(GetStates(), Notification::GetStateFilterMap(), ~0));
23 void User::OnAllConfigLoaded()
25 ObjectImpl<User>::OnAllConfigLoaded();
27 UserGroup::EvaluateObjectRules(this);
29 Array::Ptr groups = GetGroups();
32 groups = groups->ShallowClone();
34 ObjectLock olock(groups);
36 for (const String& name : groups) {
37 UserGroup::Ptr ug = UserGroup::GetByName(name);
40 ug->ResolveGroupMembership(this, true);
45 void User::Stop(bool runtimeRemoved)
47 ObjectImpl<User>::Stop(runtimeRemoved);
49 Array::Ptr groups = GetGroups();
52 ObjectLock olock(groups);
54 for (const String& name : groups) {
55 UserGroup::Ptr ug = UserGroup::GetByName(name);
58 ug->ResolveGroupMembership(this, false);
63 void User::AddGroup(const String& name)
65 boost::mutex::scoped_lock lock(m_UserMutex);
67 Array::Ptr groups = GetGroups();
69 if (groups && groups->Contains(name))
78 TimePeriod::Ptr User::GetPeriod() const
80 return TimePeriod::GetByName(GetPeriodRaw());
83 void User::ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils)
85 ObjectImpl<User>::ValidateStates(lvalue, utils);
87 int filter = FilterArrayToInt(lvalue(), Notification::GetStateFilterMap(), 0);
89 if (filter == -1 || (filter & ~(StateFilterUp | StateFilterDown | StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown)) != 0)
90 BOOST_THROW_EXCEPTION(ValidationError(this, { "states" }, "State filter is invalid."));
93 void User::ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils)
95 ObjectImpl<User>::ValidateTypes(lvalue, utils);
97 int filter = FilterArrayToInt(lvalue(), Notification::GetTypeFilterMap(), 0);
99 if (filter == -1 || (filter & ~(NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved |
100 NotificationCustom | NotificationAcknowledgement | NotificationProblem | NotificationRecovery |
101 NotificationFlappingStart | NotificationFlappingEnd)) != 0)
102 BOOST_THROW_EXCEPTION(ValidationError(this, { "types" }, "Type filter is invalid."));