zabbixapi 2.4.1 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2734200ca0b6c573e6830ef2123d7ab8efb07095
4
- data.tar.gz: 55c0ba98d8d8465c97006ac5718246f25293c3ce
3
+ metadata.gz: 8238184f0f09f3d6c538181126166da072a5169e
4
+ data.tar.gz: 6d4cadbadda8ccaffb3d99aec2234ed26135b727
5
5
  SHA512:
6
- metadata.gz: 5b95307bb8ebee4a7625f4085fbc6c8db28dc7d84080ff0ab7d3448219c5914fd87e99ca413fe692fd7b272c22f6c81d63ec29b1f2dd580485a49e5f5703793c
7
- data.tar.gz: 213f659237904eec7adff7c01f6b55e6cd5a88f1ad7937606789ebaf967b800941bd3b926d241223837d455cba659686c19e486b590fe918ce95068a493027d2
6
+ metadata.gz: 8ddd92123ebe7bb0164340f8ff08beee81fdfe759b796a43b59c02053884bca9f70308069a6ec00f992fb6c5a2bd08254cefdafe450b1a4dec1a3eb6c377a64b
7
+ data.tar.gz: bbbe5b33e8da8c79c4cc68537dc327cdf905431baece04a3e4d0c2740ef70ea3de72de68cdfbda0297a243e8b0e7bfecefac93ea90a8b7f9f7ebc045794ef883
data/README.md CHANGED
@@ -28,7 +28,7 @@ We support only three last versions of zabbix (2.0, 2.2 and 2.4), so you should
28
28
 
29
29
  ## Installation
30
30
  ```
31
- gem install zabbixapi -v 2.4.1
31
+ gem install zabbixapi -v 2.4.2
32
32
  ```
33
33
 
34
34
  ## Getting Started
@@ -343,6 +343,36 @@ zbx.proxies.create(
343
343
  )
344
344
  ```
345
345
 
346
+ ### Export object
347
+
348
+ ```ruby
349
+ zbx.configurations.export(
350
+ :format => "xml",
351
+ :options => {
352
+ :templates => [zbx.templates.get_id(:host => "template")]
353
+ }
354
+ )
355
+ ```
356
+
357
+ ### Import object
358
+
359
+ ```ruby
360
+ zbx.configurations.import(
361
+ :format => "xml",
362
+ :rules => {
363
+ :templates => {
364
+ :createMissing => true,
365
+ :updateExisting => true
366
+ },
367
+ :items => {
368
+ :createMissing => true,
369
+ :updateExisting => true
370
+ }
371
+ },
372
+ :source => "<!--?xml version=\"1.0\" encoding=\"UTF-8\"?--><zabbix_export><version>2.0</version><date>2012-04-18T11:20:14Z</date><groups><group><name>Zabbix servers</name></group></groups><hosts><host><host>Export host</host><name>Export host</name><proxyid>0</proxyid><status>0</status><ipmi_authtype>-1</ipmi_authtype><ipmi_privilege>2</ipmi_privilege><ipmi_username></ipmi_username><ipmi_password></ipmi_password><templates></templates><groups><group><name>Zabbix servers</name></group></groups><interfaces><interface><default>1</default><type>1</type><useip>1</useip><ip>127.0.0.1</ip><dns></dns><port>10050</port><interface_ref>if1</interface_ref></interface></interfaces><applications><application><name>Application</name></application></applications><items><item><name>Item</name><type>0</type><snmp_community></snmp_community><multiplier>0</multiplier><snmp_oid></snmp_oid><key>item.key</key><delay>30</delay><history>90</history><trends>365</trends><status>0</status><value_type>3</value_type><allowed_hosts></allowed_hosts><units></units><delta>0</delta><snmpv3_securityname></snmpv3_securityname><snmpv3_securitylevel>0</snmpv3_securitylevel><snmpv3_authpassphrase></snmpv3_authpassphrase><snmpv3_privpassphrase></snmpv3_privpassphrase><formula>1</formula><delay_flex></delay_flex><params></params><ipmi_sensor></ipmi_sensor><data_type>0</data_type><authtype>0</authtype><username></username><password></password><publickey></publickey><privatekey></privatekey><port></port><description></description><inventory_link>0</inventory_link><applications><application><name>Application</name></application></applications><valuemap></valuemap><interface_ref>if1</interface_ref></item></items><discovery_rules></discovery_rules><macros></macros><inventory></inventory></host></hosts><triggers><trigger><expression>{Export host:item.key.last(0)}=0</expression><name>Trigger</name><url></url><status>0</status><priority>2</priority><description>Host trigger</description><type>0</type><dependencies></dependencies></trigger></triggers><graphs><graph><name>Graph</name><width>900</width><height>200</height><yaxismin>0.0000</yaxismin><yaxismax>100.0000</yaxismax><show_work_period>1</show_work_period><show_triggers>1</show_triggers><type>0</type><show_legend>1</show_legend><show_3d>0</show_3d><percent_left>0.0000</percent_left><percent_right>0.0000</percent_right><ymin_type_1>0</ymin_type_1><ymax_type_1>0</ymax_type_1><ymin_item_1>0</ymin_item_1><ymax_item_1>0</ymax_item_1><graph_items><graph_item><sortorder>0</sortorder><drawtype>0</drawtype><color>C80000</color><yaxisside>0</yaxisside><calc_fnc>7</calc_fnc><type>0</type><item><host>Export host</host><key>item.key</key></item></graph_item></graph_items></graph></graphs></zabbix_export>"
373
+ )
374
+ ```
375
+
346
376
  ### User and global macros
347
377
  ```ruby
348
378
  zbx.usermacros.create(
data/lib/zabbixapi.rb CHANGED
@@ -22,6 +22,7 @@ require "zabbixapi/classes/unusable"
22
22
  require "zabbixapi/classes/usergroups"
23
23
  require "zabbixapi/classes/usermacros"
24
24
  require "zabbixapi/classes/users"
25
+ require "zabbixapi/classes/configurations"
25
26
 
26
27
  class ZabbixApi
27
28
 
@@ -85,7 +86,7 @@ class ZabbixApi
85
86
 
86
87
  def screens
87
88
  @screens ||= Screens.new(@client)
88
- end
89
+ end
89
90
 
90
91
  def usergroups
91
92
  @usergroups ||= Usergroups.new(@client)
@@ -99,6 +100,10 @@ class ZabbixApi
99
100
  @mediatypes ||= Mediatypes.new(@client)
100
101
  end
101
102
 
103
+ def configurations
104
+ @configurations ||= Configurations.new(@client)
105
+ end
106
+
102
107
  end
103
108
 
104
109
 
@@ -1,6 +1,8 @@
1
1
  class ZabbixApi
2
2
  class Applications
3
3
 
4
+ API_PARAMETERS = %w(applicationids groupids hostids inherited itemids templated templateids expandData selectHosts selectItems)
5
+
4
6
  def initialize(client)
5
7
  @client = client
6
8
  end
@@ -31,7 +33,11 @@ class ZabbixApi
31
33
  end
32
34
 
33
35
  def get_full_data(data)
34
- @client.api_request(:method => "application.get", :params => {:filter => data, :output => "extend"})
36
+ filter_params = {}
37
+ request_data = data.dup # Duplicate data, as we modify it. Otherwise methods that use data after calling get_full_data (such as get_id) will fail.
38
+
39
+ request_data.each { |key, value| filter_params[key] = request_data.delete(key) unless API_PARAMETERS.include?(key) }
40
+ @client.api_request(:method => "application.get", :params => request_data.merge({:filter => filter_params, :output => "extend"}))
35
41
  end
36
42
 
37
43
  def get_id(data)
@@ -0,0 +1,36 @@
1
+ class ZabbixApi
2
+ class Configurations < Basic
3
+
4
+ def array_flag
5
+ true
6
+ end
7
+
8
+ def method_name
9
+ "configuration"
10
+ end
11
+
12
+ def indentify
13
+ "host"
14
+ end
15
+
16
+ # Export configuration data as a serialized string
17
+ # * *Args* :
18
+ # see available parameters: https://www.zabbix.com/documentation/2.2/manual/api/reference/configuration/export
19
+ # * *Returns* :
20
+ # - String
21
+ def export(data)
22
+ @client.api_request(:method => "configuration.export", :params => data)
23
+ end
24
+
25
+ # Import configurations data from a serialized string
26
+ # * *Args* :
27
+ # see available parameters: https://www.zabbix.com/documentation/2.2/manual/api/reference/configuration/import
28
+ # * *Returns* :
29
+ # - Boolean
30
+ def import(data)
31
+ @client.api_request(:method => "configuration.import", :params => data)
32
+ end
33
+
34
+ end
35
+ end
36
+
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "2.4.1"
2
+ VERSION = "2.4.2"
3
3
  end
@@ -0,0 +1,122 @@
1
+ #encoding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe "configuration" do
6
+ before :all do
7
+ @hostgroup = gen_name "hostgroup"
8
+ @hostgroup_id = zbx.hostgroups.create(:name => @hostgroup)
9
+ @template = gen_name "template"
10
+ @template_id = zbx.templates.create(
11
+ :host => @template,
12
+ :groups => [:groupid => @hostgroup_id]
13
+ )
14
+ @source = zbx.configurations.export(
15
+ :format => "xml",
16
+ :options => {
17
+ :templates => [@template_id]
18
+ }
19
+ )
20
+ @item = gen_name "item"
21
+ @item_id = zbx.items.create(
22
+ :name => @item,
23
+ :description => "item",
24
+ :key_ => "proc.num[aaa]",
25
+ :type => 0,
26
+ :value_type => 3,
27
+ :hostid => zbx.templates.get_id(:host => @template),
28
+ )
29
+ end
30
+
31
+ after :all do
32
+ zbx.items.delete(zbx.items.get_id(:name => @item))
33
+ zbx.templates.delete(zbx.templates.get_id(:host => @template))
34
+ zbx.hostgroups.delete(zbx.hostgroups.get_id(:name => @hostgroup))
35
+ end
36
+
37
+ context "when object not exists" do
38
+ describe "import with createMissing" do
39
+ before do
40
+ zbx.items.delete(@item_id)
41
+ zbx.templates.delete(@template_id)
42
+ zbx.hostgroups.delete(@hostgroup_id)
43
+ zbx.configurations.import(
44
+ :format => "xml",
45
+ :rules => {
46
+ :groups => {
47
+ :createMissing => true
48
+ },
49
+ :templates => {
50
+ :createMissing => true
51
+ }
52
+ },
53
+ :source => @source
54
+ )
55
+ end
56
+
57
+ it "should create object" do
58
+ expect(zbx.hostgroups.get_id(:name => @hostgroup)).to be_kind_of(Integer)
59
+ expect(zbx.templates.get_id(:host => @template)).to be_kind_of(Integer)
60
+ end
61
+ end
62
+ end
63
+
64
+ context "when object exists" do
65
+
66
+ describe "export" do
67
+ before do
68
+ zbx.items.create(
69
+ :name => @item,
70
+ :description => "item",
71
+ :key_ => "proc.num[aaa]",
72
+ :type => 0,
73
+ :value_type => 3,
74
+ :hostid => zbx.templates.get_id(:host => @template),
75
+ )
76
+ end
77
+
78
+ it "should export updated object" do
79
+ expect(zbx.configurations.export(
80
+ :format => "xml",
81
+ :options => {
82
+ :templates => [zbx.templates.get_id(:host => @template)]
83
+ }
84
+ )).to match(/#{@item}/)
85
+ end
86
+ end
87
+
88
+ describe "import with updateExisting" do
89
+ before do
90
+ @source_updated = zbx.configurations.export(
91
+ :format => "xml",
92
+ :options => {
93
+ :templates => [zbx.templates.get_id(:host => @template)]
94
+ }
95
+ )
96
+ zbx.items.delete(zbx.items.get_id(:name => @item))
97
+ zbx.configurations.import(
98
+ :format => "xml",
99
+ :rules => {
100
+ :templates => {
101
+ :updateExisting => true
102
+ },
103
+ :items => {
104
+ :createMissing => true
105
+ }
106
+ },
107
+ :source => @source_updated
108
+ )
109
+ end
110
+
111
+ it "should update object" do
112
+ expect(zbx.configurations.export(
113
+ :format => "xml",
114
+ :options => {
115
+ :templates => [zbx.templates.get_id(:host => @template)]
116
+ }
117
+ )).to match(/#{@item}/)
118
+ end
119
+ end
120
+ end
121
+ end
122
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbixapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliev D.V.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-01 00:00:00.000000000 Z
12
+ date: 2014-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -52,6 +52,7 @@ files:
52
52
  - lib/zabbixapi/basic/basic_init.rb
53
53
  - lib/zabbixapi/basic/basic_logic.rb
54
54
  - lib/zabbixapi/classes/applications.rb
55
+ - lib/zabbixapi/classes/configurations.rb
55
56
  - lib/zabbixapi/classes/errors.rb
56
57
  - lib/zabbixapi/classes/graphs.rb
57
58
  - lib/zabbixapi/classes/hostgroups.rb
@@ -71,6 +72,7 @@ files:
71
72
  - lib/zabbixapi/version.rb
72
73
  - spec/application.rb
73
74
  - spec/basic_func.rb
75
+ - spec/configuration.rb
74
76
  - spec/graph.rb
75
77
  - spec/host.rb
76
78
  - spec/hostgroup.rb
@@ -112,6 +114,7 @@ summary: Realization for Zabbix API.
112
114
  test_files:
113
115
  - spec/application.rb
114
116
  - spec/basic_func.rb
117
+ - spec/configuration.rb
115
118
  - spec/graph.rb
116
119
  - spec/host.rb
117
120
  - spec/hostgroup.rb