Giter Site home page Giter Site logo

Comments (6)

lucasheld avatar lucasheld commented on May 30, 2024 1

I'm not sure how this error occurred. It looks like the login was successful, but when the monitor was created uptime kuma was no longer reachable.

This is an example code that works with a fresh uptime kuma instance.

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)

r = api.add_monitor(type=MonitorType.HTTP, name="Test API", url="https://gm.com")
print(r)
# {'msg': 'Added Successfully.', 'monitorID': 1}

monitors = api.get_monitors()
print(monitors)
# [{'id': 1, 'name': 'Test API', 'url': 'https://gm.com', 'method': 'GET', 'hostname': None, 'port': 53, 'maxretries': 0, 'weight': 2000, 'active': True, 'type': 'http', 'interval': 60, 'retryInterval': 60, 'resendInterval': 0, 'keyword': None, 'expiryNotification': False, 'ignoreTls': False, 'upsideDown': False, 'maxredirects': 10, 'accepted_statuscodes': ['200-299'], 'dns_resolve_type': 'A', 'dns_resolve_server': '1.1.1.1', 'dns_last_result': None, 'pushToken': None, 'docker_container': None, 'docker_host': None, 'proxyId': None, 'notificationIDList': [], 'tags': [], 'mqttUsername': None, 'mqttPassword': None, 'mqttTopic': None, 'mqttSuccessMessage': None, 'databaseConnectionString': None, 'databaseQuery': None, 'authMethod': '', 'authWorkstation': None, 'authDomain': None, 'radiusUsername': None, 'radiusPassword': None, 'radiusCalledStationId': None, 'radiusCallingStationId': None, 'radiusSecret': None, 'headers': None, 'body': None, 'basic_auth_user': None, 'basic_auth_pass': None}]

api.disconnect()

from uptime-kuma-api.

lucasheld avatar lucasheld commented on May 30, 2024 1

Supported parameters for add_monitor and edit_monitor:

type: MonitorType,
name: str,
interval: int = 60,
retryInterval: int = 60,
resendInterval: int = 0,
maxretries: int = 0,
upsideDown: bool = False,
notificationIDList: list = None,
# HTTP, KEYWORD
url: str = None,
expiryNotification: bool = False,
ignoreTls: bool = False,
maxredirects: int = 10,
accepted_statuscodes: list = None,
proxyId: int = None,
method: str = "GET",
body: str = None,
headers: str = None,
authMethod: AuthMethod = AuthMethod.NONE,
basic_auth_user: str = None,
basic_auth_pass: str = None,
authDomain: str = None,
authWorkstation: str = None,
# KEYWORD
keyword: str = None,
# DNS, PING, STEAM, MQTT
hostname: str = None,
# DNS, STEAM, MQTT
port: int = 53,
# DNS
dns_resolve_server: str = "1.1.1.1",
dns_resolve_type: str = "A",
# MQTT
mqttUsername: str = None,
mqttPassword: str = None,
mqttTopic: str = None,
mqttSuccessMessage: str = None,
# SQLSERVER, POSTGRES
databaseConnectionString: str = None,
databaseQuery: str = None,
# DOCKER
docker_container: str = "",
docker_host: int = None,
# RADIUS
radiusUsername: str = None,
radiusPassword: str = None,
radiusSecret: str = None,
radiusCalledStationId: str = None,
radiusCallingStationId: str = None

An existing monitor can be edited by passing the id of the monitor and the key-value pairs of monitor parameters that should be edited.

def edit_monitor(self, id_: int, **kwargs):

Example:

# add a new monitor
r = api.add_monitor(type=MonitorType.HTTP, name="Test API", url="https://gm.com")
print(r)
# {'msg': 'Added Successfully.', 'monitorID': 1}

# save the id of the new monitor
monitor_id = r["monitorID"]

# get and print the monitor
monitor = api.get_monitor(monitor_id)
print(monitor)
# {'id': 1, 'name': 'Test API', 'url': 'https://gm.com', 'method': 'GET', 'hostname': None, 'port': 53, 'maxretries': 0, 'weight': 2000, 'active': True, 'type': 'http', 'interval': 60, 'retryInterval': 60, 'resendInterval': 0, 'keyword': None, 'expiryNotification': False, 'ignoreTls': False, 'upsideDown': False, 'maxredirects': 10, 'accepted_statuscodes': ['200-299'], 'dns_resolve_type': 'A', 'dns_resolve_server': '1.1.1.1', 'dns_last_result': None, 'pushToken': None, 'docker_container': None, 'docker_host': None, 'proxyId': None, 'notificationIDList': [], 'tags': [], 'mqttUsername': None, 'mqttPassword': None, 'mqttTopic': None, 'mqttSuccessMessage': None, 'databaseConnectionString': None, 'databaseQuery': None, 'authMethod': '', 'authWorkstation': None, 'authDomain': None, 'radiusUsername': None, 'radiusPassword': None, 'radiusCalledStationId': None, 'radiusCallingStationId': None, 'radiusSecret': None, 'headers': None, 'body': None, 'basic_auth_user': None, 'basic_auth_pass': None}

# edit the monitor, change the url and the heartbeat interval
r = api.edit_monitor(monitor_id, url="https://google.com", interval=20)
print(r)
# {'msg': 'Saved.', 'monitorID': 1}

# get and print the monitor again
monitor = api.get_monitor(monitor_id)
print(monitor)
# {'id': 1, 'name': 'Test API', 'url': 'https://google.com', 'method': 'GET', 'hostname': None, 'port': 53, 'maxretries': 0, 'weight': 2000, 'active': True, 'type': 'http', 'interval': 20, 'retryInterval': 60, 'resendInterval': 0, 'keyword': None, 'expiryNotification': False, 'ignoreTls': False, 'upsideDown': False, 'maxredirects': 10, 'accepted_statuscodes': ['200-299'], 'dns_resolve_type': 'A', 'dns_resolve_server': '1.1.1.1', 'dns_last_result': None, 'pushToken': None, 'docker_container': None, 'docker_host': None, 'proxyId': None, 'notificationIDList': [], 'tags': [], 'mqttUsername': None, 'mqttPassword': None, 'mqttTopic': None, 'mqttSuccessMessage': None, 'databaseConnectionString': None, 'databaseQuery': None, 'authMethod': '', 'authWorkstation': None, 'authDomain': None, 'radiusUsername': None, 'radiusPassword': None, 'radiusCalledStationId': None, 'radiusCallingStationId': None, 'radiusSecret': None, 'headers': None, 'body': None, 'basic_auth_user': None, 'basic_auth_pass': None}

from uptime-kuma-api.

boshnak avatar boshnak commented on May 30, 2024

looks like its related to the python version I used (3.6.9)
once I switch to 3.7.5 it worked as expected.

any chance to get more examples of the api? how to edit existing monitors, which inputs are supported while creating a monitor, e.g. retry count before notificiation, etc.

from uptime-kuma-api.

lucasheld avatar lucasheld commented on May 30, 2024

I have started writing documentation for this module, with examples for all methods. I will publish it the next days.

from uptime-kuma-api.

boshnak avatar boshnak commented on May 30, 2024

thank you!!

from uptime-kuma-api.

lucasheld avatar lucasheld commented on May 30, 2024

The documentation is now available here: https://uptime-kuma-api.readthedocs.io/

from uptime-kuma-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.