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
414 stars 202 forks source link

ServiceApplyRules API response not working as expected #2652

Open mskrgulja opened 1 year ago

mskrgulja commented 1 year ago

Expected Behavior

Get ID for each Service Apply Rule

for example: curl -k -s -S -i -u ':' -H 'Accept: application/json' 'https:/icingahost/icingaweb2/director/ServiceApplyRules' should return all service apply rules with internal ID's

Per official documentation https://icinga.com/docs/icinga-director/latest/doc/70-REST-API/#service-apply-rules this should be possible:

a dedicated REST API endpoint director/serviceapplyrules ships all Service Apply Rules combined with their internal ID. This ID can then be used to modify or delete a Rule via director/service.

Current Behavior

The service apply rules are fetched but without internal ID. Example response: { "assign_filter": "host.vars.metricbeat_host=true", "check_command": "check_beat_stats", "fields": [], "imports": [ "basic-service" ], "object_name": "metricbeat Stats", "object_type": "apply", "vars": { "beat_file_handles_percent_critical": "0:90", "beat_file_handles_percent_warn": "0:85", "beat_host": "$host.vars.metricbeat_host$", "beat_module_errors_percent_critical": "0:10", "beat_module_errors_percent_warn": "0:1", "beat_output_errors_percent_critical": "0:10", "beat_output_errors_percent_warn": "0:1", "beat_pipeline_errors_absolute_warn": "0:0", "beat_pipeline_errors_percent_critical": "0:10", "beat_port": 20860 } There is no ID

Steps to Reproduce (for bugs)

Make a request to the API endpoint director/serviceapplyrules

Your Environment

mskrgulja commented 1 year ago

The working solution, for me was to set $resolveIds = true. Here is the patch if somebody needs it:

*** /usr/share/icingaweb2/modules/director/library/Director/Objects/IcingaObject.php
--- /usr/share/icingaweb2/modules/director/library/Director/Objects/IcingaObject.php
***************
*** 2845,2851 ****
          $skipDefaults = false,
          array $chosenProperties = null,
          $resolveIds = true,
!         $keepId = false
      ) {
          $props = [];

--- 2845,2851 ----
          $skipDefaults = false,
          array $chosenProperties = null,
          $resolveIds = true,
!         $keepId = true
      ) {
          $props = [];