-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
uptimekuma.30s.py
executable file
·63 lines (52 loc) · 1.91 KB
/
uptimekuma.30s.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
#
# <xbar.title>UptimeKuma Monitor</xbar.title>
# <xbar.version>v1.1</xbar.version>
# <xbar.author>mariogarridopt</xbar.author>
# <xbar.author.github>mariogarridopt</xbar.author.github>
# <xbar.desc>Show UptimeKuma status</xbar.desc>
# <xbar.dependencies>python</xbar.dependencies>
# <xbar.abouturl>https://github.com/mariogarridopt/xBar-Uptime-Kuma</xbar.abouturl>
# <xbar.image>https://raw.githubusercontent.com/mariogarridopt/xBar-Uptime-Kuma/master/screenshot.png</xbar.image>
#
import os
from uptime_kuma_api import UptimeKumaApi
# -------------------------------------------
BASE_URL = 'http://localhost:3001' # no trailing slash
USERNAME = 'admin'
PASSWORD = 'admin'
# -------------------------------------------
try:
api = UptimeKumaApi(BASE_URL)
api.login(USERNAME, PASSWORD)
monitor_list = api.get_monitors()
monitor_total = len(monitor_list);
monitor_online = 0;
monitor_list_string = [];
## GET DATA
for monitor in monitor_list:
beats = api.get_monitor_beats(monitor['id'], 24)
text = monitor['name'] + " | href='" + BASE_URL + "/dashboard/" + str(monitor['id']) + "'"
if(len(beats) > 0 and beats[-1]['status'] == True):
monitor_online = monitor_online + 1
text = "🟢 " + text
else:
text = "❗️ " + text + " color='#ff0000'"
monitor_list_string.append(text)
## PRINT DATA
if monitor_online == monitor_total:
print('🌍')
else:
print(monitor_online, '/', monitor_total)
print('---')
for monitors_text in monitor_list_string:
print(monitors_text)
print('---')
print("Open UptimeKuma | href='" + BASE_URL + "/dashboard'")
except:
print('📛')
print('---')
print("No monitor! | color='red'")
print("Click here to configure | href='file://%s'" % os.path.abspath('uptimekuma.30s.py'))
finally:
api.disconnect()