Thank you, both. JSON string is indeed necessary.
Is there an intuitive way to debug pre-process scripts? I've added "log.debug('data')" and "log.info(object)" but not sure where to view this output if the incident does not get created.
Here's my workflow:
python script fetches 3rd party incidents on app-host via cron job -> creates Resilient Incident -> Rule triggers workflow if 'Hosts' field is not 'None' -> Workflow pre-process script parses 'incident.properties.hosts' and 1) adds each host to a new row in a Data Table, 2) passes parsed data as input to function for retrieving more data about the host.
Right now, the pre-process script fails with 'index out of range' and the incident does not get created (strange?) so there is no "Actions" menu available to see any output for workflows... Any recommendations?
------------------------------
Tom Prenderville
------------------------------
Original Message:
Sent: Fri June 04, 2021 08:09 AM
From: Ben Lurie
Subject: Pre/post process script import limitations (parsing lists, ast workaround?)
Just continuing from what Sean suggested....
It probably will be more effective if the data stored in the fields is a JSON string instead of python string representation of objects. That will give more flexibility in the long term.
Ben
------------------------------
Ben Lurie
Original Message:
Sent: Fri June 04, 2021 05:36 AM
From: Sean Mc Cann
Subject: Pre/post process script import limitations (parsing lists, ast workaround?)
Hi Tom,
What might help you is the json module which is one of the approved modules for use in Python 3 scripts
Here is an example of how you could use it to parse a list from a string.
# replace with incident.properties.hostsendpoints = '["endpoint1","endpoint2"]'import jsonparsed_list = json.loads(endpoints)log.info(parsed_list)
I found this answer https://stackoverflow.com/a/35461204 which notes you might have to replace single quotes with double quotes, but for your example that should not be needed.
------------------------------
Sean Mc Cann
Original Message:
Sent: Wed June 02, 2021 05:03 PM
From: Tom Prenderville
Subject: Pre/post process script import limitations (parsing lists, ast workaround?)
Is there a recommended workaround for not being able to import ast in any of the scripts?
Since Resilient cannot store lists in its fields, I'm looking for a straight-forward way to parse list literals for custom data tables.
I'm using the default "hosts" (incident.properties.hosts) field to store a list literal '["endpoint1","endpoint2"]' and need to parse this outside of function calls.
Is 're' the only import allowed for parsing?
------------------------------
Tom Prenderville
------------------------------