API does not return hosts in zone

Standard info:

  • Version: r2.13.0-1
  • Debian 10
  • Enabled features: api checker ido-pgsql mainlog notification
  • Icinga Web 2 version: 2.9.3
  • Icinga Web 2 modules: doc and monitoring, 2.9.3
[2021-08-12 21:48:28 +0000] information/cli: Icinga application loader (version: r2.13.0-1)
[2021-08-12 21:48:28 +0000] information/cli: Loading configuration file(s).
[2021-08-12 21:48:28 +0000] information/ConfigItem: Committing config item(s).
[2021-08-12 21:48:28 +0000] information/ApiListener: My API identity: myhostname
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 12 Notifications.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 IcingaApplication.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 2 NotificationCommands.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 2 HostGroups.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 2 Hosts.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 FileLogger.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 CheckerComponent.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 ApiListener.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 4 Zones.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 2 Endpoints.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 IdoPgsqlConnection.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 2 ApiUsers.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 244 CheckCommands.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 NotificationComponent.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 UserGroup.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 User.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 3 TimePeriods.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 3 ServiceGroups.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 1 ScheduledDowntime.
[2021-08-12 21:48:28 +0000] information/ConfigItem: Instantiated 13 Services.
[2021-08-12 21:48:28 +0000] information/ScriptGlobal: Dumping variables to file '/var/cache/icinga2/icinga2.vars'
[2021-08-12 21:48:28 +0000] information/cli: Finished validating the configuration file(s).

Object 'master' of type 'Zone':
  % declared in '/etc/icinga2/zones.conf', lines 6:1-6:20
  * __name = "master"
  * endpoints = [ "myhostname" ]
    % = modified in '/etc/icinga2/zones.conf', lines 7:2-7:33
  * global = false
  * name = "master"
  * package = "_etc"
  * parent = ""
  * source_location
    * first_column = 1
    * first_line = 6
    * last_column = 20
    * last_line = 6
    * path = "/etc/icinga2/zones.conf"
  * templates = [ "master" ]
    % = modified in '/etc/icinga2/zones.conf', lines 6:1-6:20
  * type = "Zone"
  * zone = ""
Object 'myhostname' of type 'Endpoint':
  % declared in '/etc/icinga2/zones.conf', lines 9:1-9:32
  * __name = "myhostname"
  * host = ""
  * log_duration = 86400
  * name = "myhostname"
  * package = "_etc"
  * port = "5665"
  * source_location
    * first_column = 1
    * first_line = 9
    * last_column = 32
    * last_line = 9
    * path = "/etc/icinga2/zones.conf"
  * templates = [ "myhostname" ]
    % = modified in '/etc/icinga2/zones.conf', lines 9:1-9:32
  * type = "Endpoint"
  * zone = ""

zones.d/master/hosts.conf:

object Host "myhostname" {
  name = "myhostname"
  /* Import the default host template defined in `templates.conf`. */
  import "generic-host"
  vars.agent_endpoint = name
  /* Specify the address attributes for checks e.g. `ssh` or `http`. */
  address = "localhost"
  address6 = "::1"

  /* Set custom variable `os` for hostgroup assignment in `groups.conf`. */
  vars.os = "Linux"

  /* Define http vhost attributes for service apply rules in `services.conf`. */
  vars.http_vhosts["http"] = {
    http_uri = "/"
  }
  vars.http_vhosts["Icinga Web 2"] = {
    http_uri = "/icingaweb2"
  }

  /* Define disks and attributes for service apply rules in `services.conf`. */
  vars.disks["disk"] = {
    /* No parameters. */
  }
  vars.disks["disk /"] = {
    disk_partitions = "/"
  }

  /* Define notification mail attributes for notification apply rules in `notifications.conf`. */
  vars.notification["mail"] = {
    /* The UserGroup `icingaadmins` is defined in `users.conf`. */
    groups = [ "icingaadmins" ]
  }

}

Prior to running the node wizard for master, icingaweb2 was happily displaying my host and the associated service checks. Once I did the wizard, I lost all of that. Having set up icinga before, I had a vague recollection that I needed to move everything into the zone instead of just conf.d, so I tried that. No luck. If I query the API directly as root, it shows no hosts. I am very confused. I added a node I was planning on monitoring to see if it would show up (config not shown above) and it also shows in the config verification (along with the master node) but not in the API:

curl -k -s -S -u root:mypasword 'https://localhost:5665/v1/objects/hosts' | jq
{
  "results": []
}

I’m very confused as to why the hosts defined in the zone are not showing in the API at all. Incorrectly set up, errors, fine, but this is simply… nothing. And as shown in the config verification above the host does exist according to the master:

Object 'myhostname' of type 'Host':
  % declared in '/etc/icinga2/zones.d/master/hosts.conf', lines 30:1-30:28
  * __name = "myhostname"
  * action_url = ""
  * address = "localhost"
    % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 36:3-36:23
  * address6 = "::1"
    % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 37:3-37:18
  * check_command = "hostalive"
    % = modified in '/etc/icinga2/zones.d/master/templates.conf', lines 19:3-19:29
  * check_interval = 60
    % = modified in '/etc/icinga2/zones.d/master/templates.conf', lines 16:3-16:21
  * check_period = ""
  * check_timeout = null
  * command_endpoint = ""
  * display_name = "myhostname"
  * enable_active_checks = true
  * enable_event_handler = true
  * enable_flapping = false
  * enable_notifications = true
  * enable_passive_checks = true
  * enable_perfdata = true
  * event_command = ""
  * flapping_ignore_states = null
  * flapping_threshold = 0
  * flapping_threshold_high = 30
  * flapping_threshold_low = 25
  * groups = [ ]
  * icon_image = ""
  * icon_image_alt = ""
  * max_check_attempts = 3
    % = modified in '/etc/icinga2/zones.d/master/templates.conf', lines 15:3-15:24
  * name = "myhostname"
    % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 31:3-31:25
  * notes = ""
  * notes_url = ""
  * package = "_etc"
  * retry_interval = 30
    % = modified in '/etc/icinga2/zones.d/master/templates.conf', lines 17:3-17:22
  * source_location
    * first_column = 1
    * first_line = 30
    * last_column = 28
    * last_line = 30
    * path = "/etc/icinga2/zones.d/master/hosts.conf"
  * templates = [ "myhostname", "generic-host" ]
    % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 30:1-30:28
    % = modified in '/etc/icinga2/zones.d/master/templates.conf', lines 14:1-14:28
  * type = "Host"
  * vars
    * agent_endpoint = "myhostname"
      % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 34:3-34:28
    * disks
      * disk
        % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 51:3-53:3
      * disk /
        % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 54:3-56:3
        * disk_partitions = "/"
    * http_vhosts
      * Icinga Web 2
        % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 46:3-48:3
        * http_uri = "/icingaweb2"
      * http
        % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 43:3-45:3
        * http_uri = "/"
    * notification
      * mail
        % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 59:3-62:3
        * groups = [ "icingaadmins" ]
    * os = "Linux"
      % = modified in '/etc/icinga2/zones.d/master/hosts.conf', lines 40:3-40:19
  * volatile = false
  * zone = "master"

I’m sure this is quite a silly error, but I really have no idea where it is.

1 Like

I have solved this on my own, but I’m honestly not sure how. I moved all config files out of the zones.d/master directory, into conf.d/, then turned on include_recursive conf.d/, which of course instantly threw errors due to zones. So I moved hosts back, and then using the config validation, moved files back one by one until the config was valid and I could reload Icinga. This left me with 4 files in conf.d/: api-users.conf (I understand this), then app.conf, apt.conf, and downtimes.conf. I moved the other three back as well, and the API is still functional. Hopefully someone is able to explain what happened here, but I am at a loss.

Hello @downingar ,
you pretty much figured out the main part for yourself, icinga2 node wizard is essentially a wrapper for several action. This includes:

  • Disabling the include of the /etc/icinga2/conf.d directory in general, since the command assumes, that you intend to build a “bigger” setup with several instances of icinga2. This essentially means commenting a line /etc/icinga2/icinga2.conf. Therefore configuration should now be put into the /etc/icinga2/zones.d directory (on the master instance and if you are not using the director)
  • Including api-users.conf in /etc/icinga2/conf.d contrary to the previous statement, because API-Access is only relevant/valid for this particular instance (again this should be a line /etc/icinga2/icinga2.conf)
  • Creating Endpoint and Zone objects for the master instance (see /etc/icinga2/zones.conf). An Endpoint is essentially a running icinga2 instance and a zone is an area for managing those (endpoints in a zone share states and duties automatically). For other objects (Hosts and Services for example) the zones determines which icinga2 instance is responsible for executing the checks.
  • Creating a CA (if you selected master in the node wizard) and related stuff

Now, your configuration for the icinga2 “infrastructure” (icinga2 instances communicating with each other) goes into /etc/icinga2/zones.conf and your monitoring configuration (what and how do you want to monitor goes into /etc/icinga2/zones.d.

If you, for example, want to monitor the icinga2 server itself you create a Host object in a file in /etc/icinga2/zones.d/master (master being the name of the zone) and the respective Service objects (directly or via appy rules).

If this works (check for file permission, this is a common mistake), the host should the show up in the api or via icinga2 object list.

1 Like

Well, that was the odd thing. The Host object was in icinga2 object list but not in the api. As best I can tell I simply moved the files back and forth and the API started seeing them. Further modification of the files hasn’t caused the issue to resurface, but I really and truly am at a loss for how it all happened.