Skip to content

Commit

Permalink
Icinga DB: Make sure object relationships are handled correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
N-o-X committed Nov 12, 2021
1 parent 4e79eb0 commit 73e0d6e
Show file tree
Hide file tree
Showing 16 changed files with 498 additions and 66 deletions.
4 changes: 2 additions & 2 deletions lib/icinga/command.ti
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace icinga
abstract class Command : CustomVarObject
{
[config] Value command (CommandLine);
[config] Value arguments;
[config, signal_with_old_value] Value arguments;
[config] int timeout {
default {{{ return 60; }}}
};
[config] Dictionary::Ptr env;
[config, signal_with_old_value] Dictionary::Ptr env;
[config, required] Function::Ptr execute;
};

Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/customvarobject.ti
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace icinga

abstract class CustomVarObject : ConfigObject
{
[config] Dictionary::Ptr vars;
[config, signal_with_old_value] Dictionary::Ptr vars;
};

}
2 changes: 1 addition & 1 deletion lib/icinga/host.ti
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Host : Checkable
load_after Endpoint;
load_after Zone;

[config, no_user_modify, required] array(name(HostGroup)) groups {
[config, no_user_modify, required, signal_with_old_value] array(name(HostGroup)) groups {
default {{{ return new Array(); }}}
};

Expand Down
6 changes: 6 additions & 0 deletions lib/icinga/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ void Notification::Start(bool runtimeCreated)
if (ApiListener::IsHACluster() && GetNextNotification() < Utility::GetTime() + 60)
SetNextNotification(Utility::GetTime() + 60, true);

for (const UserGroup::Ptr& group : GetUserGroups())
group->AddNotification(this);

ObjectImpl<Notification>::Start(runtimeCreated);
}

Expand All @@ -144,6 +147,9 @@ void Notification::Stop(bool runtimeRemoved)

if (obj)
obj->UnregisterNotification(this);

for (const UserGroup::Ptr& group : GetUserGroups())
group->RemoveNotification(this);
}

Checkable::Ptr Notification::GetCheckable() const
Expand Down
4 changes: 2 additions & 2 deletions lib/icinga/notification.ti
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Notification : CustomVarObject < NotificationNameComposer
return TimePeriod::GetByName(GetPeriodRaw());
}}}
};
[config, protected] array(name(User)) users (UsersRaw);
[config, protected] array(name(UserGroup)) user_groups (UserGroupsRaw);
[config, signal_with_old_value] array(name(User)) users (UsersRaw);
[config, signal_with_old_value] array(name(UserGroup)) user_groups (UserGroupsRaw);
[config] Dictionary::Ptr times;
[config] array(Value) types;
[no_user_view, no_user_modify] int type_filter_real (TypeFilter);
Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/service.ti
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Service : Checkable < ServiceNameComposer
load_after Host;
load_after Zone;

[config, no_user_modify, required] array(name(ServiceGroup)) groups {
[config, no_user_modify, required, signal_with_old_value] array(name(ServiceGroup)) groups {
default {{{ return new Array(); }}}
};

Expand Down
6 changes: 3 additions & 3 deletions lib/icinga/timeperiod.ti
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class TimePeriod : CustomVarObject
return m_DisplayName.m_Value;
}}}
};
[config] Dictionary::Ptr ranges;
[config, signal_with_old_value] Dictionary::Ptr ranges;
[config, required] Function::Ptr update;
[config] bool prefer_includes {
default {{{ return true; }}}
};
[config, required] array(name(TimePeriod)) excludes {
[config, required, signal_with_old_value] array(name(TimePeriod)) excludes {
default {{{ return new Array(); }}}
};
[config, required] array(name(TimePeriod)) includes {
[config, required, signal_with_old_value] array(name(TimePeriod)) includes {
default {{{ return new Array(); }}}
};
[state, no_user_modify] Value valid_begin;
Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/user.ti
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class User : CustomVarObject
return m_DisplayName.m_Value;
}}}
};
[config, no_user_modify, required] array(name(UserGroup)) groups {
[config, no_user_modify, required, signal_with_old_value] array(name(UserGroup)) groups {
default {{{ return new Array(); }}}
};
[config, navigation] name(TimePeriod) period (PeriodRaw) {
Expand Down
18 changes: 18 additions & 0 deletions lib/icinga/usergroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ void UserGroup::RemoveMember(const User::Ptr& user)
m_Members.erase(user);
}

std::set<Notification::Ptr> UserGroup::GetNotifications() const
{
std::unique_lock<std::mutex> lock(m_UserGroupMutex);
return m_Notifications;
}

void UserGroup::AddNotification(const Notification::Ptr& notification)
{
std::unique_lock<std::mutex> lock(m_UserGroupMutex);
m_Notifications.insert(notification);
}

void UserGroup::RemoveNotification(const Notification::Ptr& notification)
{
std::unique_lock<std::mutex> lock(m_UserGroupMutex);
m_Notifications.erase(notification);
}

bool UserGroup::ResolveGroupMembership(const User::Ptr& user, bool add, int rstack) {

if (add && rstack > 20) {
Expand Down
6 changes: 6 additions & 0 deletions lib/icinga/usergroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace icinga
{

class ConfigItem;
class Notification;

/**
* An Icinga user group.
Expand All @@ -27,13 +28,18 @@ class UserGroup final : public ObjectImpl<UserGroup>
void AddMember(const User::Ptr& user);
void RemoveMember(const User::Ptr& user);

std::set<intrusive_ptr<Notification>> GetNotifications() const;
void AddNotification(const intrusive_ptr<Notification>& notification);
void RemoveNotification(const intrusive_ptr<Notification>& notification);

bool ResolveGroupMembership(const User::Ptr& user, bool add = true, int rstack = 0);

static void EvaluateObjectRules(const User::Ptr& user);

private:
mutable std::mutex m_UserGroupMutex;
std::set<User::Ptr> m_Members;
std::set<intrusive_ptr<Notification>> m_Notifications;

static bool EvaluateObjectRule(const User::Ptr& user, const intrusive_ptr<ConfigItem>& group);
};
Expand Down
Loading

0 comments on commit 73e0d6e

Please sign in to comment.