Multiple applications of `restore_attrs` HTTP API calls set attribute to a null value
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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