You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to allow all of my developers to freely install this, but I don't want them access user/password to kuma. I have made some changes to the code to parse the metrics api that can use the api key. I'll leave this here incase anyone else is looking for this functionality or if we want to include this into this project:
#!/usr/bin/env python3
#
# <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
import requests
import re
# -------------------------------------------
TOKEN = '<API_KEY>'
DOMAIN = 'my.domain.com'
BASE_URL = 'https://' + ':'+ TOKEN + '@' + DOMAIN + '/metrics'
SITE = 'https://' + DOMAIN
REPORTING_URL = 'https://mygrafana.dashboard.com/status?orgId=1&from=now-60m&to=now&&var-Service='
# -------------------------------------------
def parse_line(line, status):
attributes = {}
items = re.findall(r'(\w+)=(".*?"|\w+)', line)
for key, value in items:
attributes[key] = value.strip('"')
attributes['status'] = status
return attributes
def get_response_time(list, name):
for rs in list:
if rs['monitor_name'] == name:
return "- " + rs['status'] + "ms"
return ""
try:
x = requests.get(BASE_URL)
status_pattern = re.compile(r'monitor_status\{(.+?)\} (\d)')
monitor_rt_pattern = re.compile(r'monitor_response_time\{(.+?)\} (\d+)')
# Extract matches and parse them
status_matches = status_pattern.findall(x.text)
monitor_rt_matches = monitor_rt_pattern.findall(x.text)
monitor_status_list = [parse_line(match[0], match[1]) for match in status_matches]
monitor_rt_list = [parse_line(match[0], match[1]) for match in monitor_rt_matches]
monitor_status_list = [item for item in monitor_status_list if item['monitor_type'] != 'group']
monitor_total = len(monitor_status_list);
monitor_online = 0;
monitor_list_string = [];
## GET DATA
for monitor in monitor_status_list:
text = monitor['monitor_name'] + " " + get_response_time(monitor_rt_list,monitor['monitor_name']) + " | href='"+ REPORTING_URL + monitor['monitor_name']+"'"
if(monitor['status']=="1"):
monitor_online = monitor_online + 1
text = "🟢 " + text
elif(monitor['status']=="2"):
text = "🟡 " + text
elif(monitor['status']=="3"):
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='" + SITE + "/dashboard'")
except Exception as e:
print('📛')
print('---')
print("No monitor! | color='red'")
print(e)
print("Click here to configure | href='file://%s'" % os.path.abspath('uptimekuma.30s.py'))
The text was updated successfully, but these errors were encountered:
I want to allow all of my developers to freely install this, but I don't want them access user/password to kuma. I have made some changes to the code to parse the metrics api that can use the api key. I'll leave this here incase anyone else is looking for this functionality or if we want to include this into this project:
The text was updated successfully, but these errors were encountered: