IcingaDB: Send the int representation of states & types filter

This commit is contained in:
Yonas Habteab 2025-05-20 17:17:23 +02:00
parent ef1c0eb9b3
commit 7037b18b34
4 changed files with 43 additions and 6 deletions

View File

@ -29,7 +29,9 @@ enum NotificationFilter
StateFilterUnknown = 8,
StateFilterUp = 16,
StateFilterDown = 32
StateFilterDown = 32,
StateFilterAll = StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown | StateFilterUp | StateFilterDown,
};
/**
@ -47,7 +49,11 @@ enum NotificationType
NotificationProblem = 32,
NotificationRecovery = 64,
NotificationFlappingStart = 128,
NotificationFlappingEnd = 256
NotificationFlappingEnd = 256,
NotificationTypeAll = NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved |
NotificationCustom | NotificationAcknowledgement | NotificationProblem | NotificationRecovery |
NotificationFlappingStart | NotificationFlappingEnd,
};
class NotificationCommand;

View File

@ -1624,8 +1624,8 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
attributes->Set("email", user->GetEmail());
attributes->Set("pager", user->GetPager());
attributes->Set("notifications_enabled", user->GetEnableNotifications());
attributes->Set("states", user->GetStates());
attributes->Set("types", user->GetTypes());
attributes->Set("states", StateFilterToRedisValue(user->GetStateFilter()));
attributes->Set("types", TypeFilterToRedisValue(user->GetTypeFilter()));
if (user->GetPeriod())
attributes->Set("timeperiod_id", GetObjectIdentifier(user->GetPeriod()));
@ -1673,8 +1673,8 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
}
attributes->Set("notification_interval", std::max(0.0, std::round(notification->GetInterval())));
attributes->Set("states", notification->GetStates());
attributes->Set("types", notification->GetTypes());
attributes->Set("states", StateFilterToRedisValue(notification->GetStateFilter()));
attributes->Set("types", TypeFilterToRedisValue(notification->GetTypeFilter()));
return true;
}

View File

@ -219,6 +219,35 @@ Dictionary::Ptr IcingaDB::SerializeRedundancyGroupState(const Checkable::Ptr& ch
};
}
/**
* Converts the given filter to its Redis value representation.
*
* Within the Icinga 2 code base, if the states filter bitsets are set to -1, the filter will match on all states.
* However, since sending -1 to Redis would crash the Icinga DB daemon, as the "states" field is of type uint8, so
* the primary purpose of this function is to make sure that no values outside the valid range of 0-255 are sent to Redis.
*
* @param filter The filter to convert.
*/
int IcingaDB::StateFilterToRedisValue(int filter)
{
return filter & StateFilterAll;
}
/**
* Converts the given filter to its Redis value representation.
*
* Within the Icinga 2 code base, if the types filter bitsets are set to -1, the filter will match on all types.
* However, since sending -1 to Redis would crash the Icinga DB daemon, as the "types" field is of type uint16, so
* the primary purpose of this function is to make sure that no values outside the "types" field's valid range are
* sent to Redis.
*
* @param filter The filter to convert.
*/
int IcingaDB::TypeFilterToRedisValue(int filter)
{
return filter & NotificationTypeAll;
}
const char* IcingaDB::GetNotificationTypeByEnum(NotificationType type)
{
switch (type) {

View File

@ -173,6 +173,8 @@ private:
static String GetObjectIdentifier(const ConfigObject::Ptr& object);
static String CalcEventID(const char* eventType, const ConfigObject::Ptr& object, double eventTime = 0, NotificationType nt = NotificationType(0));
static int StateFilterToRedisValue(int filter);
static int TypeFilterToRedisValue(int filter);
static const char* GetNotificationTypeByEnum(NotificationType type);
static String CommentTypeToString(CommentType type);
static Dictionary::Ptr SerializeVars(const Dictionary::Ptr& vars);