Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better document how to match (single) objects in API requests #9188

Open
julianbrost opened this issue Jan 21, 2022 · 3 comments
Open

Better document how to match (single) objects in API requests #9188

julianbrost opened this issue Jan 21, 2022 · 3 comments
Labels
area/api REST API area/documentation End-user or developer help good first issue Good for newcomers

Comments

@julianbrost
Copy link
Contributor

Our API documentation uses filters in most places, even when only filtering for a single object with a known name:

But there is a better method for this specific case, as hidden in another example at https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#execute-command: "type": "Service", "service": "agent!custom_service"

This is obviously the better choice for selecting a single object as (1) Icinga does not have to evaluate the filter for all objects of that type but can rather directly get the desired object and (2) does not need nested quotes that have to escaped, which is especially annoying when doing API requests by hand.

I think it would be a great improvement to rewrite the API docs such that operating on a single object is the default and filters for matching multiple objects are treated as an advanced option that you only use if you actually need that functionality.

@julianbrost julianbrost added area/documentation End-user or developer help area/api REST API labels Jan 21, 2022
@julianbrost
Copy link
Contributor Author

TIL by randomly finding this in the source: it's also possible to match multiple objects by name:
"type": "Host", "hosts": ["agent-1", "agent-2"]

@Al2Klimov Al2Klimov added the good first issue Good for newcomers label Feb 22, 2022
@julianbrost
Copy link
Contributor Author

TIL: When using host(s) and service(s), you don't even need type. You can even mix and match these (not sure if that's something we should suggest to do though). But right now, this works: "service": "master-1!no-active-checks", "hosts": ["agent-1", "agent-2"], "host": "master-1" (this affects all 4 objects)

@julianbrost
Copy link
Contributor Author

What I just wrote in #9429 (comment) is also relevant here:

[...], it took me until today to understand how you're supposed to read the documentation: everything in the section https://icinga.com/docs/icinga-2/latest/doc/12-icinga2-api/#filters affects everything in the API even though the simple filters are only used for /v1/objects in the examples and not for /v1/actions, they actually work for both.

Probably the most confusing thing here is that "filter" in "In addition to these parameters a filter must be provided." does not refer to the filter attribute (query string or JSON) but rather means that you have to use any of the filtering methods described in the linked section.

So that should probably also be incorporated into a fix for this issue (maybe this will be done by the author of #9429, so if someone wants to address this issue, check if there was any progress in that PR first).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api REST API area/documentation End-user or developer help good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants