mirror of https://github.com/Icinga/icinga2.git
Require at least one user for notification objects (user or as member of user_groups)
fixes #8067
This commit is contained in:
parent
9302a6d03c
commit
db9c55835f
|
@ -107,6 +107,7 @@
|
||||||
|
|
||||||
%type Notification {
|
%type Notification {
|
||||||
%validator "ValidateNotificationFilters"
|
%validator "ValidateNotificationFilters"
|
||||||
|
%validator "ValidateNotificationUsers"
|
||||||
|
|
||||||
%require "host_name",
|
%require "host_name",
|
||||||
%attribute %name(Host) "host_name",
|
%attribute %name(Host) "host_name",
|
||||||
|
|
|
@ -34,6 +34,7 @@ using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(Notification);
|
REGISTER_TYPE(Notification);
|
||||||
REGISTER_SCRIPTFUNCTION(ValidateNotificationFilters, &Notification::ValidateFilters);
|
REGISTER_SCRIPTFUNCTION(ValidateNotificationFilters, &Notification::ValidateFilters);
|
||||||
|
REGISTER_SCRIPTFUNCTION(ValidateNotificationUsers, &Notification::ValidateUsers);
|
||||||
INITIALIZE_ONCE(&Notification::StaticInitialize);
|
INITIALIZE_ONCE(&Notification::StaticInitialize);
|
||||||
|
|
||||||
boost::signals2::signal<void (const Notification::Ptr&, double, const MessageOrigin&)> Notification::OnNextNotificationChanged;
|
boost::signals2::signal<void (const Notification::Ptr&, double, const MessageOrigin&)> Notification::OnNextNotificationChanged;
|
||||||
|
@ -500,6 +501,24 @@ int icinga::FilterArrayToInt(const Array::Ptr& typeFilters, int defaultValue)
|
||||||
return resultTypeFilter;
|
return resultTypeFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Notification::ValidateUsers(const String& location, const Notification::Ptr& object)
|
||||||
|
{
|
||||||
|
std::set<User::Ptr> allUsers;
|
||||||
|
|
||||||
|
std::set<User::Ptr> users = object->GetUsers();
|
||||||
|
std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
|
||||||
|
|
||||||
|
BOOST_FOREACH(const UserGroup::Ptr& ug, object->GetUserGroups()) {
|
||||||
|
std::set<User::Ptr> members = ug->GetMembers();
|
||||||
|
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allUsers.empty()) {
|
||||||
|
BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
|
||||||
|
location + ": No users/user_groups specified.", object->GetDebugInfo()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Notification::ValidateFilters(const String& location, const Notification::Ptr& object)
|
void Notification::ValidateFilters(const String& location, const Notification::Ptr& object)
|
||||||
{
|
{
|
||||||
int sfilter = FilterArrayToInt(object->GetStates(), 0);
|
int sfilter = FilterArrayToInt(object->GetStates(), 0);
|
||||||
|
|
|
@ -109,6 +109,7 @@ public:
|
||||||
|
|
||||||
static void RegisterApplyRuleHandler(void);
|
static void RegisterApplyRuleHandler(void);
|
||||||
|
|
||||||
|
static void ValidateUsers(const String& location, const Notification::Ptr& object);
|
||||||
static void ValidateFilters(const String& location, const Notification::Ptr& object);
|
static void ValidateFilters(const String& location, const Notification::Ptr& object);
|
||||||
|
|
||||||
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
||||||
|
|
Loading…
Reference in New Issue