Using api for removing service objects

Hello,

We are using icingaweb2 director for managing our icinga2 environment.
Beside sync jobs, manual editing, we are using the director api for a small subset of tasks we are already using the director api.
Now we have the following situation:

We have a lot of hosts with a lot of direct attached services.
Now we want to remove some (a lot) of these services.

using the script example “curlhelper” from icingaweb2 director api (https://icinga.com/docs/director/latest/doc/70-REST-API/)
with the following query i get the whole list of service objects:
./curlhelper.sh GET ‘director/services’

{ "objects": [ {
"check_period": "24x7",
"display_name": "check1",
"groups": [
    "standard_nrpe_checks"
],
"host": "server1",
"imports": [
    "svc_nrpe_check_generic"
],
"object_name": "check1",
"object_type": "object",
"vars": {
    "nrpe_command": "cmd1",
    "nrpe_timeout": "60"
}
}, {
"check_period": "24x7",
"display_name": "check2",
"groups": [
    "standard_nrpe_checks"
],
"host": "server2",
"imports": [
    "svc_nrpe_check_generic"
],
"object_name": "check2",
"object_type": "object",
"vars": {
    "nrpe_command": "cmd2",
    "nrpe_timeout": "60"
}
...
}] }

I’m looking for a query to get a list filtered by “object_name” and “host” or something else…
trying:
./curlhelper.sh GET ‘director/service?object_name=check1’
gives

{
    "error": "Object is required"
}

When I try to use “name” instead of “object_name” I get the following answer:
./curlhelper.sh GET “director/service?name=check1”

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

but I can’t give the “object_type=object” as additional parameter. It will not recognized:
./curlhelper.sh GET “director/service?name=check1&properties=all&object_type=object”

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

I don’t know howto get the wanted list and I also don’t kow howto write the query to remove these kind of “direct attached” services.

Can someone lead me into the right direction, please?

I really don’t want to remove over 1000 services manually in director webinterface

Thank you and best regards

Thomas

Hi Thomas,

as of this writing there is no granular filtering available for director/services, but you can provide any string via q=, this will execute a wildcard search on both host and service names. It’s has the same as the search box on top of the services list in the UI.

In your second attempt you’re using director/service, please note that this is a different API endpoint (no trailing s) and meant to deal with single service objects. This is the endpoint you should use to create, modify or delete single service objects. What you’re missing in your examples is the related host name. It should read: director/service?name=SomeService&host=host.example.com.

Cheers,
Thomas

1 Like

NB: The Services Table in the frontend offers the multiselect feature, so you can use SHIFT (or CTRL)-Click to select a bunch of services to tweak or delete at once. However, there you’ll face a URL-length limitation when selecting too many at once (probably 50-200, depends on various factors).

Hello,

thanks for your answer.

the hint with “q=” sounded really helpful, but it doesn’t worked as excepted:

As far as I understand your comment, adding “?q=somestring” should give only objects back, where “somestring” is forun in service name or in host name. Doing the query on “director/services” only objects with “object_name=somestring” oder “host=somestring” should be lietd as result.
But this doesn’t work:

./curlhelper.sh GET 'director/services?q=rhnsd'|grep -e "host\"" -e "object_name"

Gives back a lot of object where the wanted string is not in object_name or in host

What I’m doing wrong?

Thank you and best regards

Thomas