-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IcingaDB: handle null (Empty) for value/set_if/separator in command arguments #9371
Conversation
lib/icingadb/icingadb-objects.cpp
Outdated
@@ -996,6 +996,8 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S | |||
// Stringify if set. | |||
if (values->Get(attr, &value)) { | |||
switch (value.GetType()) { | |||
case ValueEmpty: | |||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me break is redundant, but that's a matter of preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I would remove it as well.
lib/icingadb/icingadb-objects.cpp
Outdated
@@ -996,6 +996,8 @@ void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const S | |||
// Stringify if set. | |||
if (values->Get(attr, &value)) { | |||
switch (value.GetType()) { | |||
case ValueEmpty: | |||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I would remove it as well.
…rguments Icinga 2 treats null (Empty) as if the corresponding attribute is not specified. However, without this commit, it would serialize the value as "null" (i.e. type string), so that it ends up in the database as this string instead of NULL. This commit adds handling for ValueEmpty so that is serialized as JSON null value and ends up in the database as NULL.
a6565bc
to
f110e26
Compare
…s-null IcingaDB: handle null (Empty) for value/set_if/separator in command arguments
Icinga 2 treats
null
(Empty
) as if the corresponding attribute is not specified. However, without this commit, it would serialize the value as"null"
(i.e. type string), so that it ends up in the database as this string instead ofNULL
. This commit adds handling for ValueEmpty so that is serialized as JSONnull
value and ends up in the database asNULL
.Note: this PR isn't based on #7919 but once both are merged, it affects
separator
in the same way.Tests
Note: to see updates to
checkcommand_argument
, you have to manuallyTRUNCATE checkcommand_argument;
and restart Icinga DB. This is because rows are only updated when the checksum changes. The checksum is obtained from the full dictionary specified in the config, rather than from just what's written to Redis. As the config doesn't change, both versions generate the same checksum even though they serialize the values differently.Config snippet:
-set_if_nullstr
generates a warning ("warning/PluginUtility: Error evaluating set_if value 'null' used in argument '--set_if_nullstr': Can't convert 'null' to a floating point number.") and is just added here for completeness to see how it behaves apart from that.Before
For the executed command, not specifying
set_if
/value
(--set_if_default
/--value_default
) or setting it tonull
explicitly (--set_if_null
/--set_if_null
) shows identical behavior:However, in Redis both are serialized differently:
This then also shows in the database:
After
Executed command stayed the same:
Things are written slightly different to Redis now,
"null"
becamenull
(sovalue
/set_if
is missing if it's not set, but set to JSONnull
if it's specified as Icinga DSLnull
):And now, there is also proper
NULL
in the database: