System Configuration Editor: Error Settings

Hello everyone,

I am a fairly new Hamilton (Venus) user. I am interested in using the built-in error settings to use ‘Execute Program’ that activates a .exe file which activates a script to notify me of an error as I mainly work from behind my desk.

When I was testing this function it seemed like it was not working correctly. It would only activate the .exe file once I acknowledged an error by clicking on ‘continue’ as far as I remember.
Am I doing something wrong perhaps? I would expect the .exe to fire once an error occurs.

Would anybody be so kind to help me out?

Cheers,
Ed

@Ediagnostics - That feature is designed to run the executable as soon as the error is generated and the waiting recovery window appears. Perhaps there was a lag in the network that delayed delivery of the custom notification that was scripted?

If you run the script outside of run control, from the same PC, is the response immediate?

-Nick

Hey Nick,

Thanks for the fast reply. When I run the .exe/script outside of run control it is immediately run. I remember one time I left the Hamilton to run overnight and once I booted up the computer the script ran as well, but from what I remember it was after clicking on continue.
I will be able to test again next week and I expect and hope that you are probably right. Thanks!

-Ed

1 Like

Bumping this up since it’s relevant to my question (without the need to make another topic) but how does “Program Arguments” exactly work? Like where are the arguments being pulled from to pass into the program file?

1 Like

Hi Nat,

If you are using a custom script that requires arguments, you would paste the argument string into that field, which would be used when the script is run. This configuration location is where the arguments are pulled from at runtime.

The field allows you to type or paste in whatever argument string is needed. The string would be known to the author of the script.

Thanks.

-Nick

2 Likes

Hi there,

I am experiencing a similar issue. I created a little executable to send emails and write a log file, once an error occurs. When running the executable manually or when starting it from the command line, everything works fine. However, not when an error occurs during the method. Do you have any idea what could cause this behaviour?
I used to run a similar executable in my previous job on another Hamilton system, and it was working fine. Could it be related to certain Venus versions?

Hi @DonIgor

Do you have a run trace from an attempt at using the email on error configuration feature? This would confirm if the configuration is setup correctly, as the run trace captures when a waiting-error event triggers the error script execution.

Besides that, I would check any permissions from the folder(s) in which the .exe is saved on the PC’s drive, ensuring that applications and users have full access to the contents of the folder. You could also try running run control as administrator and see if that makes a difference.

Thanks.

-Nick

Dear NIck,

thanks a lot for your help. I was finally able to figure out why my executable did not run. The executable uses a configuration .json file, in which you can define the details for the email (sender, recipient, server, …). I programmed it in such a way that it will look for the configuration file in the working directory - thinking that this would be the working directory of the .executable in all cases. However, when the executable is called from Venus, the working directory is the place where the .med file is located. After changing this piece of code, my script can finally find the configuration file and send the email.

Thanks a lot for taking the time to respond and help.

Best,
Greg

PS: I learned that Hamilton uses a similar executable called “MailAlert.exe” to send error mails. However, I could not get it configured to work with our company mail account. If anyone is interested in getting the code for the script, just drop me a message.

2 Likes

Hi Donlgor,

I saw the post about Hamilton Venus email alert configuration setting post where you made an executable to send emails on errors. I’m really interested to see the code and ask you questions about setting up email feature on Hamilton. My company is working to implement tracking/logging/reporting on Hamilton runs so would love to learn and hear from you

Thank you!
Kenny

1 Like

Hi Kenny,

sure I can share the code of my app. It is written in Python - please see below. The app is then compiled as an executable using “pyinstaller”. Feel free to use this code and to ask any questions.

Cheers,
Greg

PS: I should probably get a public git account, but I guess this will do for now…

#import required packages
import os
import json
import smtplib
from email.message import EmailMessage
from datetime import datetime
import argparse #for parsing commandline arguments
import sys

def WriteLogAndPrintMessage(LogText, LogPath):
    # datetime object containing current date and time
    now = datetime.now()
    date_string = now.strftime("%Y_%m_%d")
    datetime_string = now.strftime("%d/%m/%Y %H:%M:%S")
    log_filepath = LogPath + "\\" + date_string + '_MailNotification.log'
    if os.path.isfile(log_filepath) and os.access(log_filepath, os.R_OK):
        #append in case file exists already
        f = open(log_filepath, 'a')
    else:
        #create new file if log file does not exist already
        f = open(log_filepath, 'x')
    f.write(datetime_string + " " + LogText + "\n")
    f.close
    print(datetime_string + " " + LogText)


#Extract filepath of where .EXE file is located, such that we can write the log file into the same folder.
executable_filepath = os.path.dirname(sys.executable)
#Create default configuration filepath, for cases were configuration file path is not specified by user. In this case the configuration file has to be inside of the same folder as the executable.
default_configuration_filepath = executable_filepath + "\\" + 'MailNotificationConfiguration.json'

#Argument parser
parser = argparse.ArgumentParser(prog='MailNotification_V1.exe',description='Upon execution of this program an email notification (e.g. error mail) is sent according to the configuration file \"MailNotificationConfiguration.json\", which should be present in the same folder or specified as an additional argument to the function.', epilog='Written by Gregor W. Schmidt in Dezember 2024.')
parser.add_argument('--version', action='version', version='V1')
parser.add_argument('--configpath', action="store", type=str, help='Fully specified path to the .JSON configuration file.', default=default_configuration_filepath)
parsedArguments = parser.parse_args()

#Extract parsed file path argument
config_filepath = str(parsedArguments.configpath)

#Check if config file exists and send email according to configuration
if os.path.isfile(config_filepath) and os.access(config_filepath, os.R_OK):
    # open .json file an read config data
    with open(config_filepath, 'r') as file:
        configuration_data = json.load(file)
    #define server connection
    host = configuration_data["smtp_server"]
    server = smtplib.SMTP(host)
    #define mail message depending on JSON configuration file
    msg = EmailMessage()
    msg['Subject'] = configuration_data["message_subject"]
    msg['From'] = configuration_data["sender_address"]
    msg['To'] = configuration_data["recipients"]
    msg.set_content(configuration_data["message_body"])
    #send message and close server connection
    server.send_message(msg)
    server.quit()
    WriteLogAndPrintMessage("Error mail send to " + ' and '.join(configuration_data["recipients"]) + ". Error message subject: " + configuration_data["message_subject"] + ". Error message body: " + configuration_data["message_body"], executable_filepath)
else:
    WriteLogAndPrintMessage("Configuration file (" + config_filepath + ") not present at specified location or not readable.", executable_filepath)

2 Likes

Thank you so much! Really appreciate it.