Develop your first custom action
In your first custom integration, you defined its parameters and created a Ping action to test the connection. This document guides you through how to create two new actions for your custom integration:
- Get Domain Details: Retrieves domain information and presents the result in JSON format.
- Enrich Entities: Enriches entities with domain details.
Create a custom action
To create a custom action, follow these steps:
- Go to the Integrated Development Environment (IDE) and click Add to add a new IDE item.
- Select Action.
- Name the action
Get Domain Detailsand select the integration. - Click Create. The IDE generates a new template with built-in code comments and explanations.
Configure action parameters
Based on the WHOIS XML API documentation, the Get Domain Details action requires two parameters: Check Availability and Domain Name. To configure these parameters, follow these steps:
- In the IDE module, click Add.
- Fill in the fields for Check Availability and click Save. This parameter indicates whether the domain is available, and its result is used in the automation that you create later.
- Fill in the fields for Domain Name and click Save. Use this field to enter the domain that you want the action to check.
Edit the Get Domain Details action
To edit the Get Domain Details action, follow these steps:
Copy the provided code for Get Domain Details, paste it into the IDE, and review the code. The object must use the class's
endmethod to return an output message and a result value:siemplify.end(msg, None)Extract the integration and action parameters. Integration parameters, such as
API Key, are extracted using thesiemplify.extract_configuration_paramfunction. Action parameters, such asDomain NameandCheck availability, are extracted using thesiemplify.extract_action_paramfunction:api_key = siemplify.extract_configuration_param( provider_name=INTEGRATION_NAME, param_name="API Key", ) url = f"https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey={api_key}&outputFormat=json" domain = siemplify.extract_action_param( param_name="Domain Name", print_value=True, ) availability_check = siemplify.extract_action_param( param_name="Check availability", is_mandatory=False, print_value=True, )Build the request and process the result:
- Build the request URL based on the boolean value of the
availability_checkparameter. - Send the request to the WHOIS API.
- Parse the response and add the relevant data to the action's result.
- Define the output message presented to the user and include the JSON result:
# Add domain to scan url = f"{url}&domainName={domain}" # Determine availability check if availability_check.lower() == "true": availability_check_qs = 1 else: availability_check_qs = 0 url = f"{url}&da={availability_check_qs}" response = requests.get(url) response.raise_for_status() # Add a JSON result that can be used in the next steps of the playbook siemplify.result.add_result_json(response.json()) # Add the JSON to the action result presented in the context details siemplify.result.add_json("WhoisDetails", response.json()) msg = f"Fetched data for {domain}" siemplify.end(msg, None) if __name__ == "__main__": main()- Build the request URL based on the boolean value of the
Add a JSON result to the action
As part of the Get Domain Details action, add a JSON sample so that you can extract specific fields in the playbook designer during the Create your first automation procedure:
- Copy the JSON from the WHOIS site's JSON example.
- In the Details tab of the IDE, enable the Include JSON Result toggle to display the JSON icon at the top of the IDE.
- Click file_json Manage JSON Sample > login Import JSON Example.
Test the action
To test the action that you created, follow these steps:
- Go to the Testing tab.
- In the Scope field, select your Test Case and Integration Instance.
- Click slideshow Play in the IDE.
- View the action's result in the Testing tab. After the test finishes, you can also review the logs and output in the Debug Output tab.
Create a test case
If you don't have any test cases in your environment, follow these steps to create one:
- Go to the Cases page and select a case.
- Select Ingest alert as test case. This action creates a new case with a Test label in your case queue.
- Return to the IDE and select the test case from the list.
Create an enrichment action
This section explains how to create an enrichment action to add new data to entities. You can view the enriched data in the Entity Explorer. To create an enrichment action, follow these steps:
- In the IDE, create a new action and name it
Enrich Entities. Copy and paste the following code into the action:
from SiemplifyAction import SiemplifyAction from SiemplifyDataModel import EntityTypes from SiemplifyUtils import output_handler import requests # Example constants INTEGRATION_NAME = "My first Integration - Whois XML API" SCRIPT_NAME = "WHOIS XML API EnrichEntities" @output_handler def main(): siemplify = SiemplifyAction() siemplify.script_name = SCRIPT_NAME siemplify.LOGGER.info("================= Main - Param Init =================") api_key = siemplify.extract_configuration_param( provider_name=INTEGRATION_NAME, param_name="API Key", ) url = f"https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey={api_key}&outputFormat=json" siemplify.LOGGER.info("----------------- Main - Started -----------------") # Human-readable message shown in the UI as the action result output_message = "output message :" # Collect successful entity identifiers successful_entities = [] for entity in siemplify.target_entities: siemplify.LOGGER.info(f"processing entity {entity.identifier}") if ( entity.entity_type == EntityTypes.HOSTNAME and not entity.is_internal ) or entity.entity_type == EntityTypes.URL: entity_to_scan = entity.identifier scan_url = f"{url}&domainName={entity_to_scan}" response = requests.get(scan_url) response.raise_for_status() register_details = ( response.json().get("WhoisRecord", {}).get("registrant", {}) ) if register_details: entity.additional_properties.update(register_details) successful_entities.append(entity) if successful_entities: output_message += "\n Successfully processed entities:\n {}".format( "\n ".join([x.identifier for x in successful_entities]) ) # Send the enriched entity data back to the server siemplify.update_entities(successful_entities) else: output_message += "\n No entities were processed." result_value = len(successful_entities) siemplify.LOGGER.info("----------------- Main - Finished -----------------") siemplify.end(output_message, result_value) if __name__ == "__main__": main()Extract the configuration parameters. The script extracts the
API Keyparameter from the integration's configuration to authenticate requests to the WHOIS XML API.Identify the target entities to process. The script iterates through
siemplify.target_entitiesand processes only the following entity types:- Non-internal hostnames
- URLs
for entity in siemplify.target_entities: siemplify.LOGGER.info(f"processing entity {entity.identifier}") if ( entity.entity_type == EntityTypes.HOSTNAME and not entity.is_internal ) or entity.entity_type == EntityTypes.URL: entity_to_scan = entity.identifierScan the domain and define the enrichment step and output message. Because this action runs on an Entity scope, you don't need to configure separate action parameters:
scan_url = f"{url}&domainName={entity_to_scan}" response = requests.get(scan_url) response.raise_for_status() register_details = ( response.json().get("WhoisRecord", {}).get("registrant", {}) ) if register_details: entity.additional_properties.update(register_details) successful_entities.append(entity) if successful_entities: output_message += "\n Successfully processed entities:\n {}".format( "\n ".join([x.identifier for x in successful_entities]) ) # Send the enriched entity data back to the server siemplify.update_entities(successful_entities) else: output_message += "\n No entities were processed." result_value = len(successful_entities)Enable the action and click Save. You now have a custom integration with the following custom actions:
- Ping: Tests the connection to the WHOIS XML API product.
- Get Domain Details: Extracts data about a domain and presents it as a JSON result.
- Enrich Entities: Adds registrant data to target entities, which you can view in Entity Explorer.
You're now ready to create your first automation using the actions that you customized.
Need more help? Get answers from Community members and Google SecOps professionals.