Missing event counts when value is 0

Forum for questions and support relating to 1.33.x development only.
Post Reply
rockedge
Posts: 1080
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Missing event counts when value is 0

Post by rockedge » Thu Dec 13, 2018 6:47 pm

I have a very recent build of ZM 1.33.0 compiled and running well. I have noticed the event count fields on the web console gui are not always displayed. Until an event is created and the event count is zero... the digit "0" is not displayed. Also the count of the zones shows as "0" and at some point not yet determined, will display the number of zones for that monitor properly but at ZM restart the zone count will be shown as "0".

One can click on the zone count for a monitor and it will open up the zone interface window which has the zones correctly displayed.

I am not wholly positive that it is only a ZM problem but am interested if anyone else has seen this pop up in their version 1.33.0

User avatar
knight-of-ni
Posts: 2224
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Missing event counts when value is 0

Post by knight-of-ni » Thu Dec 13, 2018 7:49 pm

I've only got guesses at the moment, but there is a conversation in Slack with Akturas reporting negative events. Perhaps this is related.
It looks like he just waited and things righted themselves.

We fixed an issue displaying event counts on the web console with the 1.32.3 release, but due to the way we implemented it, it is possible the update could have been skipped on any machine that was running our master branch at any time.... Try calling zm_update-1.32.3.sql manually, from a sql prompt, to see if that makes things right.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

User avatar
iconnor
Posts: 740
Joined: Fri Oct 29, 2010 1:43 am
Location: Toronto
Contact:

Re: Missing event counts when value is 0

Post by iconnor » Fri Dec 14, 2018 3:36 pm

So in the 1.30 days, when displaying the console, we did an sql statement like SELECT COUNT(*) FROM Zones where MonitorID=? for each monitor.

In 1.32, we have a ZOneCount column in the Monitors table, and a trigger that updates it when you save a zone.

The trigger looks like this:
DROP TRIGGER IF EXISTS Zone_Insert_Trigger//
CREATE TRIGGER Zone_Insert_Trigger AFTER INSERT ON Zones
FOR EACH ROW
BEGIN
UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=NEW.MonitorId) WHERE Id=NEW.MonitorID;
END
//
DROP TRIGGER IF EXISTS Zone_Delete_Trigger//
CREATE TRIGGER Zone_Delete_Trigger AFTER DELETE ON Zones
FOR EACH ROW
BEGIN
UPDATE Monitors SET ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=OLD.MonitorId) WHERE Id=OLD.MonitorID;
END
//


So I can't imagine how that value got to be a null, but to manually update them all you could do

Update Monitors set ZoneCount=(SELECT COUNT(*) FROM Zones WHERE MonitorId=Monitors.Id);

rockedge
Posts: 1080
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Missing event counts when value is 0

Post by rockedge » Fri Dec 14, 2018 7:52 pm

I noticed this error when I ran zmupdate.pl but skipped over it and now used phpmyadmin to repeat the update manually and I have this error produced by zm_update-1.32.3.sql :

Code: Select all

Error

SQL query:

DROP TRIGGER IF EXISTS Events_Day_update_trigger;
CREATE TRIGGER Events_Day_update_trigger AFTER UPDATE ON Events_Day
FOR EACH ROW
  BEGIN
    declare diff BIGINT default 0;

    set diff = COALESCE(NEW.DiskSpace,0) - COALESCE(OLD.DiskSpace,0);
    IF ( diff ) THEN
      IF ( NEW.MonitorID != OLD.MonitorID ) THEN
        UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)-COALESCE(OLD.DiskSpace,0) WHERE Monitors.Id=OLD.MonitorId;
        UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)+COALESCE(NEW.DiskSpace,0) WHERE Monitors.Id=NEW.MonitorId;
      ELSE
        UPDATE Monitors SET DayEventDiskSpace=COALESCE(DayEventDiskSpace,0)+diff WHERE Monitors.Id=NEW.MonitorId;
      END IF;
    END IF;
  END;

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TRIGGER Events_Day_update_trigger AFTER UPDATE ON Events_Day
FOR EACH ROW' at line 2
which now makes sense why it is working weirdly

there were nulls in the tables....I changed to 0 and the web console looks okay
I have no idea other than the sql syntax error near the end of the database upgrade .sql sequence
Last edited by rockedge on Fri Dec 14, 2018 8:12 pm, edited 1 time in total.

User avatar
knight-of-ni
Posts: 2224
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Missing event counts when value is 0

Post by knight-of-ni » Fri Dec 14, 2018 8:11 pm

Try calling it from a command prompt:

Code: Select all

$ mysql -uroot -p zm < /usr/share/zoneminder/db/zm_update-1.32.3.sql
This works fine for me, with no error messages.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

rockedge
Posts: 1080
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Missing event counts when value is 0

Post by rockedge » Fri Dec 14, 2018 8:14 pm

I ran it and it appears okay...zmupdate.pl stumbled on it though and I ended up with nulls in the tables

Code: Select all

 ~ #mysql -uroot -p zm < /usr/local/share/zoneminder/db/zm_update-1.32.3.sql
Enter password: 
Column Protocol already exists in Servers
Column Protocol already exists in Servers
Column PathToIndex already exists in Servers
Column PathToIndex already exists in Servers
Column PathToZMS already exists in Servers
Column PathToZMS already exists in Servers
Column PathToApi already exists in Servers
Column PathToApi already exists in Servers
Column Port already exists in Servers
Column Port already exists in Servers

User avatar
knight-of-ni
Posts: 2224
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Missing event counts when value is 0

Post by knight-of-ni » Fri Dec 14, 2018 8:30 pm

zmupdate.pl runs the sql statement under the zmuser sql account, but the example I gave ran as the mysql root user.

Verify you have granted all permission to the zmuser sql account like so:

Code: Select all

mysql -uroot -p -e "grant all on zm.* to 'zmuser'@localhost identified by 'zmpass';"
mysqladmin -uroot -p reload
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/

rockedge
Posts: 1080
Joined: Fri Apr 04, 2014 1:46 pm
Location: Connecticut,USA
Contact:

Re: Missing event counts when value is 0

Post by rockedge » Fri Dec 14, 2018 10:24 pm

I had checked and the permissions were indicated as being correct. I did use the command you indicated just to be sure.

and then ran zmupdate.pl and it reports the database as at version 1.33.0

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests