Icinga / icingaweb2-module-director

The Director aims to be your new favourite Icinga config deployment tool. Director is designed for those who want to automate their configuration deployment and those who want to grant their “point & click” users easy access to the configuration.
https://icinga.com/docs/director/latest
GNU General Public License v2.0
413 stars 203 forks source link

icingacli director service does not find apply services in v1.4.0 #1228

Open neubi4 opened 7 years ago

neubi4 commented 7 years ago

Expected Behavior

Given this service in the database:

> select * from icinga_service where object_name='disk-agent' limit 1\G
*************************** 1. row ***************************
                   id: 19
          object_name: disk-agent
          object_type: apply
             disabled: n
         display_name: disk
              host_id: NULL
       service_set_id: NULL
     check_command_id: 13
   max_check_attempts: NULL
      check_period_id: NULL
       check_interval: NULL
       retry_interval: NULL
        check_timeout: NULL
 enable_notifications: NULL
 enable_active_checks: NULL
enable_passive_checks: NULL
 enable_event_handler: NULL
      enable_flapping: NULL
      enable_perfdata: NULL
     event_command_id: NULL
   flapping_threshold: NULL
             volatile: NULL
              zone_id: NULL
  command_endpoint_id: NULL
                notes: NULL
            notes_url: NULL
           action_url: NULL
           icon_image: NULL
       icon_image_alt: NULL
            use_agent: NULL
            apply_for: NULL
    use_var_overrides: NULL
        assign_filter: host.vars.StandardMonitoredBy=%22Agent%22
   template_choice_id: NULL

$ icingacli director service exists disk-agent sould find the service disk-agent

Current Behavior

$ icingacli director service exists disk-agent
Service 'disk-agent' does not exist
$ icingacli director service show disk-agent
ERROR: Icinga\Exception\NotFoundError in /usr/share/icingaweb2/modules/director/library/Director/Data/Db/DbObject.php:600 with message: Failed to load icinga_service for host_id IS NULL AND service_set_id IS NULL AND object_name = 'disk-agent' AND object_type = 'template'

It does not find the apply service, because it looks like it now only searches for object_type = 'template'

Context

We are running icinga and icingaweb2 with director in containers. On container startup we run a script wich check if our default services are already in the database, if not create them, else we compare the database result to our given service and update it if necessary.

This check is done via icingacli director service exists $service_name. It worked fine in v1.3.2, but its now broken in v1.4.0 because it only looks for object_type template and does not find our apply services.

Sample service:

{  
   "assign_filter":"host.vars.StandardMonitoredBy=%22Agent%22",
   "check_command":"disk",
   "display_name":"disk",
   "imports":[  
      "some-import"
   ],
   "object_name":"disk-agent",
   "object_type":"apply"
}

Your Environment

neubi4 commented 7 years ago

After some debugging it is related to #1094. Any idea how we can fix this? Maybe there is the need for an new cli command like "applyrules".

log1-c commented 6 years ago

Problem still exists with Director v1.4.2 (issue present coming from 1.3.2 and 1.4.0) and Icinga2 2.8 on Ubuntu 16.04.3. IcingaWeb2 Versions are 2.5 on one system and 2.4.2 on another.

Also you can't access services via the Directors activity log. The diff log is displayed normally, but if you click on the created service you get the following error message and stacktrace:

Failed to load icinga_service for host_id IS NULL AND service_set_id IS NULL AND object_name = 'Hardware-Status' AND object_type = 'template'

0 /usr/share/icingaweb2/modules/director/library/Director/Data/Db/DbObject.php(1101): Icinga\Module\Director\Data\Db\DbObject->loadFromDb()

1 /usr/share/icingaweb2/modules/director/application/controllers/ServiceController.php(252): Icinga\Module\Director\Data\Db\DbObject::load(Array, Object(Icinga\Module\Director\Db))

2 /usr/share/icingaweb2/modules/director/library/Director/Web/Controller/ObjectController.php(328): Icinga\Module\Director\Controllers\ServiceController->loadObject()

3 /usr/share/icingaweb2/modules/director/library/Director/Web/Controller/ObjectController.php(62): Icinga\Module\Director\Web\Controller\ObjectController->eventuallyLoadObject()

4 /usr/share/icingaweb2/modules/director/application/controllers/ServiceController.php(43): Icinga\Module\Director\Web\Controller\ObjectController->init()

5 /usr/share/php/Icinga/Web/Controller/ActionController.php(152): Icinga\Module\Director\Controllers\ServiceController->init()

6 /usr/share/php/Icinga/Web/Controller/Dispatcher.php(59): Icinga\Web\Controller\ActionController->__construct(Object(Icinga\Web\Request), Object(Icinga\Web\Response), Array)

7 /usr/share/icingaweb2/library/vendor/Zend/Controller/Front.php(937): Icinga\Web\Controller\Dispatcher->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))

8 /usr/share/php/Icinga/Application/Web.php(407): Zend_Controller_Front->dispatch(Object(Icinga\Web\Request), Object(Icinga\Web\Response))

9 /usr/share/php/Icinga/Application/webrouter.php(104): Icinga\Application\Web->dispatch()

10 /usr/share/icingaweb2/public/index.php(4): require_once('/usr/share/php/...')

11 {main}

icingacli director service exists Hardware-Status Service 'Hardware-Status' does not exist

icingacli director service show Hardware-Status ERROR: Icinga\Exception\NotFoundError in /usr/share/icingaweb2/modules/director/library/Director/Data/Db/DbObject.php:610 with message: Failed to load icinga_service for host_id IS NULL AND service_set_id IS NULL AND object_name = 'Hardware-Status' AND object_type = 'template'

log1-c commented 6 years ago

With IcingaWeb2 2.5.0 the errors/the problem disappeared after applying the schema upgrade to 2.5.0 Under IcingaWEb2 2.4.2 the issue is still present

pulord commented 6 years ago

the issue is still present ERROR: Icinga\Exception\NotFoundError in /usr/local/share/icingaweb2/modules/director/library/Director/Data/Db/DbObject.php:610 with message: Failed to load icinga_service for host_id IS NULL AND service_set_id IS NULL AND object_name = 'check-fund-rating-10m-service' AND object_type = 'template'

icinga2: v2.8.1 director: v1.4.3

@Thomas-Gelf

dskachan commented 5 years ago

Any news on this topic? The problem exists using director API as well: on my attempt to GET my Apply service:

json response: {'error': \"Failed to load icinga_service for host_id IS NULL AND service_set_id IS NULL AND object_name = 'apt_apply_api' AND object_type = 'template'\"}

icinga2: v.2.6.2 director: v.1.6.0

santuari commented 5 years ago

It seems that you need to define the hostname as follow: icingacli director service exists --host <host_name> <service_name> I guess that the icingacli command is not very clear ;)

maggu commented 2 years ago

@santuari Thanks!