2022 Zabbix中国峰会
2022 Zabbix中国峰会

history.get

Description 说明

integer/array history.get(object parameters)

The method allows to retrieve history data according to the given parameters.该方法允许根据给定的参数检索历史数据。

Parameters参数

(object) Parameters defining the desired output.定义所需输出的参数。

The method supports the following parameters.该方法支持以下参数。

参数r 类 描述
history integer History object types to return. 要返回的历史对象类型。

Possible values:可能的值
0 - numeric float;数字浮点数
1 - character;字符
2 - log; 日志
3 - numeric unsigned; 数字符号
4 - text.文本

Default: 3.默认:3;
hostids string/array Return only history from the given hosts.只返回给定主机的历史记录。
itemids string/array Return only history from the given items.只返回给定项的历史记录。
time_from timestamp Return only values that have been received after or at the given time.仅返回在给定时间时或之后收到的值
time_till timestamp Return only values that have been received before or at the given time.仅返回在给定时间时或之前收到的值。
sortfield string/array Sort the result by the given properties.按照给定的属性对结果进行排序。

Possible values are: itemid and clock.可能的值为:itemidclock
countOutput flag These parameters being common for all get methods are described in detail in the reference commentary page. 这些参数对于所有的“获取”方法是常见的,在参考评论页中有详细描述。
editable boolean
excludeSearch flag
filter object
limit integer
output query
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch flag

Return values 返回值

(integer/array) Returns either:返回:

  • an array of objects;一组对象;
  • the count of retrieved objects, if the countOutput parameter has been used.如果已经使用“countOutput”参数,则检索到的对象的计数。

Examples 示例

Retrieving item history data 检索项目历史数据

Return 10 latest values received from a numeric(float) item.从数字(浮动)项返回10个最新值。

Request:

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

Response:

{
           "jsonrpc": "2.0",
           "result": [
               {
                   "itemid": "23296",
                   "clock": "1351090996",
                   "value": "0.0850",
                   "ns": "563157632"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090936",
                   "value": "0.1600",
                   "ns": "549216402"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090876",
                   "value": "0.1800",
                   "ns": "537418114"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090816",
                   "value": "0.2100",
                   "ns": "522659528"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090756",
                   "value": "0.2150",
                   "ns": "507809457"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090696",
                   "value": "0.2550",
                   "ns": "495509699"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090636",
                   "value": "0.3600",
                   "ns": "477708209"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090576",
                   "value": "0.3750",
                   "ns": "463251343"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090516",
                   "value": "0.3150",
                   "ns": "447947017"
               },
               {
                   "itemid": "23296",
                   "clock": "1351090456",
                   "value": "0.2750",
                   "ns": "435307141"
               }
           ],
           "id": 1
       }

Source来源

CHistory::get() in frontends/php/include/classes/api/services/CHistory.php.