All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-AlarmWhenDiscountAndPriceExceedsThresholdInMultiZoneAndInstanceType

Last Updated:Sep 20, 2024

Template name

ACS-ECS-AlarmWhenDiscountAndPriceExceedsThresholdInMultiZoneAndInstanceType

Execute Now

Template description

Monitors the price or discount of the specified instance types in the specified zones and sends alert notifications if the price or discount exceeds the specified threshold.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

zoneId

The zone IDs.

List

Yes

instanceType

The instance types.

List

Yes

threshold

The discount or spot price threshold.

Number

Yes

webhook

The webhook URL of the DingTalk chatbot.

String

Yes

region

The region ID.

String

No

{{ ACS::RegionId }}

taskType

The type of the monitoring job.

String

No

Discount

rateControl

The rate control settings.

Json

No

{'Mode': 'Concurrency', 'MaxErrors': 100, 'Concurrency': 10}

OOSAssumeRole

The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS).

String

No

OOSServiceRole

Output parameters

Parameter

Description

Type

allThresholdInfo

Json

Permission policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeAvailableResource",
                "ecs:DescribeSpotPriceHistory"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

References

For more information, see ACS-ECS-AlarmWhenDiscountAndPriceExceedsThresholdInMultiZoneAndInstanceType.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Alarm when monitoring the discount and spot price of multi-instance types in multi-availability zone exceeding the threshold
  zh-cn: the description in Chinese
  name-en: ACS-ECS-AlarmWhenDiscountAndPriceExceedsThresholdInMultiZoneAndInstanceType
  name-zh-cn: the description in Chinese
  categories:
    - instance_manage
Parameters:
  region:
    Type: String
    Label:
      en: RegionId
      zh-cn: the description in Chinese
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  zoneId:
    Description:
      en: The zone id
      zh-cn: the description in Chinese
    Label:
      en: ZoneId
      zh-cn: the description in Chinese
    Type: List
    AssociationProperty: ALIYUN::ECS::Instance::ZoneId
    AssociationPropertyMetadata:
      RegionId: region
      AutoChangeType: false
  instanceType:
    Description:
      en: The instance type
      zh-cn: the description in Chinese
    Label:
      en: InstanceType
      zh-cn: the description in Chinese
    Type: List
    AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
    AssociationPropertyMetadata:
      Multiple: true
      RegionId: region
      ZoneIds: '${zoneId}'
  taskType:
    Description:
      en: The monitoring threshold task type (Discount: Monitor discount, Price: monitor price)
      zh-cn: the description in Chinese
    Label:
      en: TaskType
      zh-cn: the description in Chinese
    Type: String
    Default: Discount
    AllowedValues:
      - Discount
      - Price
  threshold:
    Description:
      en: 'The discount/price threshold(example:10 is 1% off,50 is 50% off,Or directly enter the price threshold).'
      zh-cn: the description in Chinese
    Label:
      en: Threshold
      zh-cn: the description in Chinese
    Type: Number
  webhook:
    Label:
      en: Webhook
      zh-cn: the description in Chinese
    Description:
      en: '(example:https://oapi.dingtalk.com/robot/send?access_token=bac51db2e39418ec6c2dbb27fd111bc7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx).'
      zh-cn: the description in Chinese '
    Type: String
  rateControl:
    Label:
      en: RateControl
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 100
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: the description in Chinese
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: alarmThresholdInfo
    Action: 'ACS::ECS::AlarmSpotPriceByDiscountThresholdWithMultiTypes'
    Description:
      en: Alarm when monitoring the discount and spot price of multi-instance types under multi-availability zone exceeding the threshold
      zh-cn: the description in Chinese
    Properties:
        regionId: '{{ region }}'
        zoneId: '{{ ACS::TaskLoopItem }}'
        instanceTypes: '{{ instanceType }}'
        threshold: '{{ threshold }}'
        taskType: '{{ taskType }}'
    Outputs:
      zoneInstanceTypeThresholdInfo:
        Type: Json
        ValueSelector: instanceTypeThresholdInfo
    Loop:
      Items: '{{ zoneId }}'
      RateControl: '{{ rateControl }}'
      Outputs:
        allThresholdInfos:
          AggregateField: zoneInstanceTypeThresholdInfo
          AggregateType: 'Fn::ListJoin'
  - Name: wetherNodifyWebhook
    Action: 'ACS::Choice'
    Description:
      en: Detect if an alarm notification is required
      zh-cn: the description in Chinese
    Properties:
      DefaultTask: alarmNotify
      Choices:
        - When:
            'Fn::Equals':
              - []
              - 'Fn::MergeList': '{{ alarmThresholdInfo.allThresholdInfos }}'
          NextTask: 'ACS::END'
  - Name: alarmNotify
    Action: 'ACS::Notify'
    Description:
      en: Instance discount / spot price exceeds threshold alarm notification
      zh-cn: the description in Chinese
    Properties:
      NotifyType: WebHook
      WebHook:
        URI: '{{ webhook }}'
        Headers:
          Content-Type: application/json
        Content:
          msgtype: markdown
          markdown:
            title: Monitoring results
            text:
              'Fn::Join':
                - ''
                - 'Fn::ListJoin':
                    - |
                      ##### The alert threshold (alarm threshold):{{ threshold }}
                    - |
                      | Instance type |  Zone|Ccurrent price|Discount|
                    - |
                      |:----|----:|:----:|:----|
                    - 'Fn::Jq':
                        - First
                        - '.[]|split(", ") | join("") |split("\n,")| join("")| split("\n,|")|join("") |split("||")|join("|")'
                        - 'Fn::Jq':
                            - All
                            - '.[1]=""|join("|")'
                            - 'Fn::Jq':
                                - All
                                - '.[1]=""| .[1]=.[0] | .[0]="" | join("|")'
                                - 'Fn::Jq':
                                    - All
                                    - map(.) | join("\n|")
                                    - 'Fn::Jq':
                                        - All
                                        - '.[] | map(.[] | tostring)| join(" |")'
                                        - 'Fn::Jq':
                                            - All
                                            - 'map(.| .threshold=.threshold+" |\n," )'
                                            - 'Fn::MergeList': '{{ alarmThresholdInfo.allThresholdInfos }}'
Outputs:
  allThresholdInfo:
    Type: Json
    Value:
      'Fn::Join':
        - ''
        - 'Fn::ListJoin':
            - |
              ##### The alert threshold (alarm threshold):{{ threshold }}
            - |
              | Instance type |  Zone|Ccurrent price|Discount|
            - |
              |:----|----:|:----:|:----|
            - 'Fn::Jq':
                - First
                - '.[]|split(", ") | join("") |split("\n,")| join("")| split("\n,|")|join("") |split("||")|join("|")'
                - 'Fn::Jq':
                    - All
                    - '.[1]=""|join("|")'
                    - 'Fn::Jq':
                        - All
                        - '.[1]=""| .[1]=.[0] | .[0]="" | join("|")'
                        - 'Fn::Jq':
                            - All
                            - map(.) | join("\n|")
                            - 'Fn::Jq':
                                - All
                                - '.[] | map(.[] | tostring)| join(" |")'
                                - 'Fn::Jq':
                                    - All
                                    - 'map(.| .threshold=.threshold+" |\n," )'
                                    - 'Fn::MergeList': '{{ alarmThresholdInfo.allThresholdInfos }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - region
          - zoneId
          - instanceType
          - taskType
          - threshold
          - webhook
        Label:
          default:
            zh-cn: the description in Chinese
            en: Configure Parameters
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: the description in Chinese
            en: Control Options