Modifying a Policy
Function
This API is used to modify a policy.
Alarm policies can be modified, but scheduled and periodic policies cannot.
Request
Request headers
Table 2 describes the request headers.
| Parameter | Description | Mandatory | Example |
|---|---|---|---|
| Content-Type | Content type, which is application/json;charset=utf-8. | Yes | application/json;charset=utf-8 |
| Cluster-Id | Cluster ID. | Yes | - |
| Namespace | Namespace. | Yes | - |
| Deployment-Name | Application name. | Yes | - |
Request parameters
Table 3 describes the request parameters.
| Parameter | Mandatory | Type | Value Range | Description |
|---|---|---|---|---|
| id | Yes | String | - | Policy ID. |
| name | Yes | String | The value must be 1 to 64 characters starting with a letter. Only digits, letters, underscores (_), and hyphens (-) are allowed. | Policy name, which cannot be modified. |
| policy_type | Yes | String | ALARM | Policy type. Currently, only ALARM policies are supported. |
| rule | Yes | See Table 4. | - | Policy trigger rule. |
| Parameter | Mandatory | Type | Value Range | Description |
|---|---|---|---|---|
| conditions | Yes | See Table 5. | 1–5 | Condition contents. A rule can contain multiple conditions in AND relationships. One condition describes the matching method of one metric. |
| actions | Yes | See Table 6. | 1–5 | Action executed after a specified policy is successfully matched. |
| Parameter | Mandatory | Type | Value Range | Description |
|---|---|---|---|---|
| metric_namespace | Yes | String |
| Metric namespace. |
| metric_name | Yes | String | The value must be 1 to 255 characters long and meet the [a-zA-Z_:][a-zA-Z0-9_:]* expression. That is, the value must start with a letter, underscore (_), or colon (:). Only letters, digits, underscores, and colons are allowed. | Metric name. |
| metric_unit | Yes | String | - | Unit. NOTE: The value is retrieved from an AMS API and varies with the metric name. |
| period | Yes | Integer | 20, 60, 300, 900, 1800, or 3600 | Statistical period (unit: s). |
| evaluation_periods | Yes | Integer | 1, 2, 3, 4, or 5 | Number of consecutive periods. |
| statistic | Yes | String | Currently, only average is supported. | Statistic. |
| metric_operation | Yes | String | > and <. For example, you can use > in a threshold criterion (when the value of a metric is greater than metric_thresholdUpdate) to trigger actions. | Metric operator. |
| metric_threshold | Yes | Float | [0, 2147483647] | Threshold criterion. |
| Parameter | Mandatory | Type | Value Range | Description |
|---|---|---|---|---|
| type | Yes | String |
|
NOTE: The value containing k8s indicates a container application and that containing vm indicates a process application. |
| parameters | Yes | See Table 7. | - | Number of scale-in or -out instances. |
| Parameter | Mandatory | Type | Value Range | Description |
|---|---|---|---|---|
| scale_unit | Yes | Integer | Minimum number of instances to the maximum number of instances in a policy group. | Number of scale-in or -out instances. |
Example request
Example of an alarm policy
{
"id" : "5c2eecea-32ac-42c0-be30-f73b15d68429",
"name" : "policy_1",
"policy_type" : "ALARM",
"rule" : {
"conditions" : [{
"metric_namespace" : "PAAS.CONTAINER",
"metric_name" : "cpuUsage",
"metric_unit" : "Percent",
"period" : 60,
"evaluation_periods" : 1,
"statistic" : "average",
"metric_operation" : ">",
"metric_threshold" : 70
}
],
"actions" : [{
"type" : "scale_out_k8s",
"parameters" : {
"scale_unit" : 1
}
}
]
}
} Response
Response parameters
Table 8 describes the response parameters.
| Parameter | Type | Description |
|---|---|---|
| errorCode | String | Error code. |
| errorMessage | String | Error details. |
| context | String | Details about a modified policy. |
Example response
{
"errorCode": 0,
"errorMessage": "",
"context": {
"id" : "5c2eecea-32ac-42c0-be30-f73b15d68429",
"name" : "policy_1",
"policy_type" : "ALARM",
"rule" : {
"conditions" : [{
"metric_namespace" : "PAAS.CONTAINER",
"metric_name" : "cpuUsage",
"metric_unit" : "Percent",
"period" : 60,
"evaluation_periods" : 1,
"statistic" : "average",
"metric_operation" : ">",
"metric_threshold" : 70
}
],
"actions" : [{
"type" : "scale_out_k8s",
"parameters" : {
"scale_unit" : 1
}
}
]
}
}
} Error Code
| Error Code | Message | Solution |
|---|---|---|
| SVCSTG.PE.4001101 | Invalid parameter. | Check whether the parameter meets requirements. |
| SVCSTG.PE.4031012 | Failed to verify the project ID. | Check whether the parameter meets requirements. |
| SVCSTG.PE.4033008 | Failed to update the scheduled or periodic policy. | Check whether the parameter meets requirements. |
| SVCSTG.PE.5001201 | Failed to insert or update data in the background. | Contact the administrator. |
| SVCSTG.PE.5001203 | Query error. | Contact the administrator. |
| SVCSTG.PE.5003007 | Failed to update the threshold rule. | Contact the administrator. |
Last Article: Deleting a Policy
Next Article: Querying a Policy List
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.