前置设置
设置问题告警模板
需要在告警消息中添加自定义模板
告警主机:{HOST.NAME}
告警地址:{HOST.IP}
监控项目:{ITEM.NAME}
告警等级:{TRIGGER.SEVERITY}
当前状态:{TRIGGER.STATUS} 值={ITEM.LASTVALUE}
告警信息:{TRIGGER.NAME}
告警时间:{EVENT.DATE} {EVENT.TIME}
事件 ID:{EVENT.ID}
需要加上事件ID,然后根据告警的事件ID来请求
获取api-token
新建api-token
发起API请求
请求链接
我这里的地址时192.168.140.5
那么请求的地址就是 192.168.140.5/api_jsonrpc.php
请求方法
请求方法都是 POST
需要携带的头
Content-Type: application/json-rpc
例子
查询问题
body部分
{
"jsonrpc": "2.0",
"method": "problem.get",
"params": {
"output": "extend",
"selectAcknowledges": "extend",
"selectTags": "extend",
"selectSuppressionData": "extend",
"eventids": "<这里是事件ID>",
"recent": "true",
"sortfield": ["eventid"],
"sortorder": "DESC"
},
"auth": "<这里时前面创建的api-token>",
"id": 1
}
响应
{
"jsonrpc": "2.0",
"result": [
{
"eventid": "2474",
"source": "0",
"object": "0",
"objectid": "23653",
"clock": "1685496566",
"ns": "183983534",
"r_eventid": "0",
"r_clock": "0",
"r_ns": "0",
"correlationid": "0",
"userid": "0",
"name": "xxxxxxxx",
"acknowledged": "0",
"severity": "4",
"opdata": "",
"acknowledges": [],
"suppression_data": [],
"suppressed": "0",
"urls": [],
"tags": [
{
"tag": "app",
"value": "gj"
},
{
"tag": "app",
"value": "test"
}
]
}
],
"id": 1
}
关闭问题
body部分
{
"jsonrpc": "2.0",
"method": "event.acknowledge",
"params": {
"eventids":"<这里是事件ID>",
"action":1
},
"auth": "<这里时前面创建的api-token>",
"id": 1
}
这里需要注意的是
action
字段的值
- 1 表示关闭问题,但不确认问题
- 2 表示确认问题,但不关闭问题
- 3 表示确认和关闭问题
响应部分
{
"jsonrpc": "2.0",
"result": {
"eventids": [
2480
]
},
"id": 1
}
标签:jsonrpc,extend,ID,利用,zabbix,API,告警,2.0,id
From: https://www.cnblogs.com/guangdelw/p/17445268.html