From: Calin Crisan Date: Thu, 6 Aug 2015 17:47:40 +0000 (+0300) Subject: sendmail & eventrelay: more verbose logging X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=8a86a71bc130dbb27592999cefb9c805a7c8d05b;p=motioneye-debian sendmail & eventrelay: more verbose logging --- diff --git a/eventrelay.py b/eventrelay.py index ca3bb2d..42c02f3 100755 --- a/eventrelay.py +++ b/eventrelay.py @@ -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!') diff --git a/motioneye.py b/motioneye.py index 3dbde2d..27e005a 100755 --- a/motioneye.py +++ b/motioneye.py @@ -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) diff --git a/sendmail.py b/sendmail.py index 2539c06..4844c08 100755 --- a/sendmail.py +++ b/sendmail.py @@ -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 diff --git a/src/config.py b/src/config.py index d89bb42..a786efa 100644 --- a/src/config.py +++ b/src/config.py @@ -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 diff --git a/src/smbctl.py b/src/smbctl.py index dd67dea..12e4505 100644 --- a/src/smbctl.py +++ b/src/smbctl.py @@ -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() diff --git a/templates/main.html b/templates/main.html index ccaba8a..199e08f 100644 --- a/templates/main.html +++ b/templates/main.html @@ -656,7 +656,7 @@ Attached Pictures Time Span seconds - ? + ?