Icinga / Icinga/icinga2

Multiple applications of `restore_attrs` HTTP API calls set attribute to a null value

Open
#11,025 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/api
Dominant language
C++
Stars
2.2k
Forks
616
Avg merge
5d 6h
Merged PRs (30d)
10

Description

Describe the bug

Bam, Oida

# curl -k -s -u "username:password" https://localhost:5665/v1/objects/services \
    | jq '.results | .[] |  select(.attrs.__name == "test!Test2") | .attrs.max_check_attempts'
3
# curl -k -s -u "username:password" https://localhost:5665/v1/objects/services  -X POST -H 'Accept: application/json' \
    -d '{ "attrs": {"max_check_attempts": 7}}'
{"results":[{"code":200,"name":"test!Test2","status":"Attributes updated.","type":"Service"}]}
# curl -k -s -u "username:password" https://localhost:5665/v1/objects/services \
    | jq '.results | .[] |  select(.attrs.__name == "test!Test2") | .attrs.max_check_attempts'
7
# curl -k -s -u "username:password" https://localhost:5665/v1/objects/services  -X POST -H 'Accept: application/json' \
    -d '{ "restore_attrs": ["max_check_attempts"]}' | jq .
{
  "results": [
    {
      "code": 200,
      "name": "test!Test2",
      "status": "Attributes updated.",
      "type": "Service"
    }
  ]
}
# curl -k -s -u "username:password" https://localhost:5665/v1/objects/services \
    | jq '.results | .[] |  select(.attrs.__name == "test!Test2") | .attrs.max_check_attempts'
3
# curl -k -s -u "username:password" https://localhost:5665/v1/objects/services  -X POST -H 'Accept: application/json' \
    -d '{ "restore_attrs": ["max_check_attempts"]}' | jq .
{
  "results": [
    {
      "code": 200,
      "name": "test!Test2",
      "status": "Attributes updated.",
      "type": "Service"                                                                                                                                                                                      }
  ]
}
# curl -k -s -u "username:password" https://localhost:5665/v1/objects/services \
    | jq '.results | .[] |  select(.attrs.__name == "test!Test2") | .attrs.max_check_attempts'
0

Expected behavior

An attribute should not be set to the null value, but not be modified at all after restoring the original value.

Your Environment

  • Version used (icinga2 --version): 2.16.5-1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the HTTP API handling POST requests to /v1/objects/services and the restore_attrs behavior shown in the curl reproduction. Repeat the two restore requests and verify that max_check_attempts remains 3 rather than becoming 0 or null; the fix is done when restoring repeatedly leaves the original value unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.