Querying Service Objects with Custom Variable via Icinga Director's REST API

  • Director version: 2.12.1
  • Icinga Web 2 version and modules:
|Icinga Web 2 Version |2.12.1|
|Git commit |cd2daeb2cb8537c633d343a29eb76c54cd2ebbf2|
|PHP Version |7.4.33|
|Git commit date |2023-11-15|

Hi Icinga Community,

I’m integrating Icinga Director with our systems and need help using the REST API to find service objects with a specific custom variable (env = “production”). Despite authenticating and executing basic GET requests successfully, my attempts to filter service objects by custom variables have hit a snag.

Attempts like GET director/service?filters=vars.env=prod and director/service?vars.env=production result in:

{
    "error": "Object is required"
}

My goals are:

  1. Correctly query service objects with a specific custom variable value.
  2. Understand the proper API endpoint and request format for this action.

Insights or documentation references would be hugely appreciated. Thanks!

Simple answer it doesn’t work.
https://icinga.com/docs/icinga-director/latest/doc/70-REST-API/

What I do so far:

GET /icingaweb2/director/hosts
GET /icingaweb2/director/services

this returns a json with all objects which I can iterate over in python and make a decision in my code.

if you need multiple hosts or services that start with the same name you can filter with:

GET /icingaweb2/director/hosts?q=nodeA
GET /icingaweb2/director/services?q=serviceA

and you can also query services from a specific host:

GET /icingaweb2/director/services?host=node123

1 Like