Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I add monitors to status pages? #8

Closed
AMDTonyRyzen opened this issue Oct 11, 2022 · 2 comments
Closed

How do I add monitors to status pages? #8

AMDTonyRyzen opened this issue Oct 11, 2022 · 2 comments

Comments

@AMDTonyRyzen
Copy link

Hi, can you tell me how I can change the status_page data using the python api. Apparently, the following function save_status_page(self, slug: str, **kwargs) is used for this, but I don't quite understand how to insert data into it correctly.
print(api.save_status_page(slug="google", data={'domainNameList': ["google.com"]}))
I get html code and
requests.exceptions.JSONDecodeError: [Errno Expecting value]

@lucasheld
Copy link
Owner

Here is a full example.

First you need to add the monitors themselves.
Then add a status page and save it with the publicGroupList parameter. It consists of a name (the title of the monitor section inside the status page), a weight (to define the order if you have multiple monitor sections) and a monitorList (the ids of the monitors you want to add to this status page section).

from uptime_kuma_api import UptimeKumaApi, MonitorType

username = "admin"
password = "secret123"

api = UptimeKumaApi("http://127.0.0.1:3001")
if api.need_setup():
    api.setup(username, password)
api.login(username, password)

monitor_id_1 = api.add_monitor(
    type=MonitorType.HTTP,
    url="http://127.0.0.1",
    name="monitor1"
)["monitorID"]

monitor_id_2 = api.add_monitor(
    type=MonitorType.HTTP,
    url="http://127.0.0.2",
    name="monitor2"
)["monitorID"]

slug = "statuspage1"
api.add_status_page(
    slug=slug,
    title="Status Page 1"
)
api.save_status_page(
    slug=slug,
    publicGroupList=[
        {
            'name': 'Services',
            'weight': 1,
            'monitorList': [
                {
                    "id": monitor_id_1
                },
                {
                    "id": monitor_id_2
                }
            ]
        }
    ]
)

api.disconnect()

@AMDTonyRyzen
Copy link
Author

Thank you so much for the detailed answer, at the time of receipt I still get an error, but I think I can handle it over time, I understood the main principle. By the way, if you need help writing a manual, I can help in my free time. you can infiltrate me in tg @Ynot_Frost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants