All ThreatConnect ™ Exchange Apps should deliberately exit with the appropriate exit code on successful or failed execution. The
TcEx Framework provides the
exit_code property to handle exit codes. All Apps should end with the
exit() method supports and optional
msg parameter. If provided the
msg value will be logged and written to the
message_tc file as the App exit message.
Providing a proper exit code for Playbook Apps is important for execution of downstream Apps.
Setting Exit Code¶
Some failures do not warrant an immediate exit. In such case the
exit_code property allows an exit code to be set for when the
exit() method is called. This allows the app to continue execution and still notify the ThreatConnect Platform that a failure occurred.
1 2 3 4 5 6 7 8 9 10 11 12
tcex = TcEx() <...snipped> try: with open(datafile, 'r') as fh: data = fh.read() except: tcex.exit_code = 3 <snipped...> tcex.exit(msg='My App message')
Immediate Exit on Failure¶
Certain failures require that the App exit immediately. In these cases calling the
exit() method while passing the exit code will immediately halt execution of the App and notify the ThreatConnect Platform of a failure.
1 2 3 4 5 6 7 8 9 10
tcex = TcEx() <...snipped> try: with open(datafile, 'r') as fh: data = fh.read() except: tcex.exit(1, 'App failed') <snipped...>
Supported Exit Codes¶
- 0 - Successful execution of App
- 1 - Failed execution of App
- 3 - Partial failure of App