]> www.vanbest.org Git - motioneye-debian/commitdiff
sendmail & eventrelay: more verbose logging
authorCalin Crisan <ccrisan@gmail.com>
Thu, 6 Aug 2015 17:47:40 +0000 (20:47 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Thu, 6 Aug 2015 17:48:15 +0000 (20:48 +0300)
eventrelay.py
motioneye.py
sendmail.py
src/config.py
src/smbctl.py
templates/main.html

index ca3bb2da43eacf39ca4a7d896021cfec83afb2a5..42c02f3c59c27a3a43c9a1b2fc2ca31e0cde3e2a 100755 (executable)
@@ -32,7 +32,7 @@ from motioneye import _configure_settings, _configure_logging
 
 
 _configure_settings()
-_configure_logging()
+_configure_logging(module='eventrelay')
 
 
 def print_usage():
@@ -117,6 +117,7 @@ if __name__ == '__main__':
     event = sys.argv[1] 
     thread_id = sys.argv[2]
 
+    logging.debug('hello!')
     logging.debug('event = %s' % event)
     logging.debug('thread_id = %s' % thread_id)
     
@@ -142,3 +143,5 @@ if __name__ == '__main__':
     
     except Exception as e:
         logging.error('failed to relay event: %s' % e)
+
+    logging.debug('bye!')
index 3dbde2dff6ea9ede747a1814c80692ad1777622f..27e005a19ffdcc0b3e7c95cabe7221b3e0ce45e3 100755 (executable)
@@ -260,9 +260,15 @@ def _configure_signals():
     signal.signal(signal.SIGCHLD, child_handler)
 
 
-def _configure_logging():
+def _configure_logging(module=None):
+    if module:
+        format = '%(asctime)s: [{module}] %(levelname)s: %(message)s'.format(module=module)
+        
+    else:
+        format = '%(asctime)s: %(levelname)s: %(message)s'
+
     logging.basicConfig(filename=None, level=settings.LOG_LEVEL,
-            format='%(asctime)s: %(levelname)s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
+            format=format, datefmt='%Y-%m-%d %H:%M:%S')
     
     logging.getLogger('tornado').setLevel(logging.WARN)
 
index 2539c06a8fd4f5ddeefefa5c7fe12dbb3c356b99..4844c089cbd369d5e9653cdcef42434c62661663 100755 (executable)
@@ -37,7 +37,7 @@ from motioneye import _configure_settings, _configure_logging, _configure_signal
 
 _configure_settings()
 _configure_signals()
-_configure_logging()
+_configure_logging(module='sendmail')
 
 import config
 import mediafiles
@@ -81,6 +81,7 @@ def send_mail(server, port, account, password, tls, to, subject, message, files)
     if files:
         logging.debug('attached %d pictures' % len(files))
 
+    logging.debug('sending email message')
     conn.sendmail(_from, to, email.as_string())
     conn.quit()
 
@@ -89,11 +90,15 @@ def make_message(subject, message, camera_id, moment, timespan, callback):
     camera_config = config.get_camera(camera_id)
     
     def on_media_files(media_files):
+        logging.debug('got media files')
+        
         timestamp = time.mktime(moment.timetuple())
 
         media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < timespan] # filter out non-recent media files
         media_files.sort(key=lambda m: m['timestamp'], reverse=True)
         media_files = [os.path.join(camera_config['target_dir'], re.sub('^/', '', m['path'])) for m in media_files]
+        
+        logging.debug('selected %d pictures' % len(media_files))
 
         format_dict = {
             'camera': camera_config['@name'],
@@ -118,7 +123,9 @@ def make_message(subject, message, camera_id, moment, timespan, callback):
 
     if not timespan:
         return on_media_files([])
-        
+
+    logging.debug('creating email message')
+
     time.sleep(timespan) # give motion some time to create motion pictures
     mediafiles.list_media(camera_config, media_type='picture', callback=on_media_files)
 
@@ -145,7 +152,9 @@ if __name__ == '__main__':
         timespan = int(sys.argv[10])
 
     except:
-        timespan = 5
+        timespan = 0
+
+    logging.debug('hello!')
 
     message = messages.get(msg_id)
     subject = subjects.get(msg_id)
@@ -194,3 +203,5 @@ if __name__ == '__main__':
 
     io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT), ioloop_timeout)
     io_loop.start()
+
+    logging.debug('bye!')
\ No newline at end of file
index d89bb426f7539910d1fb573a485f13befc34aa25..a786efa2bbc3a8984f31c2cf6e75935f9a9c2046 100644 (file)
@@ -28,10 +28,8 @@ import urlparse
 from tornado.ioloop import IOLoop
 
 import diskctl
-import motionctl
 import powerctl
 import settings
-import smbctl
 import update
 import utils
 import v4l2ctl
@@ -599,6 +597,8 @@ def main_dict_to_ui(data):
 
 
 def motion_camera_ui_to_dict(ui, old_config=None):
+    import smbctl
+    
     old_config = dict(old_config or {})
     main_config = get_main() # needed for surveillance password
 
@@ -878,6 +878,8 @@ def motion_camera_ui_to_dict(ui, old_config=None):
 
 
 def motion_camera_dict_to_ui(data):
+    import smbctl
+    
     ui = {
         # device
         'name': data['@name'],
@@ -1125,6 +1127,7 @@ def motion_camera_dict_to_ui(data):
     if on_event_start:
         on_event_start = [e.strip() for e in on_event_start.split(';')]
 
+    ui['email_notifications_picture_time_span'] = 0
     command_notifications = []
     for e in on_event_start:
         if e.count('sendmail.py') and e.count('motion_start'):
@@ -1143,7 +1146,7 @@ def motion_camera_dict_to_ui(data):
                 ui['email_notifications_picture_time_span'] = int(e[10])
                 
             except:
-                ui['email_notifications_picture_time_span'] = 5
+                ui['email_notifications_picture_time_span'] = 0
 
         elif e.count('webhook.py'):
             e = shlex.split(e)
@@ -1293,6 +1296,8 @@ def restore(content):
 
 
 def is_old_motion():
+    import motionctl
+    
     try:
         binary, version = motionctl.find_motion()  # @UnusedVariable
         
index dd67deabfbde7fe938353195124a5c0b1e427224..12e45053a3bae618e1a24af50504ebb2ddc770b4 100644 (file)
@@ -25,7 +25,6 @@ import time
 from tornado import ioloop
 
 import config
-import motionctl
 import settings
 
 
@@ -210,6 +209,8 @@ def umount_all():
 
 
 def _check_mounts():
+    import motionctl
+    
     logging.debug('checking SMB mounts...')
     
     stop, start = update_mounts()
index ccaba8a2895d8a1cd71e0c7f0606f45706e0498a..199e08f46196da61f526d9ca860247a0c3cd34c3 100644 (file)
                     <tr class="settings-item advanced-setting" min="0" max="60" required="true">
                         <td class="settings-item-label"><span class="settings-item-label">Attached Pictures Time Span</span></td>
                         <td class="settings-item-value"><input type="text" class="number styled notifications camera-config" id="emailPictureTimeSpanEntry"><span class="settings-item-unit">seconds</span></td>
-                        <td><span class="help-mark" title="defines the picture search time interval to use when creating email attachments (higher values generate emails with more pictures at the cost of an increased notification delay)">?</span></td>
+                        <td><span class="help-mark" title="defines the picture search time interval to use when creating email attachments (higher values generate emails with more pictures at the cost of an increased notification delay); set to 0 to disable picture attachments">?</span></td>
                     </tr>
                     <tr class="settings-item advanced-setting">
                         <td colspan="100"><div class="settings-item-separator"></div></td>