https://github.com/morph027/checkmk-rest-python
Checkmk REST api client libraries for python
https://github.com/morph027/checkmk-rest-python
Last synced: 2 months ago
JSON representation
Checkmk REST api client libraries for python
- Host: GitHub
- URL: https://github.com/morph027/checkmk-rest-python
- Owner: morph027
- License: mit
- Created: 2026-03-30T14:56:32.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-03-30T16:49:50.000Z (2 months ago)
- Last Synced: 2026-04-03T01:43:24.492Z (2 months ago)
- Language: Python
- Size: 545 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python Checkmk REST API client
Created from builtin openapi spec (available at `//check_mk/api/1.0/openapi-swagger-ui.yaml`) using [openapi-python-client](https://github.com/openapi-generators/openapi-python-client).
## Usage Example
* Authenticate
* Start Discovery (default mode: refresh = FIX_ALL)
* Apply pending changes
```python
from checkmk_rest_python.api.activate_changes import (
cmk_gui_openapi_endpoints_activate_changes_activate_changes as activate,
)
from checkmk_rest_python.api.activate_changes import (
cmk_gui_openapi_endpoints_activate_changes_list_pending_changes as list_pending,
)
from checkmk_rest_python.api.service_discovery import (
cmk_gui_openapi_endpoints_service_discovery_execute_service_discovery as execute_discovery,
)
from checkmk_rest_python.api.service_discovery import (
cmk_gui_openapi_endpoints_service_discovery_service_discovery_run_wait_for_completion as wait_discovery,
)
from checkmk_rest_python.client import AuthenticatedClient
from checkmk_rest_python.models.activate_changes import ActivateChanges
from checkmk_rest_python.models.discover_services import DiscoverServices
def main():
client = AuthenticatedClient(
base_url="",
token=" ",
)
discover = execute_discovery.sync_detailed(
client=client,
body=DiscoverServices(host_name=""),
content_type="application/json",
)
wait_discovery.sync_detailed(host_name="", client=client)
pending = list_pending.sync_detailed(client=client)
# etag is messed up currently as stringed string
# like '"..........-gzip"' with '-gzip' suffix
etag = pending.headers.get("ETag", "").strip('"').rstrip("-gzip")
activate = activate.sync_detailed(
client=client,
body=ActivateChanges(redirect=False, force_foreign_changes=False),
if_match=etag,
content_type="application/json",
)
main()
```
Also works async:
```python
import asyncio
async def main():
client = AuthenticatedClient(
base_url="",
token=" ",
)
discover = await execute_discovery.asyncio_detailed(
client=client,
body=DiscoverServices(host_name=""),
content_type="application/json",
)
await wait_discovery.asyncio_detailed(host_name="", client=client)
pending = await list_pending.asyncio_detailed(client=client)
etag = pending.headers.get("ETag", "").strip('"').rstrip("-gzip")
result = await activate.asyncio_detailed(
client=client,
body=ActivateChanges(redirect=False, force_foreign_changes=False),
if_match=etag,
content_type="application/json",
)
asyncio.run(main())
```