Ad Widget

Collapse

Any idea why my template won't upload in the API?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mysterysmith
    Junior Member
    • Jul 2016
    • 12

    #1

    Any idea why my template won't upload in the API?

    I'm using the following code which works for several other templates:

    Code:
    def uploadTemplate(url, token, xml):
    
        template_data = '{"jsonrpc" : "2.0", "method": "configuration.import", "params": {"format" : "xml", "rules" : { "templates": { "createMissing": "true", "updateExisting": "true"}, "applications": { "createMissing": "true", "updateExisting": "true" }, "items": { "createMissing": "true", "updateExisting": "true" }, "triggers": { "createMissing": "true", "updateExisting": "true" }, "graphs": { "createMissing": "true", "updateExisting": "true" }, "discoveryRules": { "createMissing": "true", "updateExisting": "true" }, "screens": { "createMissing": "true", "updateExisting": "true" }, "groups": { "createMissing": "true" }, "hosts": { "createMissing": "true", "updateExisting": "true" }, "images": { "createMissing": "true", "updateExisting": "true" }, "maps": { "createMissing": "true", "updateExisting": "true" }, "templateLinkage": { "createMissing": "true" }, "templateScreens": { "createMissing": "true", "updateExisting": "true" }}, "source": "' + xml + '"}, "auth": "' + token + '", "id": 1}'
        json_header = {'content-type': 'application/json-rpc'}
    
        try:
            xml_payload = requests.post(url,
                                          data=template_data,
                                          headers=json_header)
            print xml_payload.headers
            return xml_payload.json()
        except:
            print "Unexpected error: %s" % sys.exc_info()[0]
            raise
    Attached Files
  • jan.garaj
    Senior Member
    Zabbix Certified Specialist
    • Jan 2010
    • 506

    #2
    Probably some special char(s) in your template, so your xml variable is not valid json string.

    You can test it in Zapix - check examples https://github.com/monitoringartist/zapix#examples
    Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
    My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

    Comment

    • mysterysmith
      Junior Member
      • Jul 2016
      • 12

      #3
      Yeah - " doesn't translate very well in a template upload via the API. If you search and replace " with \" it uploads via the API just fine.

      Comment

      Working...