获取主机列表
Payload:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["host","available"]
},
"auth": "54ec7f0d103f635ada0a76147d8a93a5",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10084",
"host": "Zabbix server",
"available": "1"
},
{
"hostid": "10254",
"host": "jfgitlab",
"available": "1"
}
],
"id": 1
}
这里能够获取到主机的host
,用于组成下面的expression
trigger
创建触发器Payload:
{
"jsonrpc": "2.0",
"method": "trigger.create",
"params": {
"description": "Total memory is lower than 4G at host: jfgitlab (中文测试)",
"expression": "{jfgitlab:vm.memory.size[total].avg(1m)}<4G",
"priority":"1"
},
"auth": "54ec7f0d103f635ada0a76147d8a93a5",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"triggerids": [
"15405"
]
},
"id": 1
}
TODO:
表达式expression
规则说明
结构为:
{<server>:<key>.<function>(<parameter>)}
server: jfgitlab
key: vm.memory.size[total]
function: avg(1m)
action
设置主机动作通过主机id与触发器名决定该action
Payload:
{
"jsonrpc": "2.0",
"method": "action.create",
"params": {
"name": "test action",
"eventsource": 0,
"status": 0,
"filter": {
"evaltype": "1",
"formula": "A and B",
"conditions": [
{
"conditiontype": "1",
"operator": "0",
"value": "10254",
"formulaid": "A"
},
{
"conditiontype": "3",
"operator": "2",
"value": "Total memory is lower than 4G at host: jfgitlab (中文测试)",
"formulaid": "B"
}
]
},
"operations": [
{
"operationtype": 0,
"esc_period": "24h",
"esc_step_from": 1,
"esc_step_to": 1,
"evaltype": 0,
"opmessage_grp": [
{
"usrgrpid": "14"
}
],
"opmessage": {
"subject": "Problem: {TRIGGER.NAME}",
"message": "Problem started at {EVENT.TIME} on {EVENT.DATE}\r\nProblem name: {TRIGGER.NAME}\r\nHost: {HOST.NAME}\r\nSeverity: {TRIGGER.SEVERITY}\r\n\r\nOriginal problem ID: {EVENT.ID}\r\n{TRIGGER.URL}",
"mediatypeid": "4"
}
}
],
"recovery_operations": [
],
"acknowledge_operations": [
]
},
"auth": "54ec7f0d103f635ada0a76147d8a93a5",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"actionids": [
11
]
},
"id": 1
}