Check connection state #16

Open
opened 2023-01-26 19:58:42 +01:00 by zimbres · 5 comments
zimbres commented 2023-01-26 19:58:42 +01:00 (Migrated from github.com)

Hello,

Is there some function to check if the connection is already established and login is done?

Trying to get_monitors without previous login, results in a "no end" call. Should this has some timeout?

Hello, Is there some function to check if the connection is already established and login is done? Trying to get_monitors without previous login, results in a "no end" call. Should this has some timeout?
lucasheld commented 2023-01-26 20:40:02 +01:00 (Migrated from github.com)

I don't know if the login expires at some point.
However, it is possible that there is no longer a connection to the server due to a timeout or a connection failure.
Currently there is no way to check this, except to recreate the instance and log in again in case of such an exception.

Has this happened more than once? Can you determine a pattern? How long does it take before the connection gets lost?

I don't know if the login expires at some point. However, it is possible that there is no longer a connection to the server due to a timeout or a connection failure. Currently there is no way to check this, except to recreate the instance and log in again in case of such an exception. Has this happened more than once? Can you determine a pattern? How long does it take before the connection gets lost?
zimbres commented 2023-01-26 22:15:02 +01:00 (Migrated from github.com)

I tried to force some kind off network failure in order to get some error, but had no success, even if after a network error, your lib keeps working.

But, it is expected to have some kind of failure behavior that requires a new login.

The point is avoid login on each call. I have a remote probe to use with "push" monitor type today getting the sensor configuration from a local configuration, but I want top get this from some tags in the monitor to have it more dynamic, to do this I create an API using your package to call it from my code that is C#, and this call will happen each minute.

By the way, your lib helped a lot since there is no official implementation for get sensors details directly from UptimeKuma.

This is my App if can be usefull for you: UptimeKumaRemoteProbe

I tried to force some kind off network failure in order to get some error, but had no success, even if after a network error, your lib keeps working. But, it is expected to have some kind of failure behavior that requires a new login. The point is avoid login on each call. I have a remote probe to use with "push" monitor type today getting the sensor configuration from a local configuration, but I want top get this from some tags in the monitor to have it more dynamic, to do this I create an API using your package to call it from my code that is C#, and this call will happen each minute. By the way, your lib helped a lot since there is no official implementation for get sensors details directly from UptimeKuma. This is my App if can be usefull for you: [UptimeKumaRemoteProbe](https://github.com/zimbres/UptimeKumaRemoteProbe/tree/endpoints_sync)
mariogarridopt commented 2023-01-26 22:28:23 +01:00 (Migrated from github.com)

I had a similar problem. I think even an invalid login might hang the process.
The only way I found to unstuck was to disconnect it.

So I just wrap the code into a try-catch block (so errors wont block code execution) and then disconnect at the end:

from uptime_kuma_api import UptimeKumaApi

try:
    api = UptimeKumaApi('http://localhost:3001')
    api.login('admin', 'admin')

    monitor_list = api.get_monitors() # get all monitors
    print(monitor_list)
except:
    print("Connection was unsuccessfull")
finally:
    api.disconnect()
I had a similar problem. I think even an invalid login might hang the process. The only way I found to unstuck was to disconnect it. So I just wrap the code into a try-catch block (so errors wont block code execution) and then disconnect at the end: ```python from uptime_kuma_api import UptimeKumaApi try: api = UptimeKumaApi('http://localhost:3001') api.login('admin', 'admin') monitor_list = api.get_monitors() # get all monitors print(monitor_list) except: print("Connection was unsuccessfull") finally: api.disconnect() ```
zimbres commented 2023-02-03 17:42:39 +01:00 (Migrated from github.com)

I wraped the get_monitors inside a function with this lib wrapt_timeout_decorator

@timeout(30)
def api_monitors():
    return api.get_monitors()

This way if I dont get a proper return, I can take another action like login again.

I wraped the get_monitors inside a function with this lib [wrapt_timeout_decorator](https://github.com/bitranox/wrapt_timeout_decorator) ``` @timeout(30) def api_monitors(): return api.get_monitors() ``` This way if I dont get a proper return, I can take another action like login again.
8ball030 commented 2023-02-24 20:15:47 +01:00 (Migrated from github.com)

Wanted to all of you guys, thanks for the amazing work you have just both literally saved me so so so much work.

Wanted to all of you guys, thanks for the amazing work you have just both literally saved me so so so much work.
Sign in to join this conversation.
No description provided.