REST API

1、添加应用;控制台 → 导航菜单 → 应用接入 → 点击添加应用,获取 回调地址api

2、接口说明。

描述
接口 https://www.opsalert.cn/alert/api/{key}
调用方式 POST

提示

  • 接口可从添加的应用复制URL
  • 也可点击编辑应用获取应用key

3、请求参数

参数 类型 是否必须 描述
uuid string 必须 事件ID(唯一)
title string 必须 告警标题
priority int 必须 告警级别:1:提醒,2:警告,3:严重
type string 必须 触发:trigger 恢复:recovery
hostname string 必须 告警主机
content string 可选 告警内容
user []int 可选 成员的ID, 可在成员列表查看, 指定后将不在执行分派策略
group string 可选 告警分组
instance string 可选 告警实例
comment string 可选 备注信息

4、测试用例1

curl -H "Content-type: application/json" -X POST -d '{
     "uuid": "9f341ad8-982f-482f-b0d8-33d84cbb15ad",
     "title": "test host 1.1.1.1 down",
     "type": "trigger",
     "priority": 3,
     "content": "测试的告警",
     "instance": "1.1.1.1",
     "group": "TestGroup",
     "hostname": "TestHost",
     "comment": ""
}'  https://www.opsalert.cn/alert/api/4f5617cd-93c6-4abf-bf4c-e4a1bfe5fcd0

5、测试用例2

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import requests
import json

def main():
    request_data = json.dumps({
        "uuid": "9f341ad8-982f-482f-b0d8-33d84cbb15ad",
        "title": "测试的告警",
        "type": "trigger",
        "priority": 3,
        "content": "测试的告警",
        "instance": "1.1.1.1",
        "group": "TestGroup",
        "hostname": "TestHost",
        "comment": ""
    })
    request = requests.post("https://www.opsalert.cn/alert/api/d494eafe-50e4-4870-94f5-dc27f73942a6", data=request_data)
    print(request.text)

if __name__ == '__main__':
    main()