mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 15:14:07 +02:00
IcingaDB: Send the int representation of states
& types
filter
This commit is contained in:
parent
ef1c0eb9b3
commit
7037b18b34
@ -29,7 +29,9 @@ enum NotificationFilter
|
|||||||
StateFilterUnknown = 8,
|
StateFilterUnknown = 8,
|
||||||
|
|
||||||
StateFilterUp = 16,
|
StateFilterUp = 16,
|
||||||
StateFilterDown = 32
|
StateFilterDown = 32,
|
||||||
|
|
||||||
|
StateFilterAll = StateFilterOK | StateFilterWarning | StateFilterCritical | StateFilterUnknown | StateFilterUp | StateFilterDown,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +49,11 @@ enum NotificationType
|
|||||||
NotificationProblem = 32,
|
NotificationProblem = 32,
|
||||||
NotificationRecovery = 64,
|
NotificationRecovery = 64,
|
||||||
NotificationFlappingStart = 128,
|
NotificationFlappingStart = 128,
|
||||||
NotificationFlappingEnd = 256
|
NotificationFlappingEnd = 256,
|
||||||
|
|
||||||
|
NotificationTypeAll = NotificationDowntimeStart | NotificationDowntimeEnd | NotificationDowntimeRemoved |
|
||||||
|
NotificationCustom | NotificationAcknowledgement | NotificationProblem | NotificationRecovery |
|
||||||
|
NotificationFlappingStart | NotificationFlappingEnd,
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotificationCommand;
|
class NotificationCommand;
|
||||||
|
@ -1624,8 +1624,8 @@ bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& a
|
|||||||
attributes->Set("email", user->GetEmail());
|
attributes->Set("email", user->GetEmail());
|
||||||
attributes->Set("pager", user->GetPager());
|
attributes->Set("pager", user->GetPager());
|
||||||
attributes->Set("notifications_enabled", user->GetEnableNotifications());
|
attributes->Set("notifications_enabled", user->GetEnableNotifications());
|
||||||
attributes->Set("states", user->GetStates());
|
attributes->Set("states", StateFilterToRedisValue(user->GetStateFilter()));
|
||||||
attributes->Set("types", user->GetTypes());
|
attributes->Set("types", TypeFilterToRedisValue(user->GetTypeFilter()));
|
||||||
|
|
||||||
if (user->GetPeriod())
|
if (user->GetPeriod())
|
||||||
attributes->Set("timeperiod_id", GetObjectIdentifier(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("notification_interval", std::max(0.0, std::round(notification->GetInterval())));
|
||||||
attributes->Set("states", notification->GetStates());
|
attributes->Set("states", StateFilterToRedisValue(notification->GetStateFilter()));
|
||||||
attributes->Set("types", notification->GetTypes());
|
attributes->Set("types", TypeFilterToRedisValue(notification->GetTypeFilter()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -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)
|
const char* IcingaDB::GetNotificationTypeByEnum(NotificationType type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -173,6 +173,8 @@ private:
|
|||||||
|
|
||||||
static String GetObjectIdentifier(const ConfigObject::Ptr& object);
|
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 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 const char* GetNotificationTypeByEnum(NotificationType type);
|
||||||
static String CommentTypeToString(CommentType type);
|
static String CommentTypeToString(CommentType type);
|
||||||
static Dictionary::Ptr SerializeVars(const Dictionary::Ptr& vars);
|
static Dictionary::Ptr SerializeVars(const Dictionary::Ptr& vars);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user