uptime-kuma-api/README.md

71 lines
2 KiB
Markdown
Raw Permalink Normal View History

2022-07-10 21:57:22 +02:00
# uptime-kuma-api
2022-08-03 22:19:37 +02:00
A wrapper for the Uptime Kuma Socket.IO API
2022-07-10 21:57:22 +02:00
---
2022-08-04 12:08:15 +02:00
uptime-kuma-api is a Python wrapper for the [Uptime Kuma](https://github.com/louislam/uptime-kuma) Socket.IO API.
2022-07-10 21:57:22 +02:00
2022-07-10 22:54:04 +02:00
This package was developed to configure Uptime Kuma with Ansible. The Ansible collection can be found at https://github.com/lucasheld/ansible-uptime-kuma.
Python version 3.7+ is required.
2022-08-03 11:56:02 +02:00
Supported Uptime Kuma versions:
2023-05-25 21:35:10 +02:00
| Uptime Kuma | uptime-kuma-api |
|-----------------|-----------------|
2023-09-26 22:32:04 +02:00
| 1.21.3 - 1.23.2 | 1.0.0 - 1.2.1 |
2023-05-25 21:35:10 +02:00
| 1.17.0 - 1.21.2 | 0.1.0 - 0.13.0 |
2022-09-07 13:03:10 +02:00
2022-07-10 21:57:22 +02:00
Installation
---
2022-08-04 12:08:15 +02:00
uptime-kuma-api is available on the [Python Package Index (PyPI)](https://pypi.org/project/uptime-kuma-api/).
2022-07-10 21:57:22 +02:00
You can install it using pip:
```
2022-08-03 22:19:37 +02:00
pip install uptime-kuma-api
2022-07-10 21:57:22 +02:00
```
2022-12-16 22:10:52 +01:00
Documentation
---
The API Reference is available on [Read the Docs](https://uptime-kuma-api.readthedocs.io).
2023-05-02 20:43:52 +02:00
Example
2022-07-10 21:57:22 +02:00
---
Once you have installed the python package, you can use it to communicate with an Uptime Kuma instance.
2022-08-04 20:16:51 +02:00
To do so, import `UptimeKumaApi` from the library and specify the Uptime Kuma server url (e.g. 'http://127.0.0.1:3001'), username and password to initialize the connection.
2022-07-10 21:57:22 +02:00
```python
2022-08-04 20:16:51 +02:00
>>> from uptime_kuma_api import UptimeKumaApi, MonitorType
2022-07-10 21:58:42 +02:00
>>> api = UptimeKumaApi('INSERT_URL')
>>> api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
2022-07-10 21:57:22 +02:00
```
Now you can call one of the existing methods of the instance. For example create a new monitor:
```python
2022-08-04 20:16:51 +02:00
>>> result = api.add_monitor(type=MonitorType.HTTP, name="Google", url="https://google.com")
2022-07-10 21:57:22 +02:00
>>> print(result)
2022-08-03 11:56:02 +02:00
{'msg': 'Added Successfully.', 'monitorId': 1}
2022-07-10 21:57:22 +02:00
```
2022-08-04 20:16:51 +02:00
At the end, the connection to the API must be disconnected so that the program does not block.
```python
>>> api.disconnect()
```
2023-05-02 20:43:52 +02:00
With a context manager, the disconnect method is called automatically:
```python
from uptime_kuma_api import UptimeKumaApi
with UptimeKumaApi('INSERT_URL') as api:
api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
api.add_monitor(
type=MonitorType.HTTP,
name="Google",
url="https://google.com"
)
```