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

Inconsistant Status calls using get_monitor_status #52

Open
bikrdotnet opened this issue Aug 23, 2023 · 2 comments
Open

Inconsistant Status calls using get_monitor_status #52

bikrdotnet opened this issue Aug 23, 2023 · 2 comments

Comments

@bikrdotnet
Copy link

I drafted a quick and dirty python blob to test the ability to retrieve a monitor status but am getting very inconsistent results.

`import time
from uptime_kuma_api import UptimeKumaApi
from uptime_kuma_api.exceptions import UptimeKumaException
import argparse

UPTIME_KUMA_URL = 'http://192.168.22.2'
UPTIME_KUMA_USER = 'MYUSER'
UPTIME_KUMA_PASSWORD = 'MYPASSSWORD'

def poll_monitor_status(monitor_id):
api = UptimeKumaApi(UPTIME_KUMA_URL)
api.login(UPTIME_KUMA_USER, UPTIME_KUMA_PASSWORD)

try:
    monitor_status_response = api.get_monitor_status(monitor_id)
    monitor_status = monitor_status_response.name  # Correctly retrieve status
    print(f"Monitor ID {monitor_id} Status: {monitor_status}")
    
except UptimeKumaException as ex:
    print(f"An error occurred for monitor ID {monitor_id}: {ex}")
    
    # Detailed logging lines
    if hasattr(ex, 'response'):
        print("Error response content:", ex.response.content)
api.disconnect()
time.sleep(1)

if name == "main":
parser = argparse.ArgumentParser(description="Poll monitor status from Uptime Kuma API")
parser.add_argument("monitor_id", type=int, help="ID of the monitor to check")
args = parser.parse_args()

poll_monitor_status(args.monitor_id)

`

Below is me running the command a few times to show the inconsistency.

printer1@floorplan % python3 test.py 59 An error occurred for monitor ID 59: monitor does not exist printer1@floorplan % python3 test.py 59 An error occurred for monitor ID 59: monitor does not exist printer1@floorplan % python3 test.py 59 Monitor ID 59 Status: UP printer1@floorplan % python3 test.py 59 An error occurred for monitor ID 59: monitor does not exist

These commands were run within 5 seconds of each other, with no changes in network status , no changes of anything inside the script etc..

Any help troubleshooting would be greatly appreciated.

@kafisatz
Copy link

I am running into this as well.
Besides monitor does not exist I also get list indices must be integers or slices, not str.
Although, as a python novice, I am not 100% certain if this stems from my code or the underyling code

@alsidneio
Copy link

Line 542 has a very short sleep time that is called. If you increase that you get more results. I cant determine the order that the list gets populated. You may have to play with that sleep time depending on how many monitors you have.

def _get_event_data(self, event) -> Any:
monitor_events = [Event.AVG_PING, Event.UPTIME, Event.HEARTBEAT_LIST, Event.IMPORTANT_HEARTBEAT_LIST, Event.CERT_INFO, Event.HEARTBEAT]
timestamp = time.time()
while self._event_data[event] is None:
if time.time() - timestamp > self.timeout:
raise Timeout(f"Timed out while waiting for event {event}")
# do not wait for events that are not sent
if self._event_data[Event.MONITOR_LIST] == {} and event in monitor_events:
return []
time.sleep(0.01)
time.sleep(self.wait_events) # wait for multiple messages
return deepcopy(self._event_data[event].copy())

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

3 participants