2022-08-02 23:47:56 +02:00
|
|
|
import unittest
|
2022-08-03 12:35:48 +02:00
|
|
|
|
2022-08-26 14:03:17 +02:00
|
|
|
from uptime_kuma_api import UptimeKumaException, MonitorType
|
2022-08-03 12:35:48 +02:00
|
|
|
from uptime_kuma_test_case import UptimeKumaTestCase
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestMonitor(UptimeKumaTestCase):
|
|
|
|
def test_monitor(self):
|
|
|
|
expected_monitor = {
|
2022-08-26 14:03:17 +02:00
|
|
|
"type": MonitorType.HTTP,
|
2022-08-02 23:47:56 +02:00
|
|
|
"name": "monitor 1",
|
2022-08-26 14:03:17 +02:00
|
|
|
"url": "http://127.0.0.1"
|
2022-08-02 23:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# add monitor
|
2022-08-26 14:03:17 +02:00
|
|
|
r = self.api.add_monitor(**expected_monitor)
|
2022-08-02 23:47:56 +02:00
|
|
|
self.assertEqual(r["msg"], "Added Successfully.")
|
2022-08-03 11:56:02 +02:00
|
|
|
monitor_id = r["monitorID"]
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
# get monitor
|
|
|
|
monitor = self.api.get_monitor(monitor_id)
|
|
|
|
self.compare(monitor, expected_monitor)
|
|
|
|
|
|
|
|
# get monitors
|
|
|
|
monitors = self.api.get_monitors()
|
|
|
|
monitor = self.find_by_id(monitors, monitor_id)
|
|
|
|
self.assertIsNotNone(monitor)
|
|
|
|
self.compare(monitor, expected_monitor)
|
|
|
|
|
|
|
|
# edit monitor
|
2022-08-03 11:56:02 +02:00
|
|
|
expected_monitor["type"] = "ping"
|
2022-08-02 23:47:56 +02:00
|
|
|
expected_monitor["name"] = "monitor 1 new"
|
2022-08-26 14:03:17 +02:00
|
|
|
expected_monitor["hostname"] = "127.0.0.10"
|
2022-08-02 23:47:56 +02:00
|
|
|
del expected_monitor["url"]
|
|
|
|
r = self.api.edit_monitor(monitor_id, **expected_monitor)
|
|
|
|
self.assertEqual(r["msg"], "Saved.")
|
|
|
|
monitor = self.api.get_monitor(monitor_id)
|
|
|
|
self.compare(monitor, expected_monitor)
|
|
|
|
|
|
|
|
# pause monitor
|
|
|
|
r = self.api.pause_monitor(monitor_id)
|
|
|
|
self.assertEqual(r["msg"], "Paused Successfully.")
|
|
|
|
|
|
|
|
# resume monitor
|
|
|
|
r = self.api.resume_monitor(monitor_id)
|
|
|
|
self.assertEqual(r["msg"], "Resumed Successfully.")
|
|
|
|
|
2022-08-05 14:35:17 +02:00
|
|
|
# get monitor beats
|
|
|
|
self.api.get_monitor_beats(monitor_id, 6)
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
# delete monitor
|
|
|
|
r = self.api.delete_monitor(monitor_id)
|
|
|
|
self.assertEqual(r["msg"], "Deleted Successfully.")
|
|
|
|
with self.assertRaises(UptimeKumaException):
|
|
|
|
self.api.get_monitor(monitor_id)
|
|
|
|
|
2022-08-26 14:03:17 +02:00
|
|
|
def do_test_monitor_type(self, expected_monitor):
|
|
|
|
r = self.api.add_monitor(**expected_monitor)
|
|
|
|
self.assertEqual(r["msg"], "Added Successfully.")
|
|
|
|
monitor_id = r["monitorID"]
|
|
|
|
|
|
|
|
monitor = self.api.get_monitor(monitor_id)
|
|
|
|
self.compare(monitor, expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_http(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.HTTP,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"url": "http://127.0.0.1"
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_port(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.PORT,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"hostname": "127.0.0.1",
|
|
|
|
"port": 8888
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_ping(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.PING,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"hostname": "127.0.0.1",
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_keyword(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.KEYWORD,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"url": "http://127.0.0.1",
|
|
|
|
"keyword": "healthy"
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_dns(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.DNS,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"url": "http://127.0.0.1",
|
|
|
|
"hostname": "127.0.0.1",
|
|
|
|
"port": 8888,
|
|
|
|
"dns_resolve_server": "1.1.1.1",
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_push(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.PUSH,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"url": "http://127.0.0.1"
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_steam(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.STEAM,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"url": "http://127.0.0.1",
|
|
|
|
"hostname": "127.0.0.1",
|
|
|
|
"port": 8888,
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_mqtt(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.MQTT,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"url": "http://127.0.0.1",
|
|
|
|
"hostname": "127.0.0.1",
|
|
|
|
"port": 8888,
|
|
|
|
"mqttTopic": "test"
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
|
|
|
def test_monitor_type_sqlserver(self):
|
|
|
|
expected_monitor = {
|
|
|
|
"type": MonitorType.SQLSERVER,
|
|
|
|
"name": "monitor 1",
|
|
|
|
"url": "http://127.0.0.1",
|
|
|
|
"databaseConnectionString": "Server=127.0.0.1,8888;Database=test;User Id=1;Password=secret123;Encrypt=true;"
|
|
|
|
"TrustServerCertificate=Yes;Connection Timeout=5",
|
|
|
|
"databaseQuery": "select getdate()"
|
|
|
|
}
|
|
|
|
self.do_test_monitor_type(expected_monitor)
|
|
|
|
|
2022-08-02 23:47:56 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|