Custom Scripts

Custom Scripts are used with Rules and Policies to collect additional data or to respond to collected data. There are four types of Custom Scripts:

Scripts must export a single function that takes two parameters – “params” and “context”, and returns a value or a Promise for a value. The “params” are the parameters specified for the Custom Script (defined in the Custom Script Reference). The “context” is a global object that includes variables defined at the Cloud Account level and merged with data returned by Prerequisite Rules.

For detailed information and examples of each type of Custom Script, see the Custom Script Reference.

Working with Custom Scripts

Custom Script Reference

Retrieval Scripts

Retrieval Scripts used in Prerequisite Rules must return an object (key-value dictionary). Retrieval Scripts used in Primary Rules can return any type of value.

Policy Response Scripts

Policy Response scripts respond to a failing Policy Test to remediate that Test. These Custom Scripts can obtain the output of the failing Policy Test by accessing context.data.output.

Policy Response scripts can return any dict or list object. We recommend returning something that helps to identify more information about what occurred during the response.

Change Response Scripts

Change Response scripts are specified in Inventory Rules, and they run when the results returned by an Inventory Scan don't match the configuration specified in the Response. For example, a Change Response could be associated with an Inventory Rule that checks privacy settings for S3 buckets. If a Scan using that Rule detects that a bucket is no longer private, the Response script would revert the bucket's settings to ensure that it stays private.

Change Responses work by comparing the attribute values of Elements returned by a Rule to values specified in the script. If an Element's attribute value differs from the value in the script, the Response Script will execute.

Account Login Scripts

Account Login scripts can be used to create "Custom" Cloud Accounts to monitor SaaS services that CM does not currently support. When you create a Cloud Account and select "Custom" as the Account Type, you can select an Account Login script that will be used to access the service.

An Account Login script is the first thing that runs during the scan process. The return value is stored under the "login" key, which can then be used by other Rules to authenticate to APIs. Custom Accounts can generally only be monitored using Custom Rules or generic Rule Types like REST.