Skip to main content

Orchestrate Next Gen

Code Snippets

Code snippets are reusable blocks of Python code that you can create in Orchestrate. They can include loops or conditional statements. You can use them to create custom nodes such as custom actions and custom conditions in playbooks. You can create and save code snippets in two ways.

  • Create code snippets: You can create code snippets from the resource library and attach them to playbook workflows.

  • Save as code snippet: You can also save your custom code as a snippet for a custom action or custom condition node from a playbook workflow.

Analysts can utilize the centralized library of reusable code to save time and effort. This allows them to customize code pieces that are used in multiple playbook workflows from one location. To access the code snippet library, go to Main Menu > Resource Library > Code Snippets. To know the supported actions for managing the code snippets in the library, see Manage Code Snippets.

Create Code Snippet

You can create and reuse code snippets in custom action and custom condition nodes in playbooks.

Before you Start

Ensure that your user group has Create/Update Code Snippets permission.

Steps

To create a code snippet, follow these steps:

  1. From the main menu, go to Playbooks > Resource Library and select Code Snippets.

  2. Click Create Snippet and enter the following details:

    • Title: Enter a title for the code snippet. For example: Incident IDs. You can enter a maximum of 100 characters.

    • Description: Enter a brief description for the code snippet. You can enter a maximum of 200 characters.

    • Code: In Custom Code, write the custom code (python) which internally uses the following parameters, and click Save.

      Script Details

      • Import Statements: Imports the internal Python modules defined in Python Module Index and the external Python modules such as xmltodict==0.12.0, feedparser==6.0.4, and json2html==1.3.0.

      • def script_function: This is the default calling function that must not be modified.

      • Write your custom code here: Write the custom Python code here, as per the requirement.

      • Return: Define the return values, as per requirement.

        from datetime import date
        def script_function():
            today = date.today()
            return today

To know how to use code snippets in a playbook, see Action Nodes and Condition Node.

Manage Code Snippets

You can perform the following actions on code snippets:

  • Update: You can update the code snippets to modify their name, description, and custom code. Upon modifying a code snippet, the changes will be updated to all the playbooks that use the code snippet.

  • Search: You can search for a code snippet by its name.

  • Delete: You can delete code snippets that are not required or used in any playbooks.