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

API create service (POST, PUT) issue json parsing. same json validates and changes fine with API modifiy and icingacli #2576

Closed
abaumgaertner opened this issue Jul 29, 2022 · 0 comments
Assignees
Labels
Milestone

Comments

@abaumgaertner
Copy link

present in current master 5686629
issue to create services from shell (PUT, POST)
refactoring: json validation routines are different, depending on call type (cli vs. api, post, put)

working example with basic data

cat initial_service.json
{
    "host": "somehost",
    "imports": [
        "some_template"
    ],
    "object_name": "some_service",
    "object_type": "object"
}

icingacli - works fine

cat initial_service.json | icingacli director service create --json
Service '' has been created

--> service name is missing in output, but service is created correctly in director

now delete service again

icingacli director service delete some_service --host somehost
Service 'some_service' has been deleted

API Issues

  1. API create (POST) call fails - json validation issue
USERNAME='username:password'
curl --insecure -s -S -u $USERNAME -H 'Accept: application/json' -X POST "https://icinga2-test.internal/icingaweb2/director/service" -d @intial_service.json
{
    "error": "Invalid JSON: Syntax error"
}
  1. API create (PUT) call fails - stacktrace
USERNAME='username:password'
curl --insecure -s -S -u $USERNAME -H 'Accept: application/json' -X PUT "https://icinga2-test.internal/icingaweb2/director/service" -d @intial_service.json
{"status":"error","message":"Uncaught TypeError: Argument 1 passed to Icinga\\Module\\Director\\RestApi\\IcingaObjectHandler::persistChanges() must be an instance of Icinga\\Module\\Director\\Objects\\IcingaObject, null given, called in \/usr\/share\/icingaweb2\/modules\/director\/library\/Director\/RestApi\/IcingaObjectHandler.php on line 150 and defined in \/usr\/share\/icingaweb2\/modules\/director\/library\/Director\/RestApi\/IcingaObjectHandler.php:170\nStack trace:\n#0 \/usr\/share\/icingaweb2\/modules\/director\/library\/Director\/RestApi\/IcingaObjectHandler.php(150): Icinga\\Module\\Director\\RestApi\\IcingaObjectHandler->persistChanges(NULL)\n#1 \/usr\/share\/icingaweb2\/modules\/director\/library\/Director\/RestApi\/IcingaObjectHandler.php(83): Icinga\\Module\\Director\\RestApi\\IcingaObjectHandler->handleApiRequest()\n#2 \/usr\/share\/icingaweb2\/modules\/director\/library\/Director\/RestApi\/RequestHandler.php(33): Icinga\\Module\\Director\\RestApi\\IcingaObjectHandler->processApiRequest()\n#3 \/usr\/share\/icingaweb2\/modules\/director\/library\/Director\/Web\/Controller\/ObjectController.php(89): Icin"}

API modifiy (POST) call works - in this case, json validation works.

cat modified_service.json
{
    "host": "somehost",
    "imports": [
        "some_template"
    ],
    "object_name": "some_service",
    "object_type": "object",
    "vars": {
        "var1": "abc",
        "var2": "def"
    }
}
USERNAME='username:password'
curl --insecure -s -S -u $USERNAME -H 'Accept: application/json' -X POST 'https://icinga2-test.internal/icingaweb2/director/service?host=somehost&name=some_service' -d @modified_service.json
{
    "host": "somehost",
    "imports": [
        "some_template"
    ],
    "object_name": "some_service",
    "object_type": "object",
    "vars": {
        "var1": "abc",
        "var2": "def"
    }
}
@Thomas-Gelf Thomas-Gelf self-assigned this Aug 2, 2022
@Thomas-Gelf Thomas-Gelf added the bug label Aug 2, 2022
@Thomas-Gelf Thomas-Gelf added this to the 1.10.0 milestone Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants