API Events from Last Hour Omits Cameras with no Events

Forum for questions and support relating to the 1.29.x releases only.
Locked
User avatar
snake
Posts: 337
Joined: Sat May 21, 2016 2:20 am

API Events from Last Hour Omits Cameras with no Events

Post by snake »

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: 1553
Joined: Sun Mar 01, 2015 12:12 pm

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

Post by asker »

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.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
User avatar
snake
Posts: 337
Joined: Sat May 21, 2016 2:20 am

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

Post by snake »

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: 1553
Joined: Sun Mar 01, 2015 12:12 pm

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

Post by asker »

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.
I no longer work on zmNinja, zmeventnotification, pyzm or mlapi. I may respond on occasion based on my available time/interest.

Please read before posting:
How to set up logging properly
How to troubleshoot and report - ES
How to troubleshoot and report - zmNinja
ES docs
zmNinja docs
Locked