charlie-haley / omada_exporter

Prometheus Exporter for TP-Link Omada Controller SDN.
MIT License
87 stars 14 forks source link

Omada Open API Support #81

Open charlie-haley opened 11 months ago

charlie-haley commented 11 months ago

Discussed in https://github.com/charlie-haley/omada_exporter/discussions/80

Originally posted by **codersaur** September 22, 2023 I see in v5.12 on the Omada Controller Open API is now supported. _Open API: Omada Controller now supports Open API integration. You can access it through Global view > Settings > Platform Integration, which allows you to utilize the REST API of most Controller services. This feature enables you to develop custom applications, embed APIs, or combine your own applications._ Is this relevant for omada_exporter, and if so, is there a plan to migrate to using it?
charlie-haley commented 11 months ago

When migrating to using the official API integration, we should document which versions of the exporter are supported. (e.g exporter v0.11.0 needs controller version v5.12+)

michelheusschen commented 10 months ago

This would be nice to have. I tried making a client with the OpenAPI schema (http://omada/v3/api-docs/All) using openapi-generator and the results are a bit mixed.

It's possible to autogenerate a Go client, but there are some issues:

  1. The OpenAPI schema has invalid syntax
  2. OAuth implementation is non-standard
  3. API calls are limited to 1000 per day, with no obvious way to increase that

For 1 and 2 there are relatively straightforward workarounds, but 3 might be the biggest problem. Making one request every 15 seconds already means 5760 requests per day. Maybe I missed a setting to increase or remove this limit, but otherwise you'd need to create multiple "applications" to bypass the limit. And yes the API call limit is enforced unfortunately:

{"errorCode":-7132,"msg":"Our server is receiving too many requests now. Please try again later."}
charlie-haley commented 10 months ago

There's some talk around the limits here https://community.tp-link.com/en/business/forum/topic/623376?replyId=1256526

this limitation will be removed in Controller 5.13, I wonder if this means the API calls/day limit will be lifted?

charlie-haley commented 10 months ago

So, I also attempted to generate from the Open API schema and a lot of the spec was wrong/invalid. I pulled the JSON down and fixed all the errors, it still doesn't solve the API request limit but it at least generates a Go package

openapi.json