Host update with a zone set via REST API always triggers a change

(Crossposting this issue here as well as I did on Github issue #2728)

Expected Behavior

A POST call to /director/host?name=hostname REST API should return a 304 Not modified when the object is the same and should return a 200 OK when there are modifications which are excepted by the server.

Current Behavior

When the POST contains a zone it always return a 200 OK, the director thinks there are changes, even if the object is exactly the same . In Activity log of the WebUI of the director it seems that the director thinks the former object is in the master zone files (see steps to reproduce below).

When there is no zone in the object the director returns expected behavior.

Possible Solution

There needs to come a bugfix to fix this problem to get the expected behavior also for hosts configured with a zone.

Steps to Reproduce

Host within a satellite zone (zone specified in API call) - NOT working as expected

Create host test1.example.com in zone satellite3816 via director API:

# ./director-curl POST 'host' '{"accept_config":true,"address":"192.168.1.1","has_agent":true,"imports":["basic-linux"],"object_name":"test1.example.com","object_type":"object","vars":{"sla":"24x7"},"zone":"satellite3816"}'
HTTP/1.1 201 Created
Date: Wed, 29 Mar 2023 12:05:48 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json

{
    "accept_config": true,
    "address": "192.168.1.1",
    "has_agent": true,
    "imports": [
        "basic-linux"
    ],
    "object_name": "test1.example.com",
    "object_type": "object",
    "vars": {
        "sla": "24x7"
    },
    "zone": "satellite3816"
}

Verify host test1.example.com via director API:

# ./director-curl GET 'host?name=test1.example.com'
HTTP/1.1 200 OK
Date: Thu, 29 Mar 2023 12:06:11 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json

{
    "accept_config": true,
    "address": "192.168.1.1",
    "has_agent": true,
    "imports": [
        "basic-linux"
    ],
    "object_name": "test1.example.com",
    "object_type": "object",
    "vars": {
        "sla": "24x7"
    },
    "zone": "satellite3816"
}

Activity log in webUI:

Update host test1.example.com with SAME configuration via director API:

# ./director-curl POST 'host?name=test1.example.com' '{"accept_config":true,"address":"192.168.1.1","has_agent":true,"imports":["basic-linux"],"object_name":"test1.example.com","object_type":"object","vars":{"sla":"24x7"},"zone":"satellite3816"}'
HTTP/1.1 200 OK
Date: Wed, 29 Mar 2023 12:13:49 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json

{
    "accept_config": true,
    "address": "192.168.1.1",
    "has_agent": true,
    "imports": [
        "basic-linux"
    ],
    "object_name": "test1.example.com",
    "object_type": "object",
    "vars": {
        "sla": "24x7"
    },
    "zone": "satellite3816"
}

Activity log in webUI

Grep in files generated by the director shows that the host is configured in the satellite zone:

# grep -r test1.example.com /var/lib/icinga2/api | grep -v log
/var/lib/icinga2/api/zones/satellite3816/director/agent_endpoints.conf:object Endpoint "test1.example.com" {
/var/lib/icinga2/api/zones/satellite3816/director/agent_zones.conf:object Zone "test1.example.com" {
/var/lib/icinga2/api/zones/satellite3816/director/agent_zones.conf:    endpoints = [ "test1.example.com" ]
/var/lib/icinga2/api/zones/satellite3816/director/hosts.conf:object Host "test1.example.com" {
/var/lib/icinga2/api/packages/_api/65b1b9cc-028e-4859-82b5-5e03ad01dc5c/conf.d/comments/test1.example.com!18057995-6033-494a-97f8-862a06703d86.conf:    host_name = "test1.example.com"
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/satellite3816/agent_endpoints.conf:object Endpoint "test1.example.com" {
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/satellite3816/agent_zones.conf:object Zone "test1.example.com" {
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/satellite3816/agent_zones.conf:    endpoints = [ "test1.example.com" ]
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/satellite3816/hosts.conf:object Host "test1.example.com" {
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/satellite3816/agent_endpoints.conf:object Endpoint "test1.example.com" {
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/satellite3816/agent_zones.conf:object Zone "test1.example.com" {
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/satellite3816/agent_zones.conf:    endpoints = [ "test1.example.com" ]
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/satellite3816/hosts.conf:object Host "test1.example.com" {

Conclusion: Director (API?) ‘thinks’ the host is in master zone’s files and triggers the change, this should not be the case.

Host in ‘default’ zone (zone NOT specified in API call) - working as expected

Create host test2.example.com without the zone variable (so create it in the default zone) via the director API:

# ./director-curl POST 'host' '{"accept_config":true,"address":"192.168.1.2","has_agent":true,"imports":["basic-linux"],"object_name":"test2.example.com","object_type":"object","vars":{"sla":"24x7"}}'
HTTP/1.1 201 Created
Date: Wed, 29 Mar 2023 12:19:21 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json

{
    "accept_config": true,
    "address": "192.168.1.2",
    "has_agent": true,
    "imports": [
        "basic-linux"
    ],
    "object_name": "test2.example.com",
    "object_type": "object",
    "vars": {
        "sla": "24x7"
    }
}

Verify host test2.example.com via director API:

# ./director-curl GET 'host?name=test2.example.com'
HTTP/1.1 200 OK
Date: Thu, 29 Mar 2023 12:22:46 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: application/json

{
    "accept_config": true,
    "address": "192.168.1.2",
    "has_agent": true,
    "imports": [
        "basic-linux"
    ],
    "object_name": "test2.example.com",
    "object_type": "object",
    "vars": {
        "sla": "24x7"
    }
}

Activity log in webUI:

Update host test2.example.com with SAME configuration via director API:

# ./director-curl POST 'host?name=test2.example.com' '{"accept_config":true,"address":"192.168.1.2","has_agent":true,"imports":["basic-linux"],"object_name":"test2.example.com","object_type":"object","vars":{"sla":"24x7"}}'
HTTP/1.1 304 Not Modified
Date: Wed, 29 Mar 2023 12:49:06 GMT
Server: Apache

Grep in files generated by the director shows that the host is configured in the master zone:

# grep -r test2.example.com /var/lib/icinga2/api | grep -v log
/var/lib/icinga2/api/zones/master/director/agent_endpoints.conf:object Endpoint "test2.example.com" {
/var/lib/icinga2/api/zones/master/director/agent_zones.conf:object Zone "test2.example.com" {
/var/lib/icinga2/api/zones/master/director/agent_zones.conf:    endpoints = [ "test2.example.com" ]
/var/lib/icinga2/api/zones/master/director/hosts.conf:object Host "test2.example.com" {
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/master/agent_endpoints.conf:object Endpoint "test2.example.com" {
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/master/agent_zones.conf:object Zone "test2.example.com" {
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/master/agent_zones.conf:    endpoints = [ "test2.example.com" ]
/var/lib/icinga2/api/packages/director/b6c57628-38af-4ea7-8245-c8614bb2223d/zones.d/master/hosts.conf:object Host "test2.example.com" {
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/master/agent_endpoints.conf:object Endpoint "test2.example.com" {
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/master/agent_zones.conf:object Zone "test2.example.com" {
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/master/agent_zones.conf:    endpoints = [ "test2.example.com" ]
/var/lib/icinga2/api/packages/director/3cd0508c-3504-4746-910a-31348166af8a/zones.d/master/hosts.conf:object Host "test2.example.com" {

Your Environment

  • Director version (System - About): 1.9.1
  • Icinga Web 2 version and modules (System - About): 2.11.4
  • Icinga 2 version (icinga2 --version): r2.13.7-1
  • Operating System and version: Debian 10
  • Webserver, PHP versions: 8.0