Page 1 of 1

ZoneMinder API - one of my cameras started returning None for MonitorId

Posted: Fri Oct 04, 2024 7:27 pm
by montagdude
Hi,

I use some python scripts to do object detection and send notifications via Pushover or email. The scripts access the ZoneMinder API via the requests python module. When setting up the monitors, I get the monitor ID as follows:

Code: Select all

# Send request for api_path/monitors.json prior to this and return the response as 'r'
rj = r.json()
for item in rj['monitors']:
    monitor = {}
    try:
        monitor['id'] = int(item['Monitor_Status']['MonitorId'])
        monitor['name'] = item['Monitor']['Name']
    except TypeError:
        # Print a debugging message (not shown here)
        continue
I've done a bit of debugging which indicates that item['Monitor_Status]['MonitorId'] is None for this particular camera. Actually, there are two monitors associated with this camera, one for the low-res stream and one for the high-res stream. Both return None, but that wasn't the case until recently, sometime within the last week, I think. It's also not the case for any of my other cameras. Any clues as to how to debug this issue?

Re: ZoneMinder API - one of my cameras started returning None for MonitorId

Posted: Fri Oct 04, 2024 7:37 pm
by montagdude
Just to add a bit more information, I have tried:
  • Restarting the server
  • Restarting ZoneMinder
  • Restarting the problematic camera
Also, the Id shows up fine in the web console. This seems to be an issue with the API only.

Re: ZoneMinder API - one of my cameras started returning None for MonitorId

Posted: Sat Oct 05, 2024 2:38 pm
by iconnor
You are pulling MonitorId from the Monitor_Status table. If there is no entry in there (because it isn't running) then you'll get None. Get MonitorId from the Monitors table, so item.Id

Re: ZoneMinder API - one of my cameras started returning None for MonitorId

Posted: Sun Oct 06, 2024 1:59 pm
by montagdude
Thanks, that solved it. It's been a while since I wrote this, and I'm not really sure why I used the Monitor_Status table in the first place. To clarify for anyone else who might search this, the fix was to use:

Code: Select all

monitor['id'] = int(item['Monitor']['Id'])