From 9856355486a9795003b5948abeea11883aa0260d Mon Sep 17 00:00:00 2001 From: Georgi Georgiev Date: Mon, 20 Jul 2020 22:17:28 +0300 Subject: [PATCH] Auto elog messages from RunControl Send automatic messages in the e-log when a run is started or stopped. The changes are not tested as we do not have a test bench. Please test before deploy --- RunControl/code/RunControlServer.py | 32 +++++++++++++++++++++++++++++ RunControl/code/elog_notify.py | 31 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 RunControl/code/elog_notify.py diff --git a/RunControl/code/RunControlServer.py b/RunControl/code/RunControlServer.py index 2ab6a1b9..9cd32d4e 100644 --- a/RunControl/code/RunControlServer.py +++ b/RunControl/code/RunControlServer.py @@ -8,6 +8,7 @@ from Run import Run from Logger import Logger from PadmeDB import PadmeDB +from elog_notify import ElogNotify class RunControlServer: @@ -27,6 +28,8 @@ def __init__(self,mode): self.lock_file = self.daq_dir+"/run/lock" self.lus_file = self.daq_dir+"/setup/last_used_setup" + self.elog = ElogNotify('http://padmesrv2.lnf.infn.it:8080/') + # Redefine print to send output to log file sys.stdout = Logger() sys.stderr = sys.stdout @@ -883,6 +886,19 @@ def start_run(self): # self.db.set_run_status(self.run.run_number,2) # Status 2: run started self.send_answer("run_started") + self.elog.log_message('Run', + Author='RunControl', + Subsystem='Run', + Category='General', + Subject='Started run %d'%self.run.run_number, + Text='\n'.join([ + 'New run started', + 'Run number: %d'%self.run.run_number, + 'Run type: %s'%self.run.run_type, + 'Run crew: %s'%self.run.run_user, + 'Run comment: %s'%self.run.run_comment_start, + ]) + ) # RunControl is now in "running" mode return "running" @@ -926,6 +942,22 @@ def terminate_run(self): self.run.stop() + self.elog.log_message('Run', + Author='RunControl', + Subsystem='Run', + Category='General', + Subject='Terminated run %d'%self.run.run_number, + Text='\n'.join([ + 'Run terminated', + 'Run number: %d'%self.run.run_number, + 'Run type: %s'%self.run.run_type, + 'Run crew: %s'%self.run.run_user, + 'Start message: %s'%self.run.run_comment_start, + 'Stop message: %s'%self.run.run_comment_stop, + ]) + ) + + # Run stop_daq procedure for each ADC board terminate_ok = True # Run stop_daq procedure for each ADC board diff --git a/RunControl/code/elog_notify.py b/RunControl/code/elog_notify.py new file mode 100644 index 00000000..65df6536 --- /dev/null +++ b/RunControl/code/elog_notify.py @@ -0,0 +1,31 @@ +import requests + +class ElogNotify: + def __init__(self, url): + self.url = url + def log_message(self, logbook, **kwargs): + print(kwargs) + fields = dict(kwargs) + fields.update(cmd='Submit') + try: + requests.post(self.url+logbook, files=fields, timeout=.00001) + except: + pass + + +if __name__ == '__main__': + elog = ElogNotify('http://127.0.0.1:8080/') + elog.log_message('Run', + Author='RunControl', + Subsystem='Run', + Category='General', + Subject='Terminated run %d'%209384092, + Text='\n'.join([ + 'Run terminated', + 'Run number: %d'%209384092, + 'Run type: %s'%'self.run.run_type', + 'Run crew: %s'%'self.run.run_user', + 'Start message: %s'%'self.run.run_comment_start', + 'Stop message: %s'%'self.run.run_comment_stop', + ]) + )