Skip to main content

Cyware Orchestrate

Code Snippets

Notice

This feature is available in Orchestrate from the release version v3.5.0 and later.

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, do the following:

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

  2. Click Create Code Snippet and enter the title and description.

  3. 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 code here: Write the custom Python code here, as per the requirement.

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

      Example:

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

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

Manage Code Snippets

You can perform the following actions on code snippets:

  • 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.

  • You can search a code snippet by its name.

  • You can delete code snippets that are not used in any playbooks.