lucasheld / uptime-kuma-api

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

get_monitor_status for all monitors #62

Open kafisatz opened 11 months ago

kafisatz commented 11 months ago

Great project, thanks! I would like to get the status of all monitors (number of up, down, pending, ....) I am not using any status pages right now.

The uptime kuma main webpage shows 'quick stats'. This is exactly what I want to get via API.

the snippet below takes about 15 seconds for 50 monitors, which is a bit inefficient.

    id = monitor["id"]
    st = api.get_monitor_status(id)

is there a better way to get all stati? I am only interested in the number of monitors that are up. I don't need the IDs.

Noschvie commented 9 months ago

Hello same here, want to get the "Quick Stats" overview too.

Maybe using the /metrics end point of uptime-kuma is a workaround. Passing metrics to other platforms

Find all lines starting with "monitor_status" and have a look to the latest character of the line. # HELP monitor_status Monitor Status (1 = UP, 0= DOWN, 2= PENDING, 3= MAINTENANCE)

kafisatz commented 8 months ago

FYI, I am now using a small python snippet to achieve this:

consider pip install playwright followed by playwright install

UPK_PW = "abcd"
UPK_USER = "uptimekuma"
UPK_URL = "https://uptimekuma.myurl.ch"

from time import sleep
import traceback
from playwright.sync_api import sync_playwright

def py_playwright_get_summary(UPK_PW,UPK_URL,UPK_USER):
    txt = "Up0Down999Maintenance0Unknown0Pause0"
    with sync_playwright() as p:
        browser_type = p.chromium
        browser = browser_type.launch()
        page = browser.new_page()
        page.goto(UPK_URL)

        page.get_by_label("Username").fill(UPK_USER)
        page.get_by_label("Password").fill(UPK_PW)
        page.get_by_role("button" ).click()
        sleep(3)

        txt = page.locator("#app > div > main > div > div > div.col-12.col-md-7.col-xl-8.mb-3 > div > div.shadow-box.big-padding.text-center.mb-4 > div").text_content()

        browser.close()
    return txt

abc = py_playwright_get_summary(UPK_PW,UPK_URL,UPK_USER)
print(abc)