-
Notifications
You must be signed in to change notification settings - Fork 581
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
ClassCompiler
: Don't allow to define an int as a group name in groups
attr
#9057
ClassCompiler
: Don't allow to define an int as a group name in groups
attr
#9057
Conversation
9fdbc8a
to
99308ce
Compare
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.
Post auto-generated code before/after.
Before: if (avalue()) {
ObjectLock olock(avalue());
for (const Value& value : avalue()) {
if (value.IsEmpty() || !utils.ValidateName("HostGroup", value))
BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast<ConfigObject *>(this), { "groups" }, "Object '" + value + "' of type 'HostGroup' does not exist."));
}
} After: if (avalue()) {
ObjectLock olock(avalue());
for (const Value& value : avalue()) {
if (!value.IsEmpty() && !value.IsString())
BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast<ConfigObject *>(this), { "groups" }, "Object '" + value + "' of type 'HostGroup' has an invalid name."));
if (value.IsEmpty() || !utils.ValidateName("HostGroup", value))
BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast<ConfigObject *>(this), { "groups" }, "Object '" + value + "' of type 'HostGroup' does not exist."));
}
} |
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.
Share an example Icinga2 complaint.
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.
An Icinga 2 complaint output, not the code that triggers the complaint.
object User: [2021-11-02 16:17:57 +0100] critical/config: Error: Validation failed for object 'icingaadmin' of type 'User'; Attribute 'groups': It is not allowed to specify '12' of type 'Number' as 'UserGroup' name. Expected type of 'UserGroup' name 'String'.
Location: in /prefix/etc/icinga2/conf.d/custom-host.conf: 73:3-73:33
/prefix/etc/icinga2/conf.d/custom-host.conf(71):
/prefix/etc/icinga2/conf.d/custom-host.conf(72): display_name = "Icinga 2 Admin"
/prefix/etc/icinga2/conf.d/custom-host.conf(73): groups = [ 12, "icingaadmins" ]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ object Host: [2021-11-02 16:20:42 +0100] critical/config: Error: Validation failed for object '49' of type 'Host'; Attribute 'groups': It is not allowed to specify '9' of type 'Number' as 'HostGroup' name. Expected type of 'HostGroup' name 'String'.
Location: in /prefix/etc/icinga2/conf.d/custom-host.conf: 54:9-54:30
/prefix/etc/icinga2/conf.d/custom-host.conf(52): check_command = "dummy"
/prefix/etc/icinga2/conf.d/custom-host.conf(53): enable_active_checks = 0
/prefix/etc/icinga2/conf.d/custom-host.conf(54): groups = [ name % hg ]
^^^^^^^^^^^^^^^^^^^^^^ object Service: [2021-11-02 16:24:06 +0100] critical/config: Error: Validation failed for object '9!4' of type 'Service'; Attribute 'groups': It is not allowed to specify '9' of type 'Number' as 'ServiceGroup' name. Expected type of 'ServiceGroup' name 'String'.
Location: in /prefix/etc/icinga2/conf.d/custom-host.conf: 63:9-63:35
/prefix/etc/icinga2/conf.d/custom-host.conf(61): check_command = "dummy"
/prefix/etc/icinga2/conf.d/custom-host.conf(62): enable_active_checks = 0
/prefix/etc/icinga2/conf.d/custom-host.conf(63): groups = [ host_name % sg ]
^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
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.
Doesn’t Icinga 2 already show you the code location along with the wrong value and its type?
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.
Share an example Icinga2 complaint.
And with the group being null, not a number?
Nothing happens. But if you explicitly define [2021-11-02 17:01:59 +0100] critical/config: Error: Validation failed for object '27!1' of type 'Service'; Attribute 'groups': Object '' of type 'ServiceGroup' does not exist.
Location: in /prefix/etc/icinga2/conf.d/custom-host.conf: 63:9-63:25
/prefix/etc/icinga2/conf.d/custom-host.conf(61): check_command = "dummy"
/prefix/etc/icinga2/conf.d/custom-host.conf(62): enable_active_checks = 0
/prefix/etc/icinga2/conf.d/custom-host.conf(63): groups = [ null ]
^^^^^^^^^^^^^^^^^ Note: This check applies also to notification's |
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.
Once done, let Julian review. (No need for squashing at all, will be done while merging.)
What's the issue this is supposed to solve? If I try the current master, I get the following which looks okay as well:
|
Generally for Icinga2 this doesn't matter, as the integers are implicitly cast to string, but when icinga2 writes to the IDO, this |
I see, so with this config
you eventually run into this error:
Have you considered normalizing all array elements to be of type string, so that the config would just work? I think it's a bit inconsistent that you can declare a group as |
What for? After all:
|
I'm just thinking out loud. It's not a request for changes. As I said, it would probably be more consistent but not practically relevant. |
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.
Just noticed strange behavior with empty strings as object names, but that not related to this PR so I created #9097 for it.
Apart from this, looks fine for me, just needs to be squashed on merge.
Won't be backported. Rationale: the current fix is slightly backwards-incompatible and most likely users don't have group names that can be represented by other types than string. |
No description provided.