1.获取所有触发器中报警信息,如果不报警则不会获取到
def trigger_get_alarm():
values = {
"jsonrpc": "2.0",
"method": "trigger.get",
"params": {
"output": [
"host",
"description",
"triggerid",
"eventid",
"templateids"
],
"selectGroups": [
"name"
],
"selectHosts": [
"name",
"host"
],
"selectItems": [
"name",
"lastvalue",
"units"
],
"filter": {
"value": 1
},
"monitored": 1,
"selectLastEvent": "extend",
"expandComment": 1,
"expandDescription": 1,
"sortfield": "priority",
"sortorder": "DESC",
"withLastEventUnacknowledged": 1
},
"auth": auth,
"id": 1
}
# 获取的报警信息如下
'''
[{
"description": "User_Login", # 这里是报警信息的具体内容
"items": [{
"itemid": "28439",
"units": "",
"lastvalue": "59",
"name": "login_user"
}],
"lastEvent": {
"eventid": "73",
"objectid": "15601",
"clock": "1528266869",
"object": "0",
"acknowledged": "0",
"value": "1",
"source": "0",
"ns": "387320307"
},
"triggerid": "15601",
"hosts": [{
"host": "zabbix_agent_1.1.1.3",
"hostid": "10264",
"name": "zabbix_agent_1.1.1.3"
}],
"groups": [{
"groupid": "19",
"name": "New Create Group"
}, {
"groupid": "20",
"name": "New Group 02"
}]
}]
'''
2.只返回给定监控项的历史记录
def get_historys_item():
values = {
"jsonrpc": "2.0",
"method": "history.get",
"params": {
"output": "extend",
"history": 3, # 要返回的历史对象类型
# 0 - numeric float;数字浮点数;1 - character;字符 ;2 - log; 日志;3 - numeric unsigned; 数字符号;4 - text.文本
"itemids": ["28439"], #监控项id
"sortfield": "clock",
"sortorder": "DESC",
"limit": 2 #显示两条数据
},
"auth": auth,
"id": 1
}
#返回的数据
'''
[{
"itemid": "28439",
"ns": "244866385",
"value": "4",
"clock": "1528274369"
}, {
"itemid": "28439",
"ns": "197647992",
"value": "4",
"clock": "1528274339"
}]
'''
3.只返回给定主机的历史记录
def get_historys_host():
values = {
"jsonrpc": "2.0",
"method": "history.get",
"params": {
"output": "extend",
"history": 3, # 要返回的历史对象类型
# 0 - numeric float;数字浮点数;1 - character;字符 ;2 - log; 日志;3 - numeric unsigned; 数字符号;4 - text.文本
"hostids": "10264", #主机id
"sortfield": "clock",
"sortorder": "DESC",
"limit": 2 # 显示两条数据
},
"auth": auth,
"id": 1
}
#返回的信息
'''
[{
"itemid": "28439",
"ns": "244866385",
"value": "4",
"clock": "1528274369"
}, {
"itemid": "28439",
"ns": "197647992",
"value": "4",
"clock": "1528274339"
}]
'''