[ZBX-7404] Zabbix API configuration.export is broken on node based setups Created: 2013 Nov 19  Updated: 2017 May 30  Resolved: 2014 May 10

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A), Frontend (F)
Affects Version/s: 2.0.9
Fix Version/s: None

Type: Incident report Priority: Major
Reporter: Marc Schoechlin Assignee: Unassigned
Resolution: Won't fix Votes: 0
Labels: api, distributed, frontend
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Zabbix 2.0.9
Ubuntu 12.04
MySQL 5.6.8
Authentication Type: HTTP BASIC Auth


Attachments: File broken-api.diff    

 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")


 Comments   
Comment by richlv [ 2013 Nov 19 ]

likely to be a dupe of ZBX-7152

Comment by Marc Schoechlin [ 2013 Nov 19 ]

Yes, i do not think that this is exactly the same problem, but it seems that this problems is related/the same class of problem.

Comment by richlv [ 2014 May 10 ]

with node based distributed monitoring being removed for 2.4, this is unlikely to get looked into for earlier versions

Generated at Sat May 24 07:23:22 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.