diff --git a/.gitignore b/.gitignore index 164df35f..c6cac56f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ testsBP/*/*.a wally-pipelined/linux-testgen/linux-testvectors/* !wally-pipelined/linux-testgen/linux-testvectors/tvCopier.py !wally-pipelined/linux-testgen/linux-testvectors/tvLinker.sh +wally-pipelined/regression/slack-notifier/slack-webhook-url.txt + diff --git a/wally-pipelined/regression/slack-notifier/slack-notifier.py b/wally-pipelined/regression/slack-notifier/slack-notifier.py new file mode 100755 index 00000000..93493267 --- /dev/null +++ b/wally-pipelined/regression/slack-notifier/slack-notifier.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 +import os,sys,subprocess +from datetime import datetime, timezone, timedelta + +if not os.path.isfile(sys.path[0]+'/slack-webhook-url.txt'): + print('==============================================================') + print(' HOWDY! ') + print('slack-notifier.py can help let you know when your sim is done.') + print('To make it work, please supply your Slack bot webhook URL in:') + print(sys.path[0]+'/slack-webhook-url.txt') + print('Ask Ben for the Tera Slack Notifier Tutorial for more details.') + print('==============================================================') +else: + urlFile = open(sys.path[0]+'/slack-webhook-url.txt','r') + url = urlFile.readline().strip('\n') + + # Traverse 3 parents up the process tree + result = subprocess.check_output('ps -o ppid -p $PPID',shell=True) + PPID2 = str(result).split('\\n')[1] + result = subprocess.check_output('ps -o ppid -p '+PPID2,shell=True) + PPID3 = str(result).split('\\n')[1] + # Get command name + result = subprocess.check_output('ps -o cmd -p '+PPID3,shell=True) + cmdName = str(result).split('\\n')[1] + # Get current time + timezone_offset = -8.0 # Pacific Standard Time (UTC−08:00) + tzinfo = timezone(timedelta(hours=timezone_offset)) + time = datetime.now(tzinfo).strftime('%I:%M %p') + # Send message + message = 'Command `'+cmdName+'` completed at '+time+' PST' + result = subprocess.run('curl -X POST -H \'Content-type: application/json\' --data \'{"text":"'+message+'"}\' '+url,shell=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) + print('Simulation stopped. Sending Slack message.') diff --git a/wally-pipelined/regression/wally-buildroot-batch.do b/wally-pipelined/regression/wally-buildroot-batch.do index 6eea258e..c16655e1 100644 --- a/wally-pipelined/regression/wally-buildroot-batch.do +++ b/wally-pipelined/regression/wally-buildroot-batch.do @@ -36,4 +36,5 @@ vsim workopt -suppress 8852,12070 run -all run -all +exec ./slack-notifier/slack-notifier.py quit diff --git a/wally-pipelined/regression/wally-buildroot.do b/wally-pipelined/regression/wally-buildroot.do index c2312f75..452ba54d 100644 --- a/wally-pipelined/regression/wally-buildroot.do +++ b/wally-pipelined/regression/wally-buildroot.do @@ -39,4 +39,5 @@ vsim workopt -suppress 8852,12070 run -all do ./wave-dos/linux-waves.do run -all +exec ./slack-notifier/slack-notifier.py ##quit diff --git a/wally-pipelined/regression/wally-busybear-batch.do b/wally-pipelined/regression/wally-busybear-batch.do index a4a80eb7..e819d780 100644 --- a/wally-pipelined/regression/wally-busybear-batch.do +++ b/wally-pipelined/regression/wally-busybear-batch.do @@ -36,4 +36,5 @@ vopt work_busybear.testbench -o workopt_busybear vsim workopt_busybear -suppress 8852,12070 run -all +exec ./slack-notifier/slack-notifier.py quit diff --git a/wally-pipelined/regression/wally-busybear.do b/wally-pipelined/regression/wally-busybear.do index 11876dde..8d6af28b 100644 --- a/wally-pipelined/regression/wally-busybear.do +++ b/wally-pipelined/regression/wally-busybear.do @@ -40,4 +40,5 @@ do ./wave-dos/linux-waves.do #-- Run the Simulation run -all +exec ./slack-notifier/slack-notifier.py ##quit