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

[dev.icinga.com #11396] inconsistent API /v1/objects/* response for PUT requests #4038

Closed
icinga-migration opened this issue Mar 16, 2016 · 9 comments

Comments

Projects
None yet
1 participant
@icinga-migration
Copy link
Member

commented Mar 16, 2016

This issue has been migrated from Redmine: https://dev.icinga.com/issues/11396

Created by danvaida on 2016-03-16 12:39:04 +00:00

Assignee: mfriedrich
Status: Resolved (closed on 2016-05-09 13:10:03 +00:00)
Target Version: 2.4.8
Last Update: 2016-05-11 07:38:31 +00:00 (in Redmine)

Icinga Version: 2.4.3
Backport?: Not yet backported
Include in Changelog: 1

icinga2 --version
icinga2 - The Icinga 2 network monitoring daemon (version: v2.4.3)

Copyright (c) 2012-2016 Icinga Development Team (https://www.icinga.org/)
License GPLv2+: GNU GPL version 2 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Application information:
  Installation root: /usr
  Sysconf directory: /etc
  Run directory: /run
  Local state directory: /var
  Package data directory: /usr/share/icinga2
  State path: /var/lib/icinga2/icinga2.state
  Modified attributes path: /var/lib/icinga2/modified-attributes.conf
  Objects path: /var/cache/icinga2/icinga2.debug
  Vars path: /var/cache/icinga2/icinga2.vars
  PID path: /run/icinga2/icinga2.pid

System information:
  Platform: CentOS Linux
  Platform version: 7 (Core)
  Kernel: Linux
  Kernel version: 3.10.0-229.14.1.el7.x86_64
  Architecture: x86_64

While calling the API for 3 operations, I am expecting something different. For example:

curl -s --cacert /etc/icinga2/pki/ca.crt --cert /etc/icinga2/pki/icinga2-master.crt --key /etc/icinga2/pki/icinga2-master.key -H 'Accept: application/json' -X PUT 'https://icinga2-master:5665/v1/objects/users/dvaida' -d '{ "attrs": { "email": "me@me.com" } }' | python -m json.tool
{
    "results": [
        {
            "code": 200.0,
            "status": "Object was created"
        }
    ]
}

curl -s --cacert /etc/icinga2/pki/ca.crt --cert /etc/icinga2/pki/icinga2-master.crt --key /etc/icinga2/pki/icinga2-master.key -H 'Accept: application/json' -X PUT 'https://icinga2-master:5665/v1/objects/users/dvaida' -d '{ "attrs": { "email": "me@me.com" } }'
Error: Configuration file '/var/lib/icinga2/api/packages/_api/icinga2-master-1457440041-1/conf.d/users/dvaida.conf' already exists.

It'd be nice to get a 503 maybe (like in the case of other requests for already existing objects).

curl -s --cacert /etc/icinga2/pki/ca.crt --cert /etc/icinga2/pki/icinga2-master.crt --key /etc/icinga2/pki/icinga2-master.key -H 'Accept: application/json' -X DELETE 'https://icinga2-master:5665/v1/objects/users/dvaida' | python -m json.tool
{
    "results": [
        {
            "code": 200.0,
            "name": "dvaida",
            "status": "Object was deleted.",
            "type": "User"
        }
    ]
}

Also, I can't really tell if the object was indeed updated or not as it's always the same response:

curl -s --cacert /etc/icinga2/pki/ca.crt --cert /etc/icinga2/pki/icinga2-master.crt --key /etc/icinga2/pki/icinga2-master.key -H 'Accept: application/json' -X POST 'https://icinga2-master:5665/v1/objects/users/dvaida' -d '{ "attrs": { "email": "me@me.com" } }' | python -m json.tool
{
    "results": [
        {
            "code": 200.0,
            "name": "dvaida",
            "status": "Attributes updated.",
            "type": "User"
        }
    ]
}

Attachments

Changesets

2016-05-09 13:08:35 +00:00 by mfriedrich 8a65c4a

API: Fix error message with PUT requests for existing objects

fixes #11396

2016-05-10 11:43:36 +00:00 by mfriedrich 1c6f09f

API: Fix error message handling for invalid attributes in PUT requests

refs #11396

2016-05-12 09:08:21 +00:00 by mfriedrich 83985f9

API: Fix error message with PUT requests for existing objects

fixes #11396

2016-05-12 09:09:49 +00:00 by mfriedrich 06f97c8

API: Fix error message handling for invalid attributes in PUT requests

refs #11396
@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented Mar 18, 2016

Updated by mfriedrich on 2016-03-18 10:07:03 +00:00

  • Status changed from New to Assigned
  • Assigned to set to jflach
  • Change the PUT request to return a JSON response if an object already exists
  • Discuss whether changes could be highlighted in a better way
@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented Mar 18, 2016

Updated by mfriedrich on 2016-03-18 23:56:15 +00:00

  • Parent Id set to 11415
@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented Mar 19, 2016

Updated by tgelf on 2016-03-19 22:02:28 +00:00

@dnsmichi: modified => 200, created => 201, unchanged => 304

@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented May 9, 2016

Updated by mfriedrich on 2016-05-09 13:04:54 +00:00

  • Assigned to changed from jflach to mfriedrich
  • Target Version set to 2.4.8

The PUT error should return a JSON error instead of throwing an exception. In terms of detecting whether an object was modified or not - that is currently not possible at this stage and not planned to add that.

I'm therefore fixing the PUT error message as missing part to resolve the ticket.

@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented May 9, 2016

Updated by mfriedrich on 2016-05-09 13:08:06 +00:00

  • File added i2_api_11396_02.png
  • File added i2_api_11396_01.png

old

i2_api_11396_01.png

new

i2_api_11396_02.png

@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented May 9, 2016

Updated by mfriedrich on 2016-05-09 13:10:03 +00:00

  • Status changed from Assigned to Resolved
  • Done % changed from 0 to 100

Applied in changeset 8a65c4a.

@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented May 9, 2016

Updated by mfriedrich on 2016-05-09 13:10:31 +00:00

  • Subject changed from inconsistent API /v1/objects/users endpoint response to inconsistent API /v1/objects/* response for PUT requests
@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented May 10, 2016

Updated by mfriedrich on 2016-05-10 11:43:29 +00:00

Similar problem when specifying an invalid attribute (e.g. 'check_command' for a usergroup object) or internal attributes.

@icinga-migration

This comment has been minimized.

Copy link
Member Author

commented May 11, 2016

Updated by mfriedrich on 2016-05-11 07:38:32 +00:00

  • Parent Id deleted 11415

@icinga-migration icinga-migration added this to the 2.4.8 milestone Jan 17, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.