Ad Widget

Collapse

Zabbix API. Библиотека для Python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sersad
    Senior Member
    • May 2009
    • 518

    #16
    Originally posted by alp
    Вы парвы, вторая версия и правда не выводит поля IP =(
    Может рано багрепорт? Просто я выше привел ссылку на дефиншены где четко обозначенно что есть Host interface в Object details
    Code:
    Parameter 	Type 	Description 
    interfaces 	array 	Host interfaces objects.
    вот как бы этот массив дернуть? может я неправильно это делаю?

    Comment

    • alp
      Member
      • Nov 2009
      • 90

      #17
      Но ведь в этой доке http://www.zabbix.com/documentation/...x/api/host/get точно приведён вывод содержащий поле IP, которое не входит в список interfaces.

      Comment

      • sersad
        Senior Member
        • May 2009
        • 518

        #18
        Originally posted by alp
        Но ведь в этой доке http://www.zabbix.com/documentation/...x/api/host/get точно приведён вывод содержащий поле IP, которое не входит в список interfaces.
        Вы правы
        Code:
        zapi.host.get(
            { "output": "extend",
              "filter": {"host": ["33-kyib22p3","Zabbix-server"]}
              }
            )
        вывод
        Code:
        10: Response Body: {u'jsonrpc': u'2.0', u'result': [{u'available': u'0', u'maintenance_type': u'0', u'maintenances': [], u'ipmi_username': u'', u'snmp_disable_until': u'0', u'ipmi_authtype': u'0', u'ipmi_disable_until': u'0', u'lastaccess': u'0', u'snmp_error': u'', u'ipmi_privilege': u'2', u'jmx_error': u'', u'jmx_available': u'0', u'ipmi_errors_from': u'0', u'maintenanceid': u'0', u'snmp_available': u'1', u'status': u'0', u'host': u'33-kyib22p3', u'disable_until': u'0', u'ipmi_password': u'', u'ipmi_available': u'0', u'maintenance_status': u'0', u'snmp_errors_from': u'0', u'ipmi_error': u'', u'proxy_hostid': u'0', u'hostid': u'10911', u'name': u'33-kyib22p3', u'jmx_errors_from': u'0', u'jmx_disable_until': u'0', u'error': u'', u'maintenance_from': u'0', u'errors_from': u'0'}, {u'available': u'1', u'maintenance_type': u'0', u'maintenances': [], u'ipmi_username': u'zabbix', u'snmp_disable_until': u'0', u'ipmi_authtype': u'-1', u'ipmi_disable_until': u'0', u'lastaccess': u'0', u'snmp_error': u'', u'ipmi_privilege': u'4', u'jmx_error': u'', u'jmx_available': u'0', u'ipmi_errors_from': u'0', u'maintenanceid': u'0', u'snmp_available': u'0', u'status': u'0', u'host': u'Zabbix server', u'disable_until': u'0', u'ipmi_password': u'2286sena', u'ipmi_available': u'0', u'maintenance_status': u'0', u'snmp_errors_from': u'0', u'ipmi_error': u'', u'proxy_hostid': u'0', u'hostid': u'10017', u'name': u'Zabbix server', u'jmx_errors_from': u'0', u'jmx_disable_until': u'0', u'error': u'', u'maintenance_from': u'0', u'errors_from': u'0'}], u'id': 1}
        Строк не хватает как обозначено в мануале
        http://www.zabbix.com/documentation/...x/api/host/get
        попробую поставить



        Хм не помогло
        Last edited by sersad; 26-06-2012, 14:18.

        Comment

        • sersad
          Senior Member
          • May 2009
          • 518

          #19

          Comment

          • sersad
            Senior Member
            • May 2009
            • 518

            #20

            You need to use "selectInterfaces" parameter to get host interface information. This parameter was added from Zabbix 2.0 API because host can have multiple interfaces from 2.0.

            Please see http://www.zabbix.com/documentation/...x/api/host/get for more details of host.get method on 2.0.
            Зря тикет поднял, извиняюсь. Без подсказки не допер как дернуть нужные данные
            Code:
            zapi.host.get(
                { "output": "extend",
                  "filter": {"host": ["33-kyib22p3"]},
                  "selectInterfaces": "extend"
                  }
                )

            дает следуюущее
            Code:
            10: Response Body: {u'jsonrpc': u'2.0', u'result': [{u'available': u'0', u'maintenance_type': u'0', u'maintenances': [], u'ipmi_username': u'', u'snmp_disable_until': u'0', u'ipmi_authtype': u'0', u'ipmi_disable_until': u'0', u'lastaccess': u'0', u'snmp_error': u'', u'ipmi_privilege': u'2', u'jmx_error': u'', u'jmx_available': u'0', u'ipmi_errors_from': u'0', u'maintenanceid': u'0', u'snmp_available': u'1', u'status': u'0', u'interfaces': {u'32734': {u'interfaceid': u'32734', u'hostid': u'10911', u'ip': u'10.21.133.84', u'useip': u'1', u'dns': u'', u'main': u'1', u'type': u'2', u'port': u'161'}, u'32733': {u'interfaceid': u'32733', u'hostid': u'10911', u'ip': u'10.21.133.84', u'useip': u'1', u'dns': u'', u'main': u'0', u'type': u'2', u'port': u'161'}}, u'host': u'33-kyib22p3', u'disable_until': u'0', u'ipmi_password': u'', u'ipmi_available': u'0', u'maintenance_status': u'0', u'snmp_errors_from': u'0', u'ipmi_error': u'', u'proxy_hostid': u'0', u'hostid': u'10911', u'name': u'33-kyib22p3', u'jmx_errors_from': u'0', u'jmx_disable_until': u'0', u'error': u'', u'maintenance_from': u'0', u'errors_from': u'0'}], u'id': 1}

            Comment

            • alp
              Member
              • Nov 2009
              • 90

              #21
              Не удивительно что не смог, ведь документация у них не для человеков написана =(

              Вот я сейчас пытаюсь сделать host.update на поля из "Host inventory", да что там профиль, тот же статус меняю и получаю ошибку =(

              zapi.host.update({
              "hostid" : hostid,
              "status" : 0 })


              (u'Error -32602: Invalid params., No permissions to referred object or it does not exist! while sending {"params": {"status": 0, "hostid": [{"hostid": "10187"}]}, "jsonrpc": "2.0", "method": "host.update", "auth": "1763c136fd064c5255d1a9cf90c5326f", "id": 5}', -32602)

              Разумеется у пользователя есть полные права на запись всего.
              Last edited by alp; 27-06-2012, 13:12.

              Comment

              • alp
                Member
                • Nov 2009
                • 90

                #22
                Разобрался, трабла была в том, что в переменную hostid приходил список, а не одна циферка.

                Comment

                • sersad
                  Senior Member
                  • May 2009
                  • 518

                  #23
                  Originally posted by alp
                  Не удивительно что не смог, ведь документация у них не для человеков написана =(
                  Просто очень мало примеров.

                  Comment

                  • fast-l
                    Junior Member
                    • Sep 2012
                    • 3

                    #24
                    приветствую.
                    Не подскажите что я не так делаю?

                    Code:
                    In [206]: zapi.host.create({
                                    "host":"testsw",
                                    "interfaces":[{
                                                    "type":2,
                                                    "main":2,
                                                    "ip":u"172.17.22.33",
                                                    "port":161,
                                                    "useip":1}],
                                    'groups':[{
                                             "groupid":9
                                             }],
                                    "templates":[{
                                                "templateid":10124
                                                }],
                                    "inventory":{
                                                "macaddress_a":"00:00:00:00:00:00"
                                                }
                                              })
                    
                    ZabbixAPIException: (u'Error -32602: Invalid params., Incorrect arguments passed to function. while sending {"params": {"templates": [{"templateid": 10124}], "host": "testsw", "interfaces": [{"ip": "172.17.22.33", "main": 2, "type": 2, "port": 161, "useip": 1}], "groups": [{"groupid": 9}], "inventory": {"macaddress_a": "00:00:00:00:00:00"}}, "jsonrpc": "2.0", "method": "host.create", "auth": "5bb48d0208688f222fbd346b1d9a17a6", "id": 45}', -32602)
                    
                    In [210]: zapi.hostgroup.get({"filter":{"name":'switch'}})
                    Out[210]: [{u'groupid': u'9'}]
                    
                    In [211]: zapi.template.get({"filter":{"name":'dlink.des-3200-26'}})
                    Out[211]: [{u'hostid': u'10124', u'templateid': u'10124'}]
                    спасибо.
                    Last edited by fast-l; 30-09-2012, 08:35.

                    Comment

                    • Pavels
                      Member
                      • Oct 2011
                      • 83

                      #25
                      Originally posted by fast-l
                      приветствую.
                      Не подскажите что я не так делаю?

                      Code:
                      In [206]: zapi.host.create({
                                      "host":"testsw",
                                      "interfaces":[{
                                                      "type":2,
                                                      "main":2,
                                                      "ip":u"172.17.22.33",
                                                      "port":161,
                                                      "useip":1}],
                                      'groups':[{
                                               "groupid":9
                                               }],
                                      "templates":[{
                                                  "templateid":10124
                                                  }],
                                      "inventory":{
                                                  "macaddress_a":"00:00:00:00:00:00"
                                                  }
                                                })
                      
                      ZabbixAPIException: (u'Error -32602: Invalid params., Incorrect arguments passed to function. while sending {"params": {"templates": [{"templateid": 10124}], "host": "testsw", "interfaces": [{"ip": "172.17.22.33", "main": 2, "type": 2, "port": 161, "useip": 1}], "groups": [{"groupid": 9}], "inventory": {"macaddress_a": "00:00:00:00:00:00"}}, "jsonrpc": "2.0", "method": "host.create", "auth": "5bb48d0208688f222fbd346b1d9a17a6", "id": 45}', -32602)
                      
                      In [210]: zapi.hostgroup.get({"filter":{"name":'switch'}})
                      Out[210]: [{u'groupid': u'9'}]
                      
                      In [211]: zapi.template.get({"filter":{"name":'dlink.des-3200-26'}})
                      Out[211]: [{u'hostid': u'10124', u'templateid': u'10124'}]
                      спасибо.
                      There are two problems with the interface:
                      1. You should pass the "dns" attribute, and empty string if you don't use DNS;
                      2. The "main" attribute is a boolean value, so it can't be set to "2".

                      Comment

                      • fast-l
                        Junior Member
                        • Sep 2012
                        • 3

                        #26
                        Originally posted by Pavels
                        There are two problems with the interface:
                        1. You should pass the "dns" attribute, and empty string if you don't use DNS;
                        2. The "main" attribute is a boolean value, so it can't be set to "2".

                        Да дело было в этом. Спасибо.

                        Code:
                        In [31]: zapi.host.create({
                                        "host":"testsw",
                                        "interfaces":[{
                                                        "type":2, "dns":"",
                                                        "main":1,
                                                        "ip":"172.17.22.33",
                                                        "port":161,
                                                        "useip":1}],
                                        "groups":    [{"groupid": u'9'}],
                                        "templates": [{ "templateid":10124 }],
                                        "inventory": { "macaddress_a":"00:00:00:00:00:00" }
                                        })
                        
                        Out[31]: {u'hostids': [u'10143']}
                        fixed and woking rghit now. thanks a lot
                        Last edited by fast-l; 01-10-2012, 16:18.

                        Comment

                        Working...