history.get

描述

integer/array history.get(object parameters)

该方法允许根据给定参数检索历史数据。

如果管家程序尚未清除相关数据,该方法可能返回已删除实体的历史数据。

该方法对所有类型用户开放。调用权限可通过用户角色设置进行撤销。更多信息请参阅User roles

参数

(object) 定义期望输出的参数.

该方法支持以下参数.

参数 数据类型 描述
history integer 要返回的历史object类型.

可能值:
0 - 数值型float;
1 - 字符型;
2 - 日志型;
3 - 无符号数值型;
4 - 文本型.

默认值: 3.
hostids string/array 仅返回来自指定主机的历史数据.
itemids string/array 仅返回来自指定监控项的历史数据.
time_from timestamp 仅返回在指定时间之后或等于该时间接收到的值.
time_till timestamp 仅返回在指定时间之前或等于该时间接收到的值.
sortfield string/array 按指定属性排序结果.

可能值为: itemidclock.
countOutput boolean 这些参数在通用get方法参数中有描述.
editable boolean
excludeSearch boolean
filter object
limit integer
output query
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean

返回值

(integer/array) 返回以下两种情况之一:

  • 一个array的objects;
  • 检索到的objects数量,如果使用了countOutput参数。

示例

检索 监控项 历史数据

返回从数值型(float) 监控项接收的最近10个值.

请求:

{
           "jsonrpc": "2.0",
           "method": "history.get",
           "params": {
               "output": "extend",
               "history": 0,
               "itemids": "23296",
               "sortfield": "clock",
               "sortorder": "DESC",
               "limit": 10
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

响应:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "23296",
                   "clock": "1351090996",
                   "value": "0.085",
                   "ns": "563157632"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090936",
                   "value": "0.16",
                   "ns": "549216402"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090876",
                   "value": "0.18",
                   "ns": "537418114"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090816",
                   "value": "0.21",
                   "ns": "522659528"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090756",
                   "value": "0.215",
                   "ns": "507809457"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090696",
                   "value": "0.255",
                   "ns": "495509699"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090636",
                   "value": "0.36",
                   "ns": "477708209"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090576",
                   "value": "0.375",
                   "ns": "463251343"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090516",
                   "value": "0.315",
                   "ns": "447947017"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090456",
                   "value": "0.275",
                   "ns": "435307141"
               }
           ],
           "id": 1
       }

来源

CHistory::get() 位于 ui/include/classes/api/services/CHistory.php 文件中。