Creates a new Policy
- payload (PolicySchema): Required. The policy data to be created:
- name (str): A descriptive name for this policy.
- data_config: Configuration relevant to the retrieval of data for this policy:
for compare distribution policy:- query_a (Query): Cube.js query.
- query_b (Query): Cube.js query.
- query_a_time_range_config: (TimeRangeConfig or None): Time range configuration for query A.
- query_b_time_range_config: (TimeRangeConfig or None): Time range configuration for query B.
- distance_function (DistanceFunction): Distance function to use.
for statistics policy: - query (Query): Cube.js query.
- time_range_config: (TimeRangeConfig): Time range configuration for the query.
- cron_expression (str): Cron expression for policy evaluation.
- condition_above_value (float or None): Condition above value.
- condition_below_value (float or None): Condition below value.
- destination_ids (list of UUID): List of communication channels to get notified through.
- alert_on_status (AlertOnStatusDirection): Trigger policy action if the value is above/below.
- alert_on_policy_level (bool): Trigger policy action on a single group/entire groups.
- dataset_id (str): The dataset this policy is monitoring.
| Time | Status | User Agent | |
|---|---|---|---|
Retrieving recent requests… | |||
Creates a policy that monitors a dataset. A policy defines a metric, as a statistics query or a comparison of two distributions; a condition, as a static threshold or a moving average; how often it is evaluated; and where alerts are sent.
When to use it
Use it to detect issues automatically, such as a metric crossing a threshold or drifting from its history. To start from a predefined policy for an agent, use Create a policy from a template.
Required parameters
alert_on_policy_level(body): whether the policy action triggers on a single group or on the entire set of groups.name(body): a descriptive name for the policy.dataset_id(body): the ID of the dataset the policy monitors.destination_ids(body): the IDs of the destinations to notify.cron_expression(body): a cron expression that sets when the policy is evaluated.threshold_settings(body): the condition: a static threshold withcondition_above_valueorcondition_below_value, or a moving average withwindow_sizeandviolation_deviation.alert_on_status(body): when to alert:HEALTHY_TO_UNHEALTHY,UNHEALTHY_TO_HEALTHY, orBOTH.data_config(body): the metric: a statistics query with a time range, or a comparison of two distribution queries with a distance function.
Optional body fields: dataset_b_id, description, initialize_with_historic_data.
Response
A successful call returns 201 Created with the PolicyResponse object, including id, name, status, data_config, threshold_settings, cron_expression, destination_ids, last_evaluation, and next_evaluation.
Related: Create a policy from a template, List policies, Trigger a policy, Create a destination
422Unprocessable Entity
500Internal Server Error