API Events from Last Hour Omits Cameras with no Events

Forum for questions and support relating to the 1.29.x releases only.
Post Reply
snake
Posts: 92
Joined: Sat May 21, 2016 2:20 am

API Events from Last Hour Omits Cameras with no Events

Post by snake » Wed Jan 10, 2018 6:26 pm

Using devuan Jessie, 1.29.

I noticed that when running this command

curl "http://server/zm/api/events/consoleEvents/1%20hour.json" you get a list of events for cameras in the last hour, that are not zero. That is, if events exist, then you get the monitor ID, and the # of events. Howver, if events are zero for a camera, you get no entry for this in the report. This may be incorrect, so I'd like to draw it to attention here.

The official API docs have a section on returning a list of events for all monitors within a given time range. The next section goes on to explain how you can use the handy mechanism to report events per monitor in the last hour.

This is not a significant problem. I can work around it as it is, however maybe it should be adjusted so that if a monitor exists in the DB, yet has zero events, it returns the monitor ID and an entry of "0" for the # of events in the last hour.

Response when all cameras have events:

Code: Select all

{
    "results": {
        "1": "6",
        "2": "6",
        "3": "6",
        "4": "6",
        "5": "6",
        "6": "6",
    }
}
Response when one or more cameras have zero events:

Code: Select all

{
    "results": {
        "1": "6",
        "2": "6",
        "3": "6",
        "5": "6",
        "6": "6",
    }
}
Last edited by snake on Wed Jan 10, 2018 6:36 pm, edited 2 times in total.

User avatar
asker
Posts: 941
Joined: Sun Mar 01, 2015 12:12 pm

Re: API Events from Last Hour Omits Cameras with no Events

Post by asker » Wed Jan 10, 2018 6:32 pm

I think this is the expected behavior. This API grabs entries from the events database and reports back with data (https://github.com/ZoneMinder/ZoneMinde ... r.php#L259)

In other words if an event did not occur at all for a particular monitor ID, it would not be in the Events DB. Now one could say that for the sake of consistency, return "0" for that monitor but one could also say "not returning a monitor Id" means it was 0.

So not sure if I'd call this a bug either, just a different interpretation. My 2c.
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

snake
Posts: 92
Joined: Sat May 21, 2016 2:20 am

Re: API Events from Last Hour Omits Cameras with no Events

Post by snake » Fri Jan 12, 2018 3:14 am

Isn't it possible to use this?

Code: Select all

Select Monitors.ID e.Count from Monitors left join (select Events.MonitorID, COUNT(*) as Count from Events where StartTime >= (DATE_SUB(NOW(), interval 1 hour)) group by Events.MonitorID ) as e on Monitors.ID = e.MonitorID;
Maybe it's more trouble than its worth, this fix though.

User avatar
asker
Posts: 941
Joined: Sun Mar 01, 2015 12:12 pm

Re: API Events from Last Hour Omits Cameras with no Events

Post by asker » Fri Jan 12, 2018 3:32 pm

snake wrote:
Fri Jan 12, 2018 3:14 am
Maybe it's more trouble than its worth, this fix though.
That's just it - what you posted is do-able. The way CakePHP works is by default it puts in easy code to be able to access the DB that the controller is linked with (in this case Events, not Monitors). However, what you are asking for is likely very easily done - but someone needs to read up on CakePHP and understand the best way do do it. Not hard, but requires reading.

If you feel strongly about it, you might want to suggest a PR for it and see if the ZM folks agree (or ask first and then implement it). I'm personally fine with both approaches.
--
My collection of ZoneMinder learnings:
https://wiki.zoneminder.com/Various_ZM_thoughts

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest