ZoneMinder / zmeventnotification

Machine Learning powered Secure Websocket & MQTT based ZoneMinder event notification server
408 stars 128 forks source link

ModuleNotFoundError: No module named 'zmes_hook_helpers' #391

Closed CV8R closed 3 years ago

CV8R commented 3 years ago

Whenever I try and run the Event Server with hooks enabled I face the error in the title. I have tried re-running the install script (sudo -H ./install.sh) but looks like I am missing dependencies. This was an older 1.32 system with the ES long before the hooks were available. I have been running 1.34.23 for some months and only now trying to experiment with the detections. I was missing a series of dependencies (numpy, pyzm - possibly more cannot recall now) but hung up on this error and cannot get any further.

Event Server version

6.1.22

Hooks version (if you are using Object Detection)

sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py --version

returns:

$ sudo -u www-data /var/lib/zmeventnotification/bin/zm_detect.py --version
Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 27, in <module>
    import zmes_hook_helpers.utils as utils
ModuleNotFoundError: No module named 'zmes_hook_helpers'

Same result with:

$ sudo ./zm_event_start.sh 908 4
Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 27, in <module>
    import zmes_hook_helpers.utils as utils
ModuleNotFoundError: No module named 'zmes_hook_helpers'

The version of ZoneMinder you are using:

v1.34.23

Debug Logs (if applicable)


2/04/21 23:08:36.801930 zmeventnotification[2409358].INF [main:331] [Running on WebSocket library version:0.004]
INF:2021-04-12,23:08:36 PARENT: using config file: /etc/zm/zmeventnotification.ini
12/04/21 23:08:36.917043 zmeventnotification[2409358].INF [main:1022] [PARENT: using config file: /etc/zm/zmeventnotification.ini]
INF:2021-04-12,23:08:36 PARENT: using secrets file: /etc/zm/secrets.ini
12/04/21 23:08:36.986150 zmeventnotification[2409358].INF [main:1022] [PARENT: using secrets file: /etc/zm/secrets.ini]
DBG-2:2021-04-12,23:08:37 PARENT: Got secret token !ZMES_PICTURE_URL
DBG-2:2021-04-12,23:08:37 PARENT: Got secret token !ZM_USER
DBG-2:2021-04-12,23:08:37 PARENT: Got secret token !ZM_PASSWORD
DBG-3:2021-04-12,23:08:37 PARENT: config string substitution: {{base_data_path}} is '/var/lib/zmeventnotification'

Configuration (read /etc/zm/zmeventnotification.ini):

Secrets file.......................... /etc/zm/secrets.ini
Base data path........................ /var/lib/zmeventnotification
Restart interval (secs)............... 0

Use admin interface .................. no
Admin interface password.............. (undefined)
Admin interface persistence file ..... /var/lib/zmeventnotification/misc/escontrol_interface.dat

Port ................................. 9000
Address .............................. [::]
Event check interval ................. 5
Monitor reload interval .............. 300
Skipped monitors...................... (undefined)

Auth enabled ......................... yes
Auth timeout ......................... 20

Use API Push.......................... no
API Push Script....................... (undefined)

Use FCM .............................. yes
Use FCM V1 APIs....................... yes
FCM Date Format....................... %I:%M %p, %d-%b
Only show latest FCMv1 message........ no
Android FCM push priority............. high
Android FCM push ttl.................. (undefined)

Token file ........................... /var/lib/zmeventnotification/push/tokens.txt

Use MQTT ............................. no
MQTT Server .......................... 127.0.0.1
MQTT Topic ........................... zoneminder
MQTT Username ........................ (undefined)
MQTT Password ........................ (undefined)
MQTT Retain .......................... no
MQTT Tick Interval ................... 15
MQTT TLS CA ........................ (undefined)
MQTT TLS Cert ........................ (undefined)
MQTT TLS Key ........................ (undefined)
MQTT TLS Insecure ........................ no

SSL enabled .......................... yes
SSL cert file ........................ /etc/apache2/ssl/zoneminder.crt
SSL key file ......................... /etc/apache2/ssl/zoneminder.key

Verbose .............................. yes
ES Debug level.........................4
Read alarm cause ..................... yes
Tag alarm event id ................... yes
Use custom notification sound ........ no
Send event start notification..........yes
Send event end notification............yes
Monitor rules JSON file................(undefined)

Use Hooks............................. yes
Max Parallel Hooks.................... 0
Hook Script on Event Start ........... '/var/lib/zmeventnotification/bin/zm_event_start.sh'
User Script on Event Start.............(undefined)
Hook Script on Event End.............. (undefined)
User Script on Event End...............(undefined)
Hook Skipped monitors................. (undefined)

Notify on Event Start (hook success).. all
Notify on Event Start (hook fail)..... none
Notify on Event End (hook success).... fcm,web,api
Notify on Event End (hook fail)....... none
Notify End only if Start success...... yes

Use Hook Description.................. yes
Keep frame match type................. yes
Store Frame in ZM......................yes

Picture URL .......................... https://www.APlace.net/zm/index.php?view=image&eid=EVENTID&fid=objdetect&width=600
Include picture....................... yes
Picture username ..................... zmuser
Picture password ..................... (defined)

INF:2021-04-12,23:08:37 PARENT: Push enabled via FCM
12/04/21 23:08:37.177088 zmeventnotification[2409358].INF [main:1022] [PARENT: Push enabled via FCM]
DBG-4:2021-04-12,23:08:37 PARENT: fcmv1: --> FCM V1 APIs: 1
INF:2021-04-12,23:08:37 PARENT: MQTT Disabled
12/04/21 23:08:37.219757 zmeventnotification[2409358].INF [main:1022] [PARENT: MQTT Disabled]
INF:2021-04-12,23:08:37 PARENT: |------- Starting ES version: 6.1.22 ---------|
12/04/21 23:08:37.279957 zmeventnotification[2409358].INF [main:1022] [PARENT: |------- Starting ES version: 6.1.22 ---------|]
DBG-1:2021-04-12,23:08:37 PARENT: Started with: perl:/usr/bin/perl and command:/usr/bin/zmeventnotification.pl
Can't ignore signal CHLD, forcing to default.
DBG-1:2021-04-12,23:08:37 PARENT: ES invoked manually. Will handle restarts ourselves
DBG-2:2021-04-12,23:08:37 PARENT: Parent<--Child pipe ready
INF:2021-04-12,23:08:37 PARENT: Event Notification daemon v 6.1.22 starting

12/04/21 23:08:37.480488 zmeventnotification[2409358].INF [main:1022] [PARENT: Event Notification daemon v 6.1.22 starting]
DBG-1:2021-04-12,23:08:37 PARENT: Initializing FCM tokens...
DBG-1:2021-04-12,23:08:37 PARENT: Total event client connections: 3

DBG-1:2021-04-12,23:08:37 PARENT: -->checkNewEvents: Connection 1: ID->1618232917.54563 IP->(none) Token->:...GG39CAPzn_ Plat:android Push:disabled
DBG-1:2021-04-12,23:08:37 PARENT: -->checkNewEvents: Connection 2: ID->1618232917.54567 IP->(none) Token->:...F3oFdpNGT6 Plat:android Push:enabled
DBG-1:2021-04-12,23:08:37 PARENT: -->checkNewEvents: Connection 3: ID->1618232917.54568 IP->(none) Token->:...Zu1COfx5BJ Plat:android Push:enabled
INF:2021-04-12,23:08:37 PARENT: Re-loading monitors
12/04/21 23:08:37.546321 zmeventnotification[2409358].INF [main:1022] [PARENT: Re-loading monitors]
DBG-1:2021-04-12,23:08:37 PARENT: Loading Doorbell Camera
DBG-1:2021-04-12,23:08:37 PARENT: Loading Driveway
DBG-1:2021-04-12,23:08:37 PARENT: ESCONTROL_INTERFACE is disabled. Not saving control data
DBG-2:2021-04-12,23:08:37 PARENT: checkEvents() new events found=0
DBG-2:2021-04-12,23:08:37 PARENT: About to start listening to socket
INF:2021-04-12,23:08:37 PARENT: Secure WS(WSS) is enabled...
12/04/21 23:08:37.628908 zmeventnotification[2409358].INF [main:1022] [PARENT: Secure WS(WSS) is enabled...]
INF:2021-04-12,23:08:37 PARENT: Web Socket Event Server listening on port 9000
12/04/21 23:08:37.696577 zmeventnotification[2409358].INF [main:1022] [PARENT: Web Socket Event Server listening on port 9000]
DBG-2:2021-04-12,23:08:42 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:1 min)<--------------
DBG-2:2021-04-12,23:08:42 PARENT: After tick: TOTAL: 3,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 3, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-04-12,23:08:42 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2021-04-12,23:08:42 PARENT: checkEvents() new events found=0
DBG-2:2021-04-12,23:08:42 PARENT: There are 0 new Events to process
DBG-2:2021-04-12,23:08:42 PARENT: ---------->Tick END (active forks:0, total forks:0, active hooks: 0)<--------------
DBG-2:2021-04-12,23:08:47 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:1 min)<--------------
DBG-2:2021-04-12,23:08:47 PARENT: After tick: TOTAL: 3,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 3, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-04-12,23:08:47 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2021-04-12,23:08:47 PARENT: checkEvents() new events found=0
DBG-2:2021-04-12,23:08:47 PARENT: There are 0 new Events to process
DBG-2:2021-04-12,23:08:47 PARENT: ---------->Tick END (active forks:0, total forks:0, active hooks: 0)<--------------
DBG-2:2021-04-12,23:08:52 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:1 min)<--------------
DBG-2:2021-04-12,23:08:52 PARENT: After tick: TOTAL: 3,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 3, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-04-12,23:08:52 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2021-04-12,23:08:52 PARENT: checkEvents() new events found=0
DBG-2:2021-04-12,23:08:52 PARENT: There are 0 new Events to process
DBG-2:2021-04-12,23:08:52 PARENT: ---------->Tick END (active forks:0, total forks:0, active hooks: 0)<--------------
DBG-2:2021-04-12,23:08:57 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:1 min)<--------------
DBG-2:2021-04-12,23:08:57 PARENT: After tick: TOTAL: 3,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 3, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-04-12,23:08:57 PARENT: There are 0 active child forks & 0 zm_detect processes running...
INF:2021-04-12,23:08:57 PARENT: New event 931 reported for Monitor:4 (Name:Doorbell Camera) Forced Web[last processed eid:]
12/04/21 23:08:57.979601 zmeventnotification[2409358].INF [main:1022] [PARENT: New event 931 reported for Monitor:4 (Name:Doorbell Camera) Forced Web[last processed eid:]]
DBG-2:2021-04-12,23:08:58 PARENT: checkEvents() new events found=1
DBG-2:2021-04-12,23:08:58 PARENT: There are 1 new Events to process
DBG-2:2021-04-12,23:08:58 PARENT: ---------->Tick END (active forks:1, total forks:1, active hooks: 0)<--------------
DBG-1:2021-04-12,23:08:58 PARENT: Forked process:2409411 to handle alarm eid:931
DBG-2:2021-04-12,23:08:58 |----> FORK:Doorbell Camera (4), eid:931 Adding event path:/var/cache/zoneminder/events/4/2021-04-12/931 to hook for image storage
DBG-1:2021-04-12,23:08:58 |----> FORK:Doorbell Camera (4), eid:931 Invoking hook on event start:'/var/lib/zmeventnotification/bin/zm_event_start.sh' 931 4 "Doorbell Camera" "Forced Web" "/var/cache/zoneminder/events/4/2021-04-12/931"
Traceback (most recent call last):
  File "/var/lib/zmeventnotification/bin/zm_detect.py", line 27, in <module>
    import zmes_hook_helpers.utils as utils
ModuleNotFoundError: No module named 'zmes_hook_helpers'
DBG-2:2021-04-12,23:08:58 |----> FORK:Doorbell Camera (4), eid:931 parse of hook: and []
DBG-1:2021-04-12,23:08:58 |----> FORK:Doorbell Camera (4), eid:931 hook start returned with text: json:[] exit:1
DBG-2:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 rules: Checking rules for alarm caused by eid:931, monitor:4, at: Mon Apr 12 23:09:00 2021 with cause:Forced Web
DBG-1:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 rules: No rules found for Monitor, allowing:4
DBG-1:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 Matching alarm to connection rules...
DBG-1:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 Checking alarm conditions for token ending in:...GG39CAPzn_
DBG-1:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 should NOT send alarm as Monitor 4 is excluded
DBG-1:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 Checking alarm conditions for token ending in:...F3oFdpNGT6
DBG-1:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 Monitor 4 event: last time not found, so should send
DBG-1:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 token is unique, shouldSendEventToConn returned true, so calling sendEvent
DBG-2:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 isAllowedChannel: got type:event_start resCode:1
INF:2021-04-12,23:09:00 |----> FORK:Doorbell Camera (4), eid:931 Not sending over FCM as notify filters are on_success:all and on_fail:none
12/04/21 23:09:00.986536 zmeventnotification[2409411].INF [main:1022] [|----> FORK:Doorbell Camera (4), eid:931 Not sending over FCM as notify filters are on_success:all and on_fail:none]
DBG-3:2021-04-12,23:09:01 |----> FORK:Doorbell Camera (4), eid:931 child finished writing to parent
DBG-1:2021-04-12,23:09:01 |----> FORK:Doorbell Camera (4), eid:931 Checking alarm conditions for token ending in:...Zu1COfx5BJ
DBG-1:2021-04-12,23:09:01 |----> FORK:Doorbell Camera (4), eid:931 Monitor 4 event: last time not found, so should send
DBG-1:2021-04-12,23:09:01 |----> FORK:Doorbell Camera (4), eid:931 token is unique, shouldSendEventToConn returned true, so calling sendEvent
DBG-2:2021-04-12,23:09:01 |----> FORK:Doorbell Camera (4), eid:931 isAllowedChannel: got type:event_start resCode:1
INF:2021-04-12,23:09:01 |----> FORK:Doorbell Camera (4), eid:931 Not sending over FCM as notify filters are on_success:all and on_fail:none
12/04/21 23:09:01.044033 zmeventnotification[2409411].INF [main:1022] [|----> FORK:Doorbell Camera (4), eid:931 Not sending over FCM as notify filters are on_success:all and on_fail:none]
DBG-3:2021-04-12,23:09:01 |----> FORK:Doorbell Camera (4), eid:931 child finished writing to parent
DBG-2:2021-04-12,23:09:02 PARENT: ----------> Tick START (active forks:1, total forks:1, active hooks: 0 running for:1 min)<--------------
DBG-2:2021-04-12,23:09:02 PARENT: After tick: TOTAL: 3,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 3, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-04-12,23:09:02 PARENT: RAW TEXT-->update_parallel_hooks--TYPE--add
DBG-2:2021-04-12,23:09:02 PARENT: RAW TEXT-->update_parallel_hooks--TYPE--del
DBG-2:2021-04-12,23:09:02 PARENT: RAW TEXT-->timestamp--TYPE--1618232917.54567--SPLIT--4--SPLIT--1618232940.98613
DBG-2:2021-04-12,23:09:02 PARENT: Job: Update last sent timestamp of monitor:4 to 1618232940.98613 for id:1618232917.54567
DBG-2:2021-04-12,23:09:02 PARENT: RAW TEXT-->timestamp--TYPE--1618232917.54568--SPLIT--4--SPLIT--1618232941.04385
DBG-2:2021-04-12,23:09:02 PARENT: Job: Update last sent timestamp of monitor:4 to 1618232941.04385 for id:1618232917.54568
DBG-2:2021-04-12,23:09:02 PARENT: There are 1 active child forks & 0 zm_detect processes running...
DBG-2:2021-04-12,23:09:02 PARENT: checkEvents() new events found=0
DBG-2:2021-04-12,23:09:02 PARENT: There are 0 new Events to process
DBG-2:2021-04-12,23:09:02 PARENT: ---------->Tick END (active forks:1, total forks:1, active hooks: 0)<--------------

Thanks!

andrewheberle commented 3 years ago

I had the same issue and tracked it to an error that occurs during the install process of the hooks in the install script:

For me this errors out as follows, so various pre-requisites are not installed:

      File "/tmp/pip-req-build-dzqz553y/setup.py", line 44, in <module>
        version=find_version('zmes_hook_helpers', '__init__.py'),
      File "/tmp/pip-req-build-dzqz553y/setup.py", line 40, in find_version
        raise RuntimeError("Unable to find version string.")
    RuntimeError: Unable to find version string.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-dzqz553y/

Its not a proper solution really, but the following worked for me by hard coding the version string in the file hook/setup.py as follows:

sed -i -e 's/version=find_version\(.*\)\,/version='\''6.1.22'\''\,/' hook/setup.py

This ensures the hooks and pre-requisite Python modules get installed, but unfortunately things still don't work right after that when I try to test things out as per the docs, so this might indicate something wrong with my Python3 setup.

For reference I'm running on a Debian 10 based container, so this might be distro based weirdness...

CV8R commented 3 years ago

Bingo! Adding the version manually installed the pre-reqs and zm_detect.py executes properly. I am running Ubuntu 20.04.2 LTS on a dedicated server.

Thank you.

pliablepixels commented 3 years ago

@andrewheberle would you grab install.sh and setup.py from master and see if it works? If not, please post the output after you select 'y' for install hook

me8myself commented 3 years ago

I am having the same issue. Adding sed -i -e 's/version=find_version(.*)\,/version='\''6.1.22'\''\,/' hook/setup.py causes my install to fail much earlier. I assume I am putting it in the wrong place?

#!/usr/bin/python3

import io
import os
import re
import codecs

from setuptools import setup
sed -i -e 's/version=find_version\(.*\)\,/version='\''6.1.22'\''\,/' hook/setup.py

#Package meta-data
NAME = 'zmes_hook_helpers'
DESCRIPTION = 'ZoneMinder EventServer hook helper functions'
URL = 'https://github.com/pliablepixels/zmeventserver/'
AUTHOR_EMAIL = 'pliablepixels@gmail.com'
AUTHOR = 'Pliable Pixels'
LICENSE = 'GPL'
INSTALL_REQUIRES = [
    'numpy', 'requests', 'Shapely', 'imutils', 
    'pyzm>=0.3.48', 'scikit-learn', 'future', 'imageio',
    'imageio-ffmpeg','pygifsicle', 'Pillow'
]

here = os.path.abspath(os.path.dirname(__file__))
# read the contents of your README file
with open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

def read(*parts):
    here = os.path.abspath(os.path.dirname(__file__))
    print ('VERBOSE: Reading {}'.format(os.path.join(here, *parts)))
    with codecs.open(os.path.join(here, *parts), 'r') as fp:
        return fp.read()

def find_version(*file_paths):
    version_file = read(*file_paths)
    print ('VERBOSE: version_file is {}'.format(version_file))
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)

    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string.")

setup(name=NAME,
      version=find_version('zmes_hook_helpers', '__init__.py'),
      description=DESCRIPTION,
      author=AUTHOR,
      author_email=AUTHOR_EMAIL,
      long_description=long_description,
      long_description_content_type='text/markdown',
      url=URL,
      license=LICENSE,
      install_requires=INSTALL_REQUIRES,
      py_modules=[
          'zmes_hook_helpers.common_params', 
          'zmes_hook_helpers.log',
          'zmes_hook_helpers.image_manip',
          'zmes_hook_helpers.apigw', 
          'zmes_hook_helpers.utils'
      ])
andrewheberle commented 3 years ago

@pliablepixels i have tested the install with the updated install.sh and setup.py and this does fix the hook install issue.

Thanks for that.

Secondly @me8myself ...the sed command is run from your shell from the location you are running the event server install from...but as I said this is more of a band-aid and not a proper fix (as you can see above this is fixed in the latest code and I'm sure will be included in an updated release).

pliablepixels commented 3 years ago

Sounds good. 6.1.23 was released 3 days ago with this change.