From 4a68111ad679c7709edda708bf2942a9523cc1d1 Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Fri, 19 Oct 2018 16:04:34 +0300 Subject: [PATCH] events: add simple notifications handler --- pupy/triggers/notification.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pupy/triggers/notification.py diff --git a/pupy/triggers/notification.py b/pupy/triggers/notification.py new file mode 100644 index 00000000..a82ad07e --- /dev/null +++ b/pupy/triggers/notification.py @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- + +IGNORED_EVENTS = ( + 'start', 'exit', 'connect', 'disconnect', 'job completed' +) + +import datetime + +def execute(event_name, client, server, handler, config, **kwargs): + if event_name in IGNORED_EVENTS: + return + + client_id = '' + if 'id' in kwargs: + client_id = 'client {}'.format(kwargs['id']) + elif 'sid' in kwargs: + client_id = 'session {:08x}'.format(kwargs['sid']) + elif 'node' in kwargs: + client_id = 'node {:12x}'.format(kwargs['node']) + + server.info('Event ({}): {} ({})'.format( + datetime.datetime.now(), event_name, client_id))