Ad Widget

Collapse

Question about API 4.0 how to relate problems with host

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Question about API 4.0 how to relate problems with host

    Hello

    I am new to ZABBIX and I am trying to query some problem's data using the API, I managed to get a list of current problems as below, however I need some help on how to find or correlate these problem with the host they are coming from. The output from the problem get is as follow:
    thanks

    Request

    {
    "params": {
    "acknowledged": false
    },
    "id": 935079109,
    "jsonrpc": "2.0",
    "method": "problem.get",
    "auth": "43b05f80b3a71acf48ea4aa54a6bc607"
    }


    response:

    {
    "result": [
    {
    "eventid": "45",
    "source": 0,
    "object": 0,
    "objectid": "16005",
    "clock": 1581597767,
    "ns": 488932734,
    "r_eventid": "0",
    "r_clock": 0,
    "r_ns": 0,
    "correlationid": "0",
    "userid": "0",
    "name": "Free disk space is less than 20% on volume /",
    "acknowledged": 0,
    "severity": 2,
    "suppressed": 0
    },
    {
    "eventid": "46",
    "source": 0,
    "object": 0,
    "objectid": "16007",
    "clock": 1581598442,
    "ns": 539714773,
    "r_eventid": "0",
    "r_clock": 0,
    "r_ns": 0,
    "correlationid": "0",
    "userid": "0",
    "name": "Too many processes on Centos",
    "acknowledged": 0,
    "severity": 2,
    "suppressed": 0
    },
    {
    "eventid": "48",
    "source": 0,
    "object": 0,
    "objectid": "16008",
    "clock": 1581598828,
    "ns": 124473811,
    "r_eventid": "0",
    "r_clock": 0,
    "r_ns": 0,
    "correlationid": "0",
    "userid": "0",
    "name": "Lack of available memory on server Centos",
    "acknowledged": 0,
    "severity": 3,
    "suppressed": 0
    }
    ],
    "id": 935079109,
    "jsonrpc": "2.0"
    }


    #2
    After further investigation I attempted to query triggers with the objectid returned by the problem. I manage to get a reply but it still does not contain the hostname related to the problem I am looking for. The following is the example:

    request
    {
    "params": {
    "triggerids": [
    "16005"
    ],
    "selectHosts": [
    "hostid",
    "name"
    ]
    },
    "id": 1561655547,
    "jsonrpc": "2.0",
    "method": "trigger.get",
    "auth": "b5dcd8c47dfdf6d26c4ae266dbe3ae1b"
    }

    Reply:

    {
    "result": [
    {
    "triggerid": 16005,
    "description": "Free disk space is less than 90% on volume /",
    "expression": "{18310}\u003c90",
    "comments": "",
    "error": "",
    "flags": 0,
    "lastchange": 1581597767,
    "priority": 2,
    "state": 0,
    "status": 0,
    "templateid": 0,
    "type": 0,
    "url": "",
    "value": 1,
    "recovery_mode": 0,
    "recovery_expression": "",
    "correlation_mode": 0,
    "correlation_tag": "",
    "manual_close": 0
    }
    ],
    "id": 1561655547,
    "jsonrpc": "2.0"
    }


    Comment


      #3
      Problem is generated by trigger. So from problem.get you get information what trigger generated particular problem.
      Value in "objectid" from response is a trigger ID.

      Next you need to ask to what hosts trigger belongs. And remember trigger can belong to many hosts not the only one. You can use "trigger.get" with value from first response (put this value in triggerids property):

      Code:
      {
          "jsonrpc": "2.0",
          "method": "trigger.get",
          "params": {
             "triggerids": "43194",
              "output": "extend",
              "selectHosts": "extend"
          },
          "auth": "xxxxxxxxxxxxxxxxxxxx",
          "id": 1
      }
      You will get something like that:

      Code:
      {
          "jsonrpc": "2.0",
          "result": [
              {
                  "triggerid": "43194",
                 ...
                 ...
                 ...
                  "hosts": [
                      {
                          "hostid": "11997",
      "name": "h1",
                         ...
                         ...
                         ...
                      },
                      {
                          "hostid": "11998",
      "name": "h2",
                         ...
                         ...
                         ...
                      }
                  ]
              }
          ],
          "id": 1
      }

      But there is a smart way... When you adding trigger you define name for it. Smart way needs you use macro {HOST.NAME} or {HOST.HOST} in trigger name.
      {HOST.NAME} - Visible host name.
      {HOST.HOST} - Host name.
      So, in that configuration every problem will have host name in the generated problem name.

      Ie. in your first response is line:
      Code:
      "name": "Free disk space is less than 20% on volume /",
      You can add to trigger name macro like above and have response like:
      Code:
      "name": "Free disk space is less than 20% on volume / on SERVER_A",
      "name": "Too many processes on Centos (SERVER_X)",
      "name": "Lack of available memory on server Centos (SERVER_Y)",

      Comment


        #4
        Great this is what I was looking for , thanks for pointing me on the right direction, I will try it out.

        Comment


          #5
          Hello

          I tried the recommended request to get the hosts for a trigger but the response still does not include the host. This is what I tried using Zabbix 4.0

          Request
          Code:
          {
          "params": {
          "triggerids": [
          "16005"
          ],
          "selectHosts": "extend",
          "output": "extend"
          },
          "id": 310502771,
          "jsonrpc": "2.0",
          "method": "trigger.get",
          "auth": "60d7457bcc03cd05690855507e613e51"
          }
          Reply
          Code:
          {
            "result": [
              {
                "triggerid": 16005,
                "description": "Free disk space is less than 90% on volume /",
                "expression": "{18310}\u003c90",
                "comments": "",
                "error": "",
                "flags": 0,
                "lastchange": 1581597767,
                "priority": 2,
                "state": 0,
                "status": 0,
                "templateid": 0,
                "type": 0,
                "url": "",
                "value": 1,
                "recovery_mode": 0,
                "recovery_expression": "",
                "correlation_mode": 0,
                "correlation_tag": "",
                "manual_close": 0
              }
            ],
            "id": 310502771,
            "jsonrpc": "2.0"
          }
          Last edited by gduchate; 14-02-2020, 16:46. Reason: Adding version

          Comment

          Announcement

          Collapse
          No announcement yet.
          Working...
          X