1、创建 一个/多个 触发器
def create_trigger():
values = {
"jsonrpc": "2.0",
"method": "trigger.create",
"params": {
"description": "机器的80端口", #触发器名称
"expression": "{172.16.1.2:net.tcp.listen[80].last()}=0", #最后的结果为0则报警
"priority": 4 #(0:未分类; 1:信息; 2:警告; 3:一般严重 ...)
},
"auth": auth,
"id": 4
}
2.检索触发器:这里只返回指定主机所属的触发器信息多个以列表形式返回
def get_trigger():
values = {
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
"hostids": "23", #主机id
"output": "extend",
"selectFunctions": "extend"
},
"auth": auth,
"id": 1
}
3.删除触发器
def del_trigger():
values = {
"jsonrpc": "2.0",
"method": "trigger.delete",
"params": ["43"], #触发器id
"auth": auth,
"id": 1
}
4.禁用/开启触发器
def update_trigger(auth,triggerid):
values ={
"jsonrpc": "2.0",
"method": "trigger.update",
"params": {
"triggerid": "34", #触发器id
"status": 0 #0启用,1禁用
},
"auth": auth,
"id": 1
}
5.只返回指定ID的触发器
def get_trigger():
values = {
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
"triggerids": ['15567'], #触发器id
"output": ['triggerid','expression','description',],
"selectFunctions": "extend", #显示functions这个字典中的内容
},
"auth": auth,
"id": 1
}
6.根据过滤信息返回
def get_trigger():
values = {
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
"templateids": ['10266'], #模板id
#"groupids": ['19'], #主机组id
#"applicationids": ['1111'], #应用集id进行过滤
#"itemids": ['28439'], #监控项id
#"hostids": ['10264'], #主机id
#"group":'New Create Group', #根据主机组名
#"host":'zabbix_agent_1.1.1.3', #根据主机名
"output": ['triggerid','expression','description',],
},
"auth": auth,
"id": 1
}
7.查询时返回更多关联信息:主机组、主机、监控项
def get_triggerinfo():
values = {
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
"triggerids": ['15567'], #触发器id
"output": ['triggerid','expression','description',],
"selectGroups": [ # 1.返回模板所属的主机组
"name",
"groupid"
],
"selectHosts": [ # 2.返回链接到模板的主机
"name",
"hostid"
],
"selectItems": [ # 3.返回模板中的监控项.
"name",
"key",
"itemid",
"interfaceid",
],
},
"auth": auth,
"id": 1
}