zabbixapi 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -0
- data/lib/zabbixapi.rb +6 -1
- data/lib/zabbixapi/classes/applications.rb +7 -1
- data/lib/zabbixapi/classes/configurations.rb +36 -0
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/configuration.rb +122 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1af8e059d91bcd50ee36f944393de794e0072d2
|
4
|
+
data.tar.gz: 3975f68a19eff6923a223943bd8d3511e6c4e088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10ffe07da786c3a7cbc6b33fdd4d1c397d5b2ce8115cbacfe26d5c1136b4ade6d1cfb70e5a63558195b998d0aae8ed3c70ff20c946b01947eb4c42f93543a95a
|
7
|
+
data.tar.gz: c19d6d4e47b3c500dfe5e87a9dc40bd6d35570608663817a28944cf72323babda2b0f7b03f569976c2a838d9265542da775dd5a2ff9422751db06b05cafd54d9
|
data/README.md
CHANGED
@@ -341,6 +341,36 @@ zbx.proxies.create(
|
|
341
341
|
)
|
342
342
|
```
|
343
343
|
|
344
|
+
### Export object
|
345
|
+
|
346
|
+
```ruby
|
347
|
+
zbx.configurations.export(
|
348
|
+
:format => "xml",
|
349
|
+
:options => {
|
350
|
+
:templates => [zbx.templates.get_id(:host => "template")]
|
351
|
+
}
|
352
|
+
)
|
353
|
+
```
|
354
|
+
|
355
|
+
### Import object
|
356
|
+
|
357
|
+
```ruby
|
358
|
+
zbx.configurations.import(
|
359
|
+
:format => "xml",
|
360
|
+
:rules => {
|
361
|
+
:templates => {
|
362
|
+
:createMissing => true,
|
363
|
+
:updateExisting => true
|
364
|
+
},
|
365
|
+
:items => {
|
366
|
+
:createMissing => true,
|
367
|
+
:updateExisting => true
|
368
|
+
}
|
369
|
+
},
|
370
|
+
: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>"
|
371
|
+
)
|
372
|
+
```
|
373
|
+
|
344
374
|
### User and global macros
|
345
375
|
```ruby
|
346
376
|
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
|
|
@@ -88,7 +89,7 @@ class ZabbixApi
|
|
88
89
|
|
89
90
|
def screens
|
90
91
|
@screens ||= Screens.new(@client)
|
91
|
-
end
|
92
|
+
end
|
92
93
|
|
93
94
|
def usergroups
|
94
95
|
@usergroups ||= Usergroups.new(@client)
|
@@ -102,5 +103,9 @@ class ZabbixApi
|
|
102
103
|
@mediatypes ||= Mediatypes.new(@client)
|
103
104
|
end
|
104
105
|
|
106
|
+
def configurations
|
107
|
+
@configurations ||= Configurations.new(@client)
|
108
|
+
end
|
109
|
+
|
105
110
|
end
|
106
111
|
|
@@ -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
|
-
|
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
|
+
|
data/lib/zabbixapi/version.rb
CHANGED
@@ -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
|
+
|
data/spec/spec_helper.rb
CHANGED
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.2.
|
4
|
+
version: 2.2.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-07
|
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
|