feat: add support for uptime kuma 1.21.2
This commit is contained in:
parent
be537a14d2
commit
d7f033030e
6 changed files with 152 additions and 139 deletions
|
@ -8,7 +8,7 @@ This package was developed to configure Uptime Kuma with Ansible. The Ansible co
|
|||
|
||||
Python version 3.6+ is required.
|
||||
|
||||
Supported Uptime Kuma versions: 1.17.0 - 1.21.1
|
||||
Supported Uptime Kuma versions: 1.17.0 - 1.21.2
|
||||
|
||||
Installation
|
||||
---
|
||||
|
|
|
@ -5,7 +5,7 @@ if [ $version ]
|
|||
then
|
||||
versions=("$version")
|
||||
else
|
||||
versions=(1.21.1 1.20.2 1.19.6 1.18.5 1.17.1)
|
||||
versions=(1.21.2 1.21.1 1.20.2 1.19.6 1.18.5 1.17.1)
|
||||
fi
|
||||
|
||||
for version in ${versions[*]}
|
||||
|
|
|
@ -24,20 +24,15 @@ class TestMaintenance(UptimeKumaTestCase):
|
|||
"2022-12-27 22:36:00",
|
||||
"2022-12-29 22:36:00"
|
||||
],
|
||||
"timeRange": [
|
||||
{
|
||||
"hours": 2,
|
||||
"minutes": 0
|
||||
},
|
||||
{
|
||||
"hours": 3,
|
||||
"minutes": 0
|
||||
}
|
||||
],
|
||||
"weekdays": [],
|
||||
"daysOfMonth": []
|
||||
}
|
||||
|
||||
if parse_version(self.api.version) >= parse_version("1.21.2"):
|
||||
expected_maintenance.update({
|
||||
"timezone": "Europe/Berlin"
|
||||
})
|
||||
|
||||
# add maintenance
|
||||
r = self.api.add_maintenance(**expected_maintenance)
|
||||
self.assertEqual(r["msg"], "Added Successfully.")
|
||||
|
@ -119,18 +114,6 @@ class TestMaintenance(UptimeKumaTestCase):
|
|||
"dateRange": [
|
||||
"2022-12-27 00:00:00"
|
||||
],
|
||||
"timeRange": [
|
||||
{
|
||||
"hours": 2,
|
||||
"minutes": 0,
|
||||
"seconds": 0
|
||||
},
|
||||
{
|
||||
"hours": 3,
|
||||
"minutes": 0,
|
||||
"seconds": 0
|
||||
}
|
||||
],
|
||||
"weekdays": [],
|
||||
"daysOfMonth": []
|
||||
}
|
||||
|
@ -147,16 +130,6 @@ class TestMaintenance(UptimeKumaTestCase):
|
|||
"2022-12-27 22:36:00",
|
||||
"2022-12-29 22:36:00"
|
||||
],
|
||||
"timeRange": [
|
||||
{
|
||||
"hours": 2,
|
||||
"minutes": 0
|
||||
},
|
||||
{
|
||||
"hours": 3,
|
||||
"minutes": 0
|
||||
}
|
||||
],
|
||||
"weekdays": [],
|
||||
"daysOfMonth": []
|
||||
}
|
||||
|
@ -246,12 +219,33 @@ class TestMaintenance(UptimeKumaTestCase):
|
|||
10,
|
||||
20,
|
||||
30,
|
||||
"lastDay4",
|
||||
"lastDay2"
|
||||
"lastDay1"
|
||||
]
|
||||
}
|
||||
self.do_test_maintenance_strategy(expected_maintenance)
|
||||
|
||||
def test_maintenance_strategy_cron(self):
|
||||
if parse_version(self.api.version) < parse_version("1.21.2"):
|
||||
self.skipTest("Unsupported in this Uptime Kuma version")
|
||||
|
||||
expected_maintenance = {
|
||||
"title": "test",
|
||||
"description": "test",
|
||||
"strategy": MaintenanceStrategy.CRON,
|
||||
"active": True,
|
||||
"intervalDay": 1,
|
||||
"dateRange": [
|
||||
"2022-12-27 22:37:00",
|
||||
"2022-12-31 22:37:00"
|
||||
],
|
||||
"weekdays": [],
|
||||
"daysOfMonth": [],
|
||||
"cron": "50 5 * * *",
|
||||
"durationMinutes": 120,
|
||||
"timezone": "Europe/Berlin"
|
||||
}
|
||||
self.do_test_maintenance_strategy(expected_maintenance)
|
||||
|
||||
def do_test_maintenance_strategy(self, expected_maintenance):
|
||||
# add maintenance
|
||||
r = self.api.add_maintenance(**expected_maintenance)
|
||||
|
|
|
@ -184,49 +184,6 @@ def _build_docker_host_data(
|
|||
return data
|
||||
|
||||
|
||||
def _build_maintenance_data(
|
||||
title: str,
|
||||
strategy: MaintenanceStrategy,
|
||||
active: bool = True,
|
||||
description: str = "",
|
||||
dateRange: list = None,
|
||||
intervalDay: int = 1,
|
||||
weekdays: list = None,
|
||||
daysOfMonth: list = None,
|
||||
timeRange: list = None
|
||||
) -> dict:
|
||||
if not dateRange:
|
||||
dateRange = [
|
||||
datetime.date.today().strftime("%Y-%m-%d 00:00:00")
|
||||
]
|
||||
if not timeRange:
|
||||
timeRange = [
|
||||
{
|
||||
"hours": 2,
|
||||
"minutes": 0,
|
||||
}, {
|
||||
"hours": 3,
|
||||
"minutes": 0,
|
||||
}
|
||||
]
|
||||
if not weekdays:
|
||||
weekdays = []
|
||||
if not daysOfMonth:
|
||||
daysOfMonth = []
|
||||
data = {
|
||||
"title": title,
|
||||
"active": active,
|
||||
"intervalDay": intervalDay,
|
||||
"dateRange": dateRange,
|
||||
"description": description,
|
||||
"strategy": strategy,
|
||||
"weekdays": weekdays,
|
||||
"daysOfMonth": daysOfMonth,
|
||||
"timeRange": timeRange
|
||||
}
|
||||
return data
|
||||
|
||||
|
||||
def _build_tag_data(
|
||||
name: str,
|
||||
color: str
|
||||
|
@ -611,7 +568,7 @@ class UptimeKumaApi(object):
|
|||
interval: int = 60,
|
||||
retryInterval: int = 60,
|
||||
resendInterval: int = 0,
|
||||
maxretries: int = 0,
|
||||
maxretries: int = 1,
|
||||
upsideDown: bool = False,
|
||||
notificationIDList: list = None,
|
||||
httpBodyEncoding: str = "json",
|
||||
|
@ -686,6 +643,10 @@ class UptimeKumaApi(object):
|
|||
# GAMEDIG
|
||||
game: str = None
|
||||
) -> dict:
|
||||
# https://github.com/louislam/uptime-kuma/compare/1.21.1...1.21.2#diff-f672603317047f3e6f27b0d7a44f6f244b7dbb5d0d0a85f1059a6b0bc2cb9aa0L910
|
||||
if parse_version(self.version) < parse_version("1.21.2"):
|
||||
maxretries = 0
|
||||
|
||||
data = {
|
||||
"type": type,
|
||||
"name": name,
|
||||
|
@ -828,6 +789,58 @@ class UptimeKumaApi(object):
|
|||
|
||||
return data
|
||||
|
||||
def _build_maintenance_data(
|
||||
self,
|
||||
title: str,
|
||||
strategy: MaintenanceStrategy,
|
||||
active: bool = True,
|
||||
description: str = "",
|
||||
dateRange: list = None,
|
||||
intervalDay: int = 1,
|
||||
weekdays: list = None,
|
||||
daysOfMonth: list = None,
|
||||
timeRange: list = None,
|
||||
cron: str = "30 3 * * *",
|
||||
durationMinutes: int = 60,
|
||||
timezone: str = None
|
||||
) -> dict:
|
||||
if not dateRange:
|
||||
dateRange = [
|
||||
datetime.date.today().strftime("%Y-%m-%d 00:00:00")
|
||||
]
|
||||
if not timeRange:
|
||||
timeRange = [
|
||||
{
|
||||
"hours": 2,
|
||||
"minutes": 0,
|
||||
}, {
|
||||
"hours": 3,
|
||||
"minutes": 0,
|
||||
}
|
||||
]
|
||||
if not weekdays:
|
||||
weekdays = []
|
||||
if not daysOfMonth:
|
||||
daysOfMonth = []
|
||||
data = {
|
||||
"title": title,
|
||||
"active": active,
|
||||
"intervalDay": intervalDay,
|
||||
"dateRange": dateRange,
|
||||
"description": description,
|
||||
"strategy": strategy,
|
||||
"weekdays": weekdays,
|
||||
"daysOfMonth": daysOfMonth,
|
||||
"timeRange": timeRange
|
||||
}
|
||||
if parse_version(self.version) >= parse_version("1.21.2"):
|
||||
data.update({
|
||||
"cron": cron,
|
||||
"durationMinutes": durationMinutes,
|
||||
"timezone": timezone,
|
||||
})
|
||||
return data
|
||||
|
||||
# monitor
|
||||
|
||||
def get_monitors(self) -> list:
|
||||
|
@ -875,7 +888,7 @@ class UptimeKumaApi(object):
|
|||
'keyword': None,
|
||||
'maintenance': False,
|
||||
'maxredirects': 10,
|
||||
'maxretries': 0,
|
||||
'maxretries': 1,
|
||||
'method': 'GET',
|
||||
'mqttPassword': None,
|
||||
'mqttSuccessMessage': None,
|
||||
|
@ -957,7 +970,7 @@ class UptimeKumaApi(object):
|
|||
'keyword': None,
|
||||
'maintenance': False,
|
||||
'maxredirects': 10,
|
||||
'maxretries': 0,
|
||||
'maxretries': 1,
|
||||
'method': 'GET',
|
||||
'mqttPassword': None,
|
||||
'mqttSuccessMessage': None,
|
||||
|
@ -2838,29 +2851,27 @@ class UptimeKumaApi(object):
|
|||
],
|
||||
"timeRange": [
|
||||
{
|
||||
"hours": 2,
|
||||
"minutes": 0,
|
||||
"seconds": 0
|
||||
"hours": 0,
|
||||
"minutes": 0
|
||||
},
|
||||
{
|
||||
"hours": 3,
|
||||
"minutes": 0,
|
||||
"seconds": 0
|
||||
"hours": 0,
|
||||
"minutes": 0
|
||||
}
|
||||
],
|
||||
"weekdays": [],
|
||||
"daysOfMonth": [],
|
||||
"timeslotList": [
|
||||
{
|
||||
"id": 1,
|
||||
"startDate": "2022-12-27 14:39:00",
|
||||
"endDate": "2022-12-30 14:39:00",
|
||||
"startDateServerTimezone": "2022-12-27 15:39",
|
||||
"endDateServerTimezone": "2022-12-30 15:39",
|
||||
"serverTimezoneOffset": "+01:00"
|
||||
"startDate": "2022-12-27 22:36:00",
|
||||
"endDate": "2022-12-29 22:36:00"
|
||||
}
|
||||
],
|
||||
"status": "under-maintenance"
|
||||
"cron": "",
|
||||
"durationMinutes": null,
|
||||
"timezone": "Europe/Berlin",
|
||||
"timezoneOffset": "+02:00",
|
||||
"status": "ended"
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
@ -2891,29 +2902,28 @@ class UptimeKumaApi(object):
|
|||
],
|
||||
"timeRange": [
|
||||
{
|
||||
"hours": 2,
|
||||
"minutes": 0,
|
||||
"seconds": 0
|
||||
"hours": 0,
|
||||
"minutes": 0
|
||||
},
|
||||
{
|
||||
"hours": 3,
|
||||
"minutes": 0,
|
||||
"seconds": 0
|
||||
"hours": 0,
|
||||
"minutes": 0
|
||||
}
|
||||
],
|
||||
"weekdays": [],
|
||||
"daysOfMonth": [],
|
||||
"timeslotList": [
|
||||
{
|
||||
"id": 1,
|
||||
"startDate": "2022-12-27 14:39:00",
|
||||
"endDate": "2022-12-30 14:39:00",
|
||||
"startDateServerTimezone": "2022-12-27 15:39",
|
||||
"endDateServerTimezone": "2022-12-30 15:39",
|
||||
"serverTimezoneOffset": "+01:00"
|
||||
"startDate": "2022-12-27 22:36:00",
|
||||
"endDate": "2022-12-29 22:36:00"
|
||||
}
|
||||
],
|
||||
"status": "under-maintenance"
|
||||
"cron": null,
|
||||
"duration": null,
|
||||
"durationMinutes": 0,
|
||||
"timezone": "Europe/Berlin",
|
||||
"timezoneOffset": "+02:00",
|
||||
"status": "ended"
|
||||
}
|
||||
"""
|
||||
return self._call('getMaintenance', id_)["maintenance"]
|
||||
|
@ -2938,18 +2948,6 @@ class UptimeKumaApi(object):
|
|||
... dateRange=[
|
||||
... "2022-12-27 00:00:00"
|
||||
... ],
|
||||
... timeRange=[
|
||||
... {
|
||||
... "hours": 2,
|
||||
... "minutes": 0,
|
||||
... "seconds": 0
|
||||
... },
|
||||
... {
|
||||
... "hours": 3,
|
||||
... "minutes": 0,
|
||||
... "seconds": 0
|
||||
... }
|
||||
... ],
|
||||
... weekdays=[],
|
||||
... daysOfMonth=[]
|
||||
... )
|
||||
|
@ -2970,20 +2968,9 @@ class UptimeKumaApi(object):
|
|||
... "2022-12-27 22:36:00",
|
||||
... "2022-12-29 22:36:00"
|
||||
... ],
|
||||
... timeRange=[
|
||||
... {
|
||||
... "hours": 2,
|
||||
... "minutes": 0,
|
||||
... "seconds": 0
|
||||
... },
|
||||
... {
|
||||
... "hours": 3,
|
||||
... "minutes": 0,
|
||||
... "seconds": 0
|
||||
... }
|
||||
... ],
|
||||
... weekdays=[],
|
||||
... daysOfMonth=[]
|
||||
... daysOfMonth=[],
|
||||
... timezone="Europe/Berlin"
|
||||
... )
|
||||
{
|
||||
"msg": "Added Successfully.",
|
||||
|
@ -3015,7 +3002,8 @@ class UptimeKumaApi(object):
|
|||
... }
|
||||
... ],
|
||||
... weekdays=[],
|
||||
... daysOfMonth=[]
|
||||
... daysOfMonth=[],
|
||||
... timezone="Europe/Berlin"
|
||||
... )
|
||||
{
|
||||
"msg": "Added Successfully.",
|
||||
|
@ -3052,7 +3040,8 @@ class UptimeKumaApi(object):
|
|||
... 5,
|
||||
... 0
|
||||
... ],
|
||||
... daysOfMonth=[]
|
||||
... daysOfMonth=[],
|
||||
... timezone="Europe/Berlin"
|
||||
... )
|
||||
{
|
||||
"msg": "Added Successfully.",
|
||||
|
@ -3089,15 +3078,39 @@ class UptimeKumaApi(object):
|
|||
... 10,
|
||||
... 20,
|
||||
... 30,
|
||||
... "lastDay2"
|
||||
... ]
|
||||
... "lastDay1"
|
||||
... ],
|
||||
... timezone="Europe/Berlin"
|
||||
... )
|
||||
{
|
||||
"msg": "Added Successfully.",
|
||||
"maintenanceID": 1
|
||||
}
|
||||
|
||||
Example (strategy: :attr:`~.MaintenanceStrategy.CRON`)::
|
||||
|
||||
>>> api.add_maintenance(
|
||||
... title="test",
|
||||
... description="test",
|
||||
... strategy=MaintenanceStrategy.CRON,
|
||||
... active=True,
|
||||
... intervalDay=1,
|
||||
... dateRange=[
|
||||
... "2022-12-27 22:39:00",
|
||||
... "2022-12-31 22:39:00"
|
||||
... ],
|
||||
... weekdays=[],
|
||||
... daysOfMonth=[],
|
||||
... cron="50 5 * * *",
|
||||
... durationMinutes=120,
|
||||
... timezone="Europe/Berlin"
|
||||
... )
|
||||
{
|
||||
"msg": "Added Successfully.",
|
||||
"maintenanceID": 1
|
||||
}
|
||||
"""
|
||||
data = _build_maintenance_data(**kwargs)
|
||||
data = self._build_maintenance_data(**kwargs)
|
||||
_check_arguments_maintenance(data)
|
||||
return self._call('addMaintenance', data)
|
||||
|
||||
|
|
|
@ -319,8 +319,11 @@ def maintenance_docstring(mode) -> str:
|
|||
:param list, optional dateRange: DateTime Range, defaults to ``["<current date>"]``
|
||||
:param int, optional intervalDay: Interval (Run once every day), defaults to ``1``
|
||||
:param list, optional weekdays: List that contains the days of the week on which the maintenance is enabled (Sun = ``0``, Mon = ``1``, ..., Sat = ``6``). Required for ``strategy`` :attr:`~.MaintenanceStrategy.RECURRING_WEEKDAY`., defaults to ``[]``.
|
||||
:param list, optional daysOfMonth: List that contains the days of the month on which the maintenance is enabled (Day 1 = ``1``, Day 2 = ``2``, ..., Day 31 = ``31``) and the last day of the month (Last Day of Month = ``"lastDay1"``, 2nd Last Day of Month = ``"lastDay2"``, 3rd Last Day of Month = ``"lastDay3"``, 4th Last Day of Month = ``"lastDay4"``). Required for ``strategy`` :attr:`~.MaintenanceStrategy.RECURRING_DAY_OF_MONTH`., defaults to ``[]``.
|
||||
:param list, optional daysOfMonth: List that contains the days of the month on which the maintenance is enabled (Day 1 = ``1``, Day 2 = ``2``, ..., Day 31 = ``31``) and the last day of the month (``"lastDay1"``). Required for ``strategy`` :attr:`~.MaintenanceStrategy.RECURRING_DAY_OF_MONTH`., defaults to ``[]``.
|
||||
:param list, optional timeRange: Maintenance Time Window of a Day, defaults to ``[{{"hours": 2, "minutes": 0}}, {{"hours": 3, "minutes": 0}}]``.
|
||||
:param str, optional cron: Cron Schedule. Required for ``strategy`` :attr:`~.MaintenanceStrategy.CRON`., defaults to ``"30 3 * * *"``
|
||||
:param int, optional durationMinutes: Duration (Minutes). Required for ``strategy`` :attr:`~.MaintenanceStrategy.CRON`., defaults to ``60``
|
||||
:param str, optional timezone: Timezone, defaults to ``None`` (Server Timezone)
|
||||
"""
|
||||
|
||||
|
||||
|
|
|
@ -18,3 +18,6 @@ class MaintenanceStrategy(str, Enum):
|
|||
|
||||
RECURRING_DAY_OF_MONTH = "recurring-day-of-month"
|
||||
"""Recurring - Day of Month"""
|
||||
|
||||
CRON = "cron"
|
||||
"""Cron Expression"""
|
||||
|
|
Loading…
Reference in a new issue