Ad Widget

Collapse

Configuration Import zabbix API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • borrelnoot
    Junior Member
    • Jun 2013
    • 3

    #1

    Configuration Import zabbix API

    Hi All,

    I'm trying to import configuration data via the Zabbix API, but it's not working.
    For the test I've copied the example import data from this URL



    I've created a script to handle the authentication and post the data via CURL
    I edited the source data from the example to something logical for my environment (IP, servername etc).

    Now, when I import the data via the API the response is what I expect it to be {"jsonrpc":"2.0","result":true,"id":1}

    But when I look into Zabbix, nothing happened, no host is added!
    When I import the source data via the webui, it works so the data is OK.

    I'm using the latest Zabbix version, Zabbix 2.0.6
    Can someone help with this one?

    Thanks a lot
    Kind Regards
    Ruud
  • viktorkho
    Member
    • Jul 2013
    • 90

    #2
    Example

    Hi All,

    I wan to confirm a problem with working examples

    Because all of this is experimental,
    I use external JSON file with included "prepared" XML-string, as described in documentation's examle (configuration.import)

    ("prepared" xml-string = all data from exported xml-file without new lines and spaces and this comment: <!--?xml version=\"1.0\" encoding=\"UTF-8\"?-->)

    JSON file:
    Code:
    {
        "jsonrpc": "2.0",
        "method": "configuration.import",
        "params": {
            "format": "xml",
            "rules": {
                "templates": {
                    "createMissing": true,
                    "updateExisting": true
                },
                "items": {
                    "createMissing": true,
                    "updateExisting": true
                }
            },
            "source": "<zabbix_export><version>2.0</version>...</zabbix_export>"
        },
        "auth": "91ea4764dcab42e8317b399c42985792",
        "id": 1
    }
    Simple bash script:
    Code:
    #! /bin/bash
    
    apiurl="http://10.254.254.1/zabbix/api_jsonrpc.php" 
    
    ## Getting Auth Token:
    #json_auth_data='{"jsonrpc":"2.0","method":"user.authenticate","params":{"user":"Admin","password":"zabbix"},"auth":null,"id":0}'
    #auth_token=$(curl -i -X POST -H 'Content-Type:application/json' \
        -d $json_auth_data $apiurl 2>/dev/null | grep result | cut -d'"' -f 8)
    ## But in examples I will use static one:
    auth_token="91ea4764dcab42e8317b399c42985792" 
    
    curl -i -X POST -H 'Content-Type:application/json' \
        -d "$(cat /root/zapi/conf_import.json)" $apiurl
    Execution:
    Code:
    # ./zcurl.sh
    HTTP/1.1 100 Continue
    
    HTTP/1.1 200 OK
    Date: Tue, 09 Jul 2013 13:37:21 GMT
    Server: Apache/2.2.15 (CentOS)
    X-Powered-By: PHP/5.3.3
    Content-Length: 38
    Connection: close
    Content-Type: application/json
    
    {"jsonrpc":"2.0","result":true,"id":1}

    Is it a bug or what can we do to make it work?

    Comment

    Working...