Receiving Alarm Notifications Using Functions
If existing notification channels (email, SMS, voice notification, Lark, DingTalk, and WeCom) of Cloud Eye cannot meet your requirements, you can use FunctionGraph to compile code for more customized requirements.
In some regions, recipients are now called contacts, and notification groups are now contact groups. The changes will be available in other regions soon. For details, see the console.
Prerequisites
You have enabled FunctionGraph. For details, see Process of Using FunctionGraph.
Scenarios
- Use FunctionGraph to process the format of alarm notifications so that tools other than Cloud Eye notification channels can receive alarm notifications.
- Use FunctionGraph to customize the alarm notification content of Cloud Eye.
Creating a Function with FunctionGraph
- Log in to the FunctionGraph console.
- In the navigation pane, choose Functions > Function List.
- In the upper right corner, click Create Function.
- On the displayed page, set Create With to Create from scratch and Function Type to Event Function, and enter a function name. Select Python 3.9 for Runtime, and retain the default values for other parameters.
For details about the parameters for creating a function, see Creating an Event Function.
Figure 1 Creating a function
- After the configuration is complete, click Create Function.
The function details page is displayed, and a new function is added.
- On the function details page, insert the required custom fields and other parameters in the code source. The following is an example:
- The alarm notification type is metric.
- The alarm receiving mode is URL, and the URL is http://10.181.139.219:5000/callback.
- Notification content fields include AlarmRecordID, AlarmTime, and AlarmLevel. Fields in alarm notifications received through functions are defined by system templates. For details about the supported field structures, see Notification Content Supported by Metric Alarms and Notification Content Supported by Event Alarms. You can adjust the fields as required.
# -*- coding:utf-8 -*- import json import requests def handler(event, context): record = event["record"][0] smn = record['smn'] message_str = smn['message'] message = json.loads(message_str) template_variable = message['template_variable'] AlarmRecordID = message['AlarmRecordID'] AlarmTime = template_variable['AlarmTime'] AlarmLevel = template_variable['AlarmLevel'] Source = 'Huawei' NewEvent = { "AlarmRecordID": AlarmRecordID, "AlarmTime": AlarmTime, "AlarmLevel": AlarmLevel, "Source": Source } print(NewEvent) URL = 'http://10.181.139.219:5000/callback' r = requests.post(URL, json=NewEvent) return { "statusCode": 200, "isBase64Encoded": False, "body": json.dumps(NewEvent), "headers": { "Content-Type": "application/json" } } - Click Deploy to complete the deployment.
Creating a Contact
- Log in to the Cloud Eye console.
- In the navigation pane, choose Alarm Management > Alarm Notifications.
- Click the Contacts tab, click Create, and set parameters as prompted. Figure 2 Creating a contact
Table 1 Creating a contact Parameter
Example Value
Description
Contact Name
notification_functiongraph
Contact name. Enter 1 to 42 characters.
Protocol
FunctionGraph (function)
Channel through which the contact receives alarm notifications. If you select FunctionGraph (function), select the corresponding function and version.
- Function: Click the function text box. In the displayed dialog box, select the function configured in Creating a Function with FunctionGraph.
- Version: After you select a function, the function endpoint address and version numbers are displayed on the page. Manually select a version.
- Click Create.
A contact named notification_functiongraph is added to the contact list.
Creating a Contact Group
- Log in to the Cloud Eye console.
- In the navigation pane, choose Alarm Management > Alarm Notifications.
- Click the Contact Groups tab, click Create, and set parameters as prompted. Figure 3 Creating a contact group
Table 2 Parameter
Example Value
Definition
Group
group_functiongraph
Contact group name. Use only letters, digits, underscores (_), and hyphens (-). Enter up to 64 characters.
Enterprise Project
default
Enterprise project to which the contact group belongs. Only users with the enterprise project permissions can view and manage the contact group. For details about how to create an enterprise project, see Creating an Enterprise Project.
Contact
notification_functiongraph
Select the contacts you have added. A maximum of 10 contacts can be added at a time.
Click Select Contact. On the displayed page, select the created contact and click
to add it to the selected list. Then, click OK. - Click Create.
A contact group named group_functiongraph is added to the contact group list.
You can also add the contact to a created contact group. For details, see Adding Contacts to a Contact Group. If you want to receive alarm notifications through an alarm policy, you can select the contact group as the recipient when configuring the alarm policy. For details, see Creating a Notification Policy.
Creating an Alarm Rule
- Log in to the Cloud Eye console.
- In the navigation pane, choose Alarm Management > Rule Settings.
In some regions, the path is Alarm Management > Alarm Rules.
- Click Create Alarm Rule.
- On the displayed page, configure the basic information, alarm content, alarm policy, and alarm notification for the alarm rule. Set Notified By to Contact groups and select group_functiongraph created in Creating a Contact Group.
For details about alarm rule parameters, see Creating an Alarm Rule and Notifications.
- Click Create.
Viewing Alarm Notifications
When a monitored metric triggers the alarm rule, the target function is called to send an alarm notification to the notification recipient.
You can also view the call logs of the target function on the FunctionGraph console and check whether the logs meet your expectations. For details, see Configuring and Viewing Function Invocation Logs.
Notification Content Supported by Metric Alarms
The following uses the CPU usage of an ECS as an example to describe the field structure supported by metric alarms.
If you have any questions about the fields in the alarm notification content, create a service ticket to contact technical support.
{
"message_type": "alarm",
"alarm_id": "al260512T094501SwVt7****",
"alarm_name": "alarm-****",
"alarm_status": "alarm",
"time": 1778550457194,
"namespace": "SYS.ECS",
"metric_name": "cpu_util",
"dimension": "instance_id:6b42c3f4-666d-409c-afe7-c16268d7****",
"period": 1,
"filter": "Raw data",
"comparison_operator": "\u003e=",
"value": 10,
"unit": "%",
"count": 1,
"alarmValue": [{
"time": 1778550457000,
"value": 0.037267080745341616
}],
"sms_content": "[CN North-Beijing4 (cn-north-4)][Enterprise Project: default][Major alarm] ***, the raw data of the CPU usage of ECS as-config-**** (private IP address: 192.168.X.X; resource ID: 6b42c3f4-666d-409c-afe7-c16268d7****) is greater than or equal to 10% for one consecutive time.\nDimension Details: CPU usage: ECS: 6b42c3f4-666d-409c-afe7-c16268d70da1\nCurrent Data: 0.04%\nAn alarm was triggered on May 12, 2026 09:47:37 (GMT+08:00). Alarm Record ID: ah260512T094737SSSej****. Alarm Rule Name: alarm-****. Alarm Type: Metric. For details, visit the Cloud Eye console.\n",
"default_content": "[CN North-Beijing4 (cn-north-4)][Enterprise Project: default][Major alarm] ***, the raw data of the CPU usage of ECS as-config-**** (private IP address: 192.168.X.X; resource ID: 6b42c3f4-666d-409c-afe7-c16268d7****) is greater than or equal to 10% for one consecutive time.\nDimension Details: CPU usage: ECS: 6b42c3f4-666d-409c-afe7-c16268d7****\nCurrent Data: 10.04%\nAn alarm was triggered on May 12, 2026 09:47:37 (GMT+08:00). Alarm Record ID: ah260512T094737SSSe****. Alarm Rule Name: alarm-****. Alarm Type: Metric. For details, visit the Cloud Eye console.\n",
"template_variable": {
"AlarmNotificationType": "Metric",
"AccountName": "***",
"Namespace": "Elastic Cloud Server",
"DimensionName": "ECSs,"
"ResourceName": "as-config-****",
"ResourceTags": "11=22",
"MetricName": "CPU Usage",
"IsAlarm": true,
"IsCycleTrigger": false,
"AlarmLevel": "Major",
"Region": "CN North-Beijing4",
"RegionId": "cn-north-4",
"ResourceId": "6b42c3f4-666d-409c-afe7-c16268d7****",
"PrivateIp": "192.168.X.X",
"CurrentData": "10.04 %",
"AlarmTime": "2026/05/12 09:47:37 GMT+08:00",
"DataPoint": {
"2026/05/12 09:47:37 GMT+08:00": "10.04 %"
},
"DataPointTime": ["2026/05/12 09:47:37 GMT+08:00"],
"AlarmDurationTime": "0",
"AlarmRecordID": "ah260512T094737SSSej****",
"AlarmRuleName": "alarm-****",
"AlarmId": "al260512T094501SwVt7****",
"MonitoringRange": "All resources",
"IsOriginalValue": true,
"Filter": "Raw data",
"ComparisonOperator": "\u003e=",
"Value": "10 %",
"Unit": "%",
"Count": 1,
"Link": "https://console.huaweicloud.com/ces/?region=cn-north-4#/alarm/histories?alarmRecordId=ah260512T094737SSSej****",
"EpName": "default",
"IsIEC": false,
"IsAgentEvent": false,
"ShowImpactAndSolution": false,
"ResourceDimensionInfos": [{
"MetricName": "CPU Usage",
"DimensionInfos": [{
"Name": "ECS,"
"Value": "6b42c3f4-666d-409c-afe7-c16268d7****"
}]
}]
},
"AlarmRecordID": "ah260512T094737SSSej****"
} Notification Content Supported by Event Alarms
The following uses restarting an ECS as an example to describe the field structure supported by event alarms:
If you have any questions about the fields in the alarm notification content, create a service ticket to contact technical support.
{
"message_type": "alarm",
"alarm_id": "al260514T104252SVeqi****",
"alarm_name": "alarm-8***",
"alarm_status": "alarm",
"time": 1778726924655,
"namespace": "SYS.ECS",
"metric_name": "rebootServer",
"dimension": "instance_id:095b058c-ae86-4544-b3b9-6dd4583a****",
"period": 0,
"filter": "average",
"comparison_operator": "\\u003e=",
"value": 1,
"unit": "count",
"count": 1,
"alarmValue": [{
"time": 1778726607943,
"value": 1
}],
"sms_content": "[CN North-Beijing4 (cn-north-4)][Enterprise Project: default][Major alarm] ***, an alarm was triggered on May 14, 2026 10:48:44 (GMT+08:00) for the VM restart of ECS ecs-*** (private IP address: 192.168.X.X; ID: 095b058c-ae86-4544-b3b9-6dd4583a****). Alarm Record ID: ah260514T104844Shz0J****; Alarm Rule Name: alarm-8***; Alarm Type: Event; Impact: The VM is restarted. Solution: Check whether services are recovered. For details, visit the Cloud Eye console."
"default_content": "[CN North-Beijing4 (cn-north-4)][Enterprise Project: default][Major alarm] ***, an alarm was triggered on May 14, 2026 10:48:44 (GMT+08:00) for the VM restart of ECS ecs-*** (private IP address: 192.168.X.X; ID: 095b058c-ae86-4544-b3b9-6dd4583a****). Alarm Record ID: ah260514T104844Shz0J****; Alarm Rule Name: alarm-8***; Alarm Type: Event; Impact: The VM is restarted. Solution: Check whether services are recovered. For details, visit the Cloud Eye console."
"template_variable": {
"PrivateIPV6": "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX",
"AlarmNotificationType": "Event",
"AccountName": "***",
"Namespace": "Elastic Cloud Server",
"ResourceName": "ecs-****",
"ResourceTags": "CES_TAG_XXX",
"MetricName": "VM Restart",
"IsAlarm": true,
"IsCycleTrigger": false,
"AlarmLevel": "Major",
"Region": "CN North-Beijing4",
"RegionId": "cn-north-4",
"ResourceId": "095b058c-ae86-4544-b3b9-6dd4583a****",
"PrivateIp": "192.168.X.X",
"CurrentData": "1.00 ",
"AlarmTime": "2026/05/14 10:48:44 GMT+08:00",
"DataPoint": {
"2026/05/14 10:43:27 GMT+08:00": "1.00"
},
"DataPointTime": ["2026/05/14 10:43:27 GMT+08:00"],
"AlarmRecordID": "ah260514T104844Shz0J****",
"AlarmRuleName": "alarm-8***",
"AlarmId": "al260514T104252SVeqi****",
"MonitoringRange": "All resources",
"IsOriginalValue": false,
"Filter": "Avg.",
"ComparisonOperator": "\\u003e=",
"Count": 1,
"Link": "https://console.huaweicloud.com/ces/?region=cn-north-4#/alarm/histories?alarmRecordId=ah260514T104844Shz0J****",
"EpName": "default",
"IsIEC": false,
"IsAgentEvent": false,
"ShowImpactAndSolution": true,
"ImpactScope": "The VM is restarted.",
"RecommendedSolution": "Check whether services are recovered."
},
"AlarmRecordID": "ah260514T104844Shz0J****"
} Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot