Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-7404

Zabbix API configuration.export is broken on node based setups

    XMLWordPrintable

    Details

    • Type: Incident report
    • Status: Closed
    • Priority: Major
    • Resolution: Won't fix
    • Affects Version/s: 2.0.9
    • Fix Version/s: None
    • Component/s: API (A), Frontend (F)
    • Environment:
      Zabbix 2.0.9
      Ubuntu 12.04
      MySQL 5.6.8
      Authentication Type: HTTP BASIC Auth

      Description

      We are using the zabbix api to create xml backups of our zabbix templates.

      How to reproduce the problem:
      1.) Use a zabbix setup with two nodes
      2.) WEG-GUI: ogin to the parent node using basic auth/http auth
      3.) WEB-GUI: Select the parent node foo with node id "1"
      4.) API: Start a export of the templates of node "1" using the same user
      => The output seems to be correct
      5.) WEB-GUI: Select the child node foo with node id "2"
      6.) API: Start again a export of the templates of node "1" using the same user
      => The output is broken (see attached diff)

      We wrote the following ruby code to backup the templates:
      (https://github.com/vadv/zabbixapi)

      #!/usr/bin/ruby
      #
      # sudo apt-get install ruby-dev ruby 
      # gem install --user-install zabbixapi"
      # gem install --user-install inifile 
      # gem install --user-install json
      # gem install --user-install rexml/document
      # gem install --user-install highline
      
      require "zabbixapi"
      require "inifile"
      require 'json'
      require "rexml/document"
      require "highline/import"
      
      def gatherTemplates(zbx, nodeid)
      
         templates = zbx.query(
             :method => "template.get",
             :params => {
                 :output => :extend,
                 :nodeids => nodeid,
             }
         )
      
         for template in templates do
            #puts JSON.pretty_generate(template)
      
            printf "Filename : '%s/%s'\n", Dir.pwd(), template["host"]+".xml"
      
            template_xml = zbx.query(
                :method => "configuration.export",
                :params => {
                  :options => {
                    :templates => [ template["templateid"] ],
                  },
                  :format => 'xml',
                },
            )
      
            #puts template_xml
      
      
            xml=REXML::Document.new(template_xml);
            formatter = REXML::Formatters::Pretty.new
            formatter.compact = true
            formatter.width = 1000000
            File.open(template["host"]+".xml","w"){|file| file.puts formatter.write(xml.root,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")}
            #exit 1
         end
      end
      
      
      zbx = ZabbixApi.connect(
        :url => inifile['global']["url"],
        :user => inifile['global']["user"],
        :password => inifile['global']["password"],
        :http_user => inifile['global']["user"],
        :http_password => inifile['global']["password"],
      )
      
      gatherTemplates(zbx, "1")
      gatherTemplates(zbx, "2")
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            scoopex Marc Schoechlin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: