Ad Widget

Collapse

Get Host Name by its ID

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shay
    Junior Member
    • Dec 2021
    • 2

    #1

    Get Host Name by its ID

    Hi

    I'm issuing a "problem.get" api call and I get the result.
    One of the properties in the result is objectid, which holds the id of the relevant host.
    How can I translate the Id to its hostname?

    Thanks in advance.


    Example output:


    eventid : 926
    source : 0
    object : 0
    objectid : 19836
    clock : 1639898475
    ns : 415548935
    r_eventid : 0
    r_clock : 0
    r_ns : 0
    correlationid : 0
    userid : 0
    name : "BITS" (Background Intelligent Transfer Service) is not running (startup type automatic delayed)
    acknowledged : 0
    severity : 3
    opdata :
    suppressed : 0
    urls : {}



  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2


    host.get
    hostids string/array Return only hosts with the given host IDs.

    Comment


    • shay
      shay commented
      Editing a comment
      Hi

      I saw that too but I can't get it to work. Something like:

      {
      "jsonrpc": "2.0",
      "method": "host.get",
      "params": {
      "output" = "hostid","name"
      "filter": {
      "hostid": 12345
      }
      },
      "auth": "038e1d7b1735c6a5436ee9eae095879e",
      "id": 1
      }

      But the result doesn't include the host name. Can you share a code example?


      -shay
  • shay
    Junior Member
    • Dec 2021
    • 2

    #3
    I'm having problems editing my reply so writing here.

    I think I got it wrong assuming objectid is the id of the host on which the problem occurred.
    Which of the properties of "problems.get" refers to the host? How can I relate a problem to a host?


    ### UPDATE ###

    I managed to get the problems for each host by querying hosts and passing each hostid to the following:

    {
    "jsonrpc": "2.0"
    "method": "problem.get"
    "auth" = 1111111111
    "id" = 1
    "params" = {
    "hostids" = ["222"]
    }
    }

    -shay
    Last edited by shay; 20-12-2021, 11:28.

    Comment

    • ISiroshtan
      Senior Member
      • Nov 2019
      • 324

      #4
      Hi mate.

      As mentioned in Problem Object documentation, "object" property value of 0 indicates that object is trigger. So that is TriggerID, not the HostID. I think you should try trigger.get with this ID while also passing parameter "selectHosts": "extend" and see what it returns.

      Comment

      Working...