Ad Widget

Collapse

API Trigger get IP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eloy
    Junior Member
    • Apr 2013
    • 1

    #1

    API Trigger get IP

    Hi,

    I'm updating this week from zabbix 1.8 to 2.0. In my custom dashboard I get in trigger.get the IP into the host. Now in the version 2.0 I don't have ip. Any idea parameter? I check the doc but nothing explain about the IP.

    This is my zabbix 2 host[] info.

    'hosts': [
    {
    'available': '1',
    'maintenance_type': '0',
    'maintenances': [

    ],
    'ipmi_username': u'',
    'snmp_disable_until': '0',
    'ipmi_authtype': '-1',
    'ipmi_disable_until': '0',
    'lastaccess': '0',
    'snmp_error': u'',
    'ipmi_privilege': '2',
    'jmx_error': u'',
    'jmx_available': '0',
    'ipmi_errors_from': '0',
    'maintenanceid': '0',
    'snmp_available': '0',
    'status': '0',
    'host': 'test1',
    'disable_until': '0',
    'ipmi_password': u'',
    'ipmi_available': '0',
    'maintenance_status': '0',
    'snmp_errors_from': '0',
    'ipmi_error': u'',
    'proxy_hostid': '0',
    'hostid': '10084',
    'name': 'test1',
    'jmx_errors_from': '0',
    'jmx_disable_until': '0',
    'error': u'',
    'maintenance_from': '0',
    'errors_from': '0'
    }
    ]


    And my call to the system with python lib.
    triggers = zapi.trigger.get(
    only_true=1,
    active=1,
    output='extend',
    sortorder='DESC',
    monitored=1,
    selectHosts = 'extend',
    maintenance= 0,
    min_severity=2,
    skipDependent=1
    )

    Any idea?
    Cheers!
    Eloy Coto
  • Pavels
    Member
    • Oct 2011
    • 83

    #2
    In 2.0 a host can have any number of interfaces. Because of that the IP of the host is no longer a property of the host object, but a separate related object. You'll need to first retrieve the hosts for each trigger, and then perform either a separate host.get request with the "selectInterfaces" parameter or a hostinterface.get request to retrieve the host interfaces.

    These API doc pages might help:


    Comment

    • Zbbixuser
      Member
      • Jun 2021
      • 45

      #3
      Try this:

      """
      Shows a list of all current issues (AKA tripped triggers)
      """
      from datetime import datetime
      import time
      from pyzabbix import ZabbixAPI

      # The hostname at which the Zabbix web interface is available
      ZABBIX_SERVER = 'http://192.168.***.***/zabbix'

      zapi = ZabbixAPI(ZABBIX_SERVER)

      # Login to the Zabbix API
      zapi.login('***', '***')

      # Get a list of all issues (AKA tripped triggers)
      triggers = zapi.trigger.get(only_true=1,
      skipDependent=1,
      monitored=1,
      active=1,
      filter={"value": 1},
      output='extend',
      expandDescription=1,
      selectHosts=['name'],
      sortfield=['lastchange'],
      sortorder='ASC',
      )

      def seconds_to_dhms(time):
      seconds_to_minute = 60
      seconds_to_hour = 60 * seconds_to_minute
      seconds_to_day = 24 * seconds_to_hour
      seconds_to_month = 30 * seconds_to_day
      seconds_to_year = 12 * seconds_to_month


      years = time // seconds_to_year
      time %= seconds_to_year

      month = time // seconds_to_month
      time %= seconds_to_month

      days = time // seconds_to_day
      time %= seconds_to_day

      hours = time // seconds_to_hour
      time %= seconds_to_hour

      minutes = time // seconds_to_minute
      time %= seconds_to_minute

      seconds = time

      if (seconds >= 0) and (minutes == 0) and (hours == 0) and (days == 0) and (month == 0) and (years == 0):
      return("%d seconds" % (seconds))
      elif (seconds >= 0) and (minutes >= 1) and (hours == 0) and (days == 0) and (month == 0) and (years == 0):
      return("%d minutes : %d seconds" % (minutes, seconds))
      elif (seconds >= 0) and (minutes >= 0) and (hours >= 1) and (days == 0) and (month == 0) and (years == 0):
      return("%d hours : %d minutes" % (hours, minutes))
      elif (seconds >= 0) and (minutes >= 0) and (hours >= 0) and (days >= 1) and (month == 0) and (years == 0):
      return("%d days : %d hours" % (days, hours))
      elif (seconds >= 0) and (minutes >= 0) and (hours >= 0) and (days >= 0) and (month >= 1) and (years == 0):
      return("%d month : %d days" % (month, days))
      elif (seconds >= 0) and (minutes >= 0) and (hours >= 0) and (days >= 0) and (month >= 0) and (years >= 1):
      return("%d year : %d month" % (years, month))
      else:
      return("%dm:%dd:%dh:%dm:%ds" % (month, days, hours, minutes, seconds))



      # Print a list containing only "tripped" triggers
      for t in triggers:
      if int(t['value']) == 1:
      time_period=int(time.mktime(datetime.now().timetup le())) - int(t['lastchange'])
      hostss=zapi.host.get(hostids=t['hosts'][0]['hostid'], output = ['hostid','host','name'], selectInterfaces=['ip','port','dns'])
      for i in hostss:
      print("-----")
      print("{0}\n{1}\n{2}\n{3}".format(t['hosts'][0]['name'],i['interfaces'][0]['ip'], t['description'], seconds_to_dhms(time_period)))

      Comment

      Working...