lucasheld / uptime-kuma-api

A Python wrapper for the Uptime Kuma Socket.IO API
https://uptime-kuma-api.readthedocs.io
MIT License
272 stars 21 forks source link

Cannot update status page monitors #2

Closed GGServersDevelopment closed 2 years ago

GGServersDevelopment commented 2 years ago

Found an actual issue this time. I can't seem to update the monitors on a status page no matter what I do. I am on Uptime-Kuma Version: 1.17.1 using the latest git clones of your api repo & also tried the ansible module.

I get the following in the API:

result=api.save_status_page(slug="internal-status",monitors=["1","5","9","12"]) File "d:\Work\python\uptime\uptime_kuma_api\api.py", line 641, in save_status_page return self._call('saveStatusPage', data) File "d:\Work\python\uptime\uptime_kuma_api\api.py", line 408, in _call raise UptimeKumaException(r["msg"]) uptime_kuma_api.exceptions.UptimeKumaException: insert into monitor_group (group_id, monitor_id, weight) values (11, NULL, 1) - SQLITE_CONSTRAINT: NOT NULL constraint failed: monitor_group.monitor_id and the same in ansible:

[localhost]: FAILED! => {"changed": false, "msg": "Traceback (most recent call last):\n File \"/tmp/ansible_lucasheld.uptime_kuma.status_page_payload__6jfsqnw/ansible_lucasheld.uptime_kuma.status_page_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/status_page.py\", line 216, in main\n File \"/tmp/ansible_lucasheld.uptime_kuma.status_page_payload__6jfsqnw/ansible_lucasheld.uptime_kuma.status_page_payload.zip/ansible_collections/lucasheld/uptime_kuma/plugins/modules/status_page.py\", line 159, in run\n File \"/usr/local/lib/python3.6/site-packages/uptime_kuma_api/api.py\", line 641, in save_status_page\n return self._call('saveStatusPage', data)\n File \"/usr/local/lib/python3.6/site-packages/uptime_kuma_api/api.py\", line 408, in _call\n raise UptimeKumaException(r[\"msg\"])\nuptime_kuma_api.exceptions.UptimeKumaException: insert intomonitor_group(group_id,monitor_id,weight) values (10, NULL, 1) - SQLITE_CONSTRAINT: NOT NULL constraint failed: monitor_group.monitor_id\n"

It seems the monitor_id never gets set into the monitor group section, for some reason it seems it gets a null value at first which causes uptime-kuma to error.

There seems to be no null passed on, the data passed is "[{'name': 'Services', 'monitorList': ['36']}]", not sure if this is an issue with uptime kuma instead of the api though.

lucasheld commented 2 years ago

Thank you for this issue. It should be fixed now.

The monitors argument needs to be replace by publicGroupList. It's a list of groups. Each group has a name, a list of monitor ids and an optional weight to define the order of the groups.

This is an example value: https://github.com/lucasheld/uptime-kuma-api/blob/b2bacc9f8b2e15092da74d4f1d33b2cb20b0a527/tests/test_status_page.py#L17-L27