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

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
montagdude
Posts: 91
Joined: Fri Nov 10, 2017 6:05 pm

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

Post 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?
montagdude
Posts: 91
Joined: Fri Nov 10, 2017 6:05 pm

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

Post 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.
User avatar
iconnor
Posts: 3185
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

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

Post 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
montagdude
Posts: 91
Joined: Fri Nov 10, 2017 6:05 pm

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

Post 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'])
Post Reply