Ad Widget

Collapse

Import map.xml with api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • esawyja
    Member
    Zabbix Certified Specialist
    • Dec 2011
    • 54

    #1

    Import map.xml with api

    Hi all,
    I have the following code that I use to import hosts etc, it seems that the source line must be linarized? see below
    #! /bin/bash

    curl -i -X POST -H 'Content-Type:application/json' -d'
    {
    "jsonrpc": "2.0",
    "method": "configuration.import",
    "params": {
    "format": "xml",
    "rules": {
    "hosts": {
    "createMissing": true,
    "updateExisting": true
    },
    "groups": {
    "createMissing": true,
    "updateExisting": true
    },
    "items": {
    "createMissing": true,
    "updateExisting": true
    },
    "applications": {
    "createMissing": true,
    "updateExisting": true
    },
    "triggers": {
    "createMissing": true,
    "updateExisting": true
    },
    "templateLinkage" : {
    "createMissing": true
    },
    "graphs": {
    "createMissing": true,
    "updateExisting": true
    }
    },
    "source": "<!--?xmlversion=\"1.0\"encoding=\"UTF-8\"?--><zabbix_export><version>2.0</version><date>2015-08-26T07:23:04Z</date><groups><group><name>Linuxservers</name></group></groups><hosts><host><host>zab_dl</host><name>zab_dl</name><description/><proxy/><status>0</status><ipmi_authtype>-1</ipmi_authtype><ipmi_privilege>2</ipmi_privilege><ipmi_username/><ipmi_password/><templates><template><name>TemplateOSLinux</name></template><template><name>Template_Oracle</name></template></templates><groups><group><name>Linuxservers</name></group></groups><interfaces><interface><default>1</default><type>1</type><useip>1</useip><ip>172.28.200.167</ip><dns/><port>10050</port><bulk>1</bulk><interface_ref>if1</interface_ref></interface></interfaces><applications/><items/><discovery_rules/><macros/><inventory/></host></hosts></zabbix_export>"
    },
    "auth": "d4cfb53050bc1d1efa59c510bb4246d7",
    "id": 1
    }
    ' http://172.28.200.170/zabbix/api_jsonrpc.php

    With a map.xml that imports without any problems using the gui, the method above does not seem to work, I suspect the map file might be to big? the only error I see is
    HTTP/1.1 100 Continue

    HTTP/1.1 200 OK
    Date: Tue, 08 Sep 2015 01:11:45 GMT
    Server: Apache/2.2.12 (Linux/SUSE)
    X-Powered-By: PHP/5.3.17
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Headers: Content-Type
    Access-Control-Allow-Methods: POST
    Access-Control-Max-Age: 1000
    Content-Length: 124
    Content-Type: application/json

    {"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid Request.","data":"JSON-rpc version is not specified."},"id":null}

    My question is, using the method above, is there a way to specify the actual map file instead of linarizing the source?

    Please help, I'm out of ideas
  • gleepwurp
    Senior Member
    • Mar 2014
    • 119

    #2
    Hi esawyja,

    I think it would be easier to use one of the following methods:

    1- Export an existing map to xml, modify it according to taste and re-import it using the Zabbix Frontend Import function.

    - OR -

    2- Use the Zabbix API for maps (https://www.zabbix.com/documentation.../reference/map) and you will find life easier.

    Good luck!

    G.

    Comment

    Working...