zoukankan      html  css  js  c++  java
  • Zabbix API获取监控项的值

    使用history.get API进行监控项的获取,进行排序和limit就可以取到最新值;

    1.1 如何进行API认证?

    获取认证中的result认证值,在后面的请求中使用;

    curl -X POST 
      http://IP:Port/zabbix/api_jsonrpc.php 
      -H 'Content-Type: application/json' -d '{
        "jsonrpc": "2.0",
        "method": "user.login",
        "params": {
            "user": "Admin",
            "password": "zabbix"
        },
        "id": 1
    }'

    返回结果是:

    {
        "jsonrpc": "2.0",
        "result": "f3f5xxx69e958",
        "id": 1
    }

    1.2 如何获取某一个监控项的值?

    使用的方法是history.get;其中的history表示数据类型;limit=1表示只取一条记录,再按照时间倒排就可以取到最新值;
    history取值:0-浮点,1-字符,2-日志,3-整数(默认),4-文本;

    itemids可以在zabbix界面查看到,点击查看该监控项的图形可以在地址栏上面看到;

    auth的值就是上一步获取的认证结果;

    curl -X POST 
      http://IP:Port/zabbix/api_jsonrpc.php 
      -H 'Content-Type: application/json' -d '{
        "jsonrpc": "2.0",
        "method": "history.get",
        "params": {
            "output": "extend",
            "history": 3,
            "itemids": "30632",
            "sortfield": "clock",
            "sortorder": "DESC",
            "limit": 1
        },
        "auth": " f3f5xxx69e958",
        "id": 1
    }'

    返回结果:

    {
        "jsonrpc": "2.0",
        "result": [
            {
                "itemid": "30632",
                "clock": "1603271688",
                "value": "812304",
                "ns": "882748120"
            }
        ],
        "id": 1
    }
  • 相关阅读:
    VMware虚拟机安装
    代码搜索的终极武器Ag
    模糊搜索神器fzf
    Python:json、xml、字典各种转换
    03-azkaban安装部署
    linux下环境变量PATH设置错误的补救
    01-编译azkaban
    VMware安装CentOS7
    PS(二)
    等待公交车的时间
  • 原文地址:https://www.cnblogs.com/stono/p/13857109.html
Copyright © 2011-2022 走看看