Page 1 of 1

[SOLVED] Getting monitor status from API

Posted: Mon Feb 10, 2020 2:39 pm
by moasat
I'm not sure this is a 1.34 issue but I did upgrade over the weekend. I'm writing an app and trying to get the monitor status through the API by calling /zm/api/monitors/alarm/id:5/command:status.json but the response I get back always has a blank status: {"status":""}. This is for every monitor. I've also tried forcing an alarm on the monitor but the status doesn't change. It shows up in the web GUI just fine. Maybe I have something configured wrong? I'm expecting to see one of Idle, Alert, Alarm, etc.

Re: Getting monitor status from API

Posted: Mon Feb 10, 2020 5:28 pm
by iconnor
I'm not so great with cakephp.... so I have no idea what the url actually means.

If you just do
/zm/api/monitors/5.json

you will get all the monitor data, including a Monitor_Status field.

Re: Getting monitor status from API

Posted: Mon Feb 10, 2020 6:02 pm
by moasat
This is what I get from api/monitors/2.json. The Monitor_Status only shows "Connected", not one of Idle, Alarm, Alert. Also, I thought I read that Monitor_Status is not available in earlier versions of ZM and I was hoping to support those, although its not a requirement.

Code: Select all

{
  "monitor": {
    "Monitor": {
      "Id": "2",
      "Name": "PTZ",
      "Notes": null,
      "ServerId": "0",
      "StorageId": "2",
      "Type": "Ffmpeg",
      "Function": "Modect",
      "Enabled": "1",
      "LinkedMonitors": "",
      "Triggers": "",
      "Device": "\/dev\/video0",
      "Channel": "0",
      "Format": "255",
      "V4LMultiBuffer": null,
      "V4LCapturesPerFrame": "1",
      "Protocol": "rtsp",
      "Method": "rtpRtsp",
      "Host": "user:password@ip-camera2",
      "Port": "554",
      "SubPath": "",
      "Path": "rtsp:\/\/user:password@ip-camera2\/live",
      "Options": null,
      "User": null,
      "Pass": null,
      "Width": "1920",
      "Height": "1080",
      "Colours": "4",
      "Palette": "0",
      "Orientation": "ROTATE_0",
      "Deinterlacing": "0",
      "DecoderHWAccelName": null,
      "DecoderHWAccelDevice": null,
      "SaveJPEGs": "3",
      "VideoWriter": "1",
      "OutputCodec": null,
      "OutputContainer": null,
      "EncoderParameters": "# Lines beginning with # are a comment \r\n# For changing quality, use the crf option\r\n# 1 is best, 51 is worst quality\r\n#crf=23",
      "RecordAudio": "0",
      "RTSPDescribe": false,
      "Brightness": "-1",
      "Contrast": "-1",
      "Hue": "-1",
      "Colour": "-1",
      "EventPrefix": "Event-",
      "LabelFormat": "%N - %d\/%m\/%y %H:%M:%S",
      "LabelX": "0",
      "LabelY": "0",
      "LabelSize": "1",
      "ImageBufferCount": "30",
      "WarmupCount": "2",
      "PreEventCount": "15",
      "PostEventCount": "15",
      "StreamReplayBuffer": "0",
      "AlarmFrameCount": "2",
      "SectionLength": "600",
      "MinSectionLength": "10",
      "FrameSkip": "0",
      "MotionFrameSkip": "0",
      "AnalysisFPSLimit": "5.00",
      "AnalysisUpdateDelay": "0",
      "MaxFPS": "30.000",
      "AlarmMaxFPS": "30.00",
      "FPSReportInterval": "100",
      "RefBlendPerc": "6",
      "AlarmRefBlendPerc": "6",
      "Controllable": "0",
      "ControlId": null,
      "ControlDevice": null,
      "ControlAddress": null,
      "AutoStopTimeout": null,
      "TrackMotion": "0",
      "TrackDelay": null,
      "ReturnLocation": "-1",
      "ReturnDelay": null,
      "DefaultRate": "100",
      "DefaultScale": "100",
      "DefaultCodec": "auto",
      "SignalCheckPoints": "10",
      "SignalCheckColour": "#0000c0",
      "WebColour": "red",
      "Exif": false,
      "Sequence": "2",
      "TotalEvents": "37",
      "TotalEventDiskSpace": "434525663",
      "HourEvents": "0",
      "HourEventDiskSpace": "0",
      "DayEvents": "1",
      "DayEventDiskSpace": "9388570",
      "WeekEvents": "5",
      "WeekEventDiskSpace": "50392474",
      "MonthEvents": "15",
      "MonthEventDiskSpace": "187283227",
      "ArchivedEvents": "0",
      "ArchivedEventDiskSpace": null,
      "ZoneCount": "1",
      "Refresh": null
    },
    "Monitor_Status": {
      "MonitorId": "2",
      "Status": "Connected",
      "CaptureFPS": "14.29",
      "AnalysisFPS": "5.26",
      "CaptureBandwidth": "154519"
    }
  }
}

Re: Getting monitor status from API

Posted: Tue Feb 11, 2020 4:36 pm
by asker
If you want alarm status then

Code: Select all

https://server/api/monitors/alarm/id:X/command:status.json

is correct. I just checked on my monitors and I am correctly getting the right status value based on the alarmed status. I also forced an alarm on a modect monitor, and the status switch correctly from 0 to 2.

Re: Getting monitor status from API

Posted: Wed Feb 12, 2020 1:29 am
by moasat
Hmm, mine is always blank. I have 5 different monitors, all return {"status":""} regardless of the status. Maybe a regression bug in 1.34?

Re: Getting monitor status from API

Posted: Wed Feb 12, 2020 2:50 pm
by iconnor
I have two thoughts on this:

#1 if this was a multi-server setup and we asked a server that wasn't the recording server, it would fail.

#2 If auth not working, perhaps due to timezone problem, then maybe we get nothing.

The thing to do would be turn on debugging and see what zmu is saying.

Re: Getting monitor status from API

Posted: Thu Feb 13, 2020 12:43 am
by moasat
Its a single server setup. And all of the previous calls are working. But zmu.log is giving an error of:

Code: Select all

02/12/20 18:37:58.035870 zmu[27091].ERR-zmu.cpp/435 [Username must be supplied]
I'm using token based auth, so the URLs look like this:

Code: Select all

https://zm:443/zm/api/monitors/alarm/id:2/command:status.json?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJab25lTWluZGVyIiwiaWF0IjoxNTgxNTUwNTc3LCJleHAiOjE1ODE1NTc3NzcsInVzZXIiOiJhZG1pbiIsInR5cGUiOiJhY2Nlc3MifQ.4X2kXbEuqq-uo9N6kj4sJ5NdJFpDFjaqLlt9xVlRmnk
I tried changing the url to https://user@zm and also https://user:pass@zm but neither made a difference. What username should I be using here? Again, all the other API calls I'm using seem to be working ok. I also tried adding user as a query param and also user and pass as query params. Still no difference.

Re: Getting monitor status from API

Posted: Thu Feb 13, 2020 1:28 am
by asker
Try setting AUTH_RELAY to hashed.

Re: Getting monitor status from API

Posted: Fri Feb 14, 2020 2:59 am
by moasat
Setting AUTH_RELAY to Hashed fixed it. It looks like that change had no other adverse effects so I'll keep it. Any explanation why everything else was working but that wasn't?