Skip to content
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

icingacli error with modify action - Trying to set invalid key "fields" #2945

Open
andyb2000 opened this issue Dec 13, 2024 · 2 comments
Open

Comments

@andyb2000
Copy link

Describe the bug

The error is when trying to amend/update an icinga director service. To do an amend first I query the current service object using:
icingacli director service show --host="aslf02" 'check_juniper_load' --json --no-pretty

which returns the json output, I would then modify the keys/values and then submit the change back. However when pushing back the change (for example even if I don't change any fields and push back exactly the same record) I get the error:

ERROR: InvalidArgumentException in /usr/share/icingaweb2/modules/director/library/Director/Data/Db/DbObject.php:364 with message: Trying to set invalid key "fields"

The "director service show" command returns:

icingacli director service show --host="aslf02" 'check_juniper_load' --json --no-pretty

{"fields":[],"host":"aslf02","imports":["servicetemplate-XXXX","service-juniper-load"],"notes":"Added by icinga-import 10:14:56 13/12/2024","object_name":"check_juniper_load","object_type":"object","uuid":"198e50ba-73d8-4be8-979f-fae427918a2b","vars":{"ARG1":"20,30,40"}}

You can see the first json array returned is "fields". This isn't being set in my code anywhere, it seems to be a default parameter added either by director or icinga.
So if I then submit that back I get the error returned as it's trying to set the key "fields" which it states to be invalid.

In previous versions of icinga/icingacli this didn't occur, however my other installation is a much older install so this may be a few revisions since this crept in.

icingacli version
Icinga Web 2 2.12.2
Git Commit 7f9217b0521f19f770ad59ca17d7d4b3514e54e5
PHP Version 8.1.2-1ubuntu2.19
MODULE VERSION
director 1.11.3
incubator 0.22.0
monitoring 2.12.2
pnp 1.0.1
pulsant-theme 1.0.1

(For reference, my older install uses 2.7.3 which doesn't appear to have this issue)

If I do an "inspect" via the GUI I see no reference of this key "fields".

Looking at the code, the export I suspect is adding this is here:
/usr/share/icingaweb2/modules/director/library/Director/Data/Exporter.php

protected function exportIcingaObject(IcingaObject $object)
    {
        $props = (array) $object->toPlainObject($this->resolveObjects, !$this->showDefaults);
        if ($object->supportsFields()) {
            $props['fields'] = $this->fieldReferenceLoader->loadFor($object);
        }

        return $props;
    }

But I'm not clear if this should be exporting the property "fields" or not when it's clearly blank in my case?

@nilmerg nilmerg transferred this issue from Icinga/icingaweb2 Dec 16, 2024
@andyb2000
Copy link
Author

Actually, I think I'm looking in the wrong place. It could have custom fields defined, so the export seems correct in creating/exporting this value, however the import seems to be the problem.
On import it's hitting this failure:

/usr/share/icingaweb2/modules/director/library/Director/Data/Db/DbObject.php

        if (! $this->hasProperty($key)) {
            throw new InvalidArgumentException(sprintf(
                'Trying to set invalid key "%s"',
                $key
            ));
        }

So this: $this->hasProperty($key) (whereby $key must be 'fields') is getting a false.

@moreamazingnick
Copy link
Contributor

This also happens when using the REST API.
The object you get is from the api contains the "fields" array but when you send it back to update something the "fields" array isn't allowed. I think this problem was introduced in 1.10.

moreamazingnick added a commit to RISE-GmbH/icingaweb2-module-director that referenced this issue Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants