zabbixapi 2.2.4 → 2.4.0
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/.travis.yml +2 -2
- data/README.md +5 -33
- data/lib/zabbixapi.rb +2 -13
- data/lib/zabbixapi/basic/basic_func.rb +12 -23
- data/lib/zabbixapi/basic/basic_logic.rb +10 -17
- data/lib/zabbixapi/classes/applications.rb +1 -7
- data/lib/zabbixapi/classes/hosts.rb +2 -7
- data/lib/zabbixapi/classes/triggers.rb +0 -3
- data/lib/zabbixapi/client.rb +8 -2
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/host.rb +6 -37
- data/spec/query.rb +8 -3
- data/spec/server.rb +2 -2
- metadata +12 -18
- data/lib/zabbixapi/classes/configurations.rb +0 -36
- data/lib/zabbixapi/classes/hostinterfaces.rb +0 -19
- data/spec/configuration.rb +0 -122
- data/spec/hostinterface.rb +0 -88
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d821fad6072067f4fcfb5a664165e19624b661f
|
|
4
|
+
data.tar.gz: 1f1a9adde080dbabc46a9333cd88bdf0d7328944
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c451bf0f57555ddda1827d8b73851614b7b04a2cd657788f30b7919a2d571ca468c9f90ff48922d316a9d7c7678e78c6888fbc5a492445568bc8eca3f848fb6f
|
|
7
|
+
data.tar.gz: 658565fe62621c59b5ed9d742b36cb71c1f11f8306c97f9715e2e4957e21a840587d5d0d81dbb4ea6cda4d1fef2cf7525672e8b1602b8073b23be720d93aa8bc
|
data/.travis.yml
CHANGED
|
@@ -5,8 +5,8 @@ rvm:
|
|
|
5
5
|
- 2.0.0
|
|
6
6
|
- 2.1.1
|
|
7
7
|
before_script:
|
|
8
|
-
- wget -qO - http://obs.express42.com/project_root:/zabbix2.
|
|
9
|
-
- echo "deb http://obs.express42.com/project_root:/zabbix2.
|
|
8
|
+
- wget -qO - http://obs.express42.com/project_root:/zabbix2.4/precise/Release.key | sudo apt-key add -
|
|
9
|
+
- echo "deb http://obs.express42.com/project_root:/zabbix2.4/precise/ ./" | sudo tee /etc/apt/sources.list.d/zabbix.list
|
|
10
10
|
- sudo apt-get update
|
|
11
11
|
- sudo apt-get install libiodbc2
|
|
12
12
|
- sudo apt-get install zabbix-server-pgsql zabbix-frontend-php
|
data/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Simple and lightweight ruby module for work with zabbix api
|
|
|
9
9
|
* 1.8.9 (api version 1.3) /zabbixapi 0.6.x [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
|
|
10
10
|
* 2.0.x (api version 1.4 -> 2.0.10) /zabbixapi 2.0.x [branch zabbix2.0](https://github.com/express42/zabbixapi/tree/zabbix2.0)
|
|
11
11
|
* 2.2.x (api version 2.2.x) /zabbixapi 2.2.x [master or branch zabbix2.2](https://github.com/express42/zabbixapi/tree/master)
|
|
12
|
+
* 2.4.x (api version 2.2.x) /zabbixapi 2.4.x [branch zabbix2.4](https://github.com/express42/zabbixapi/tree/zabbix2.4)
|
|
12
13
|
|
|
13
14
|
Because Zabbix 2.2 is a main branch of Zabbix, so master of zabbixapi supports this version of zabbix.
|
|
14
15
|
|
|
@@ -18,15 +19,16 @@ Zabbixapi has next version policy:
|
|
|
18
19
|
* for zabbix 1.8.9 and below you should use zabbixapi 0.6.x
|
|
19
20
|
* for zabbix 2.0.x you should use zabbixapi 2.0.y
|
|
20
21
|
* for zabbix 2.2.x you should use zabbixapi 2.2.y
|
|
22
|
+
* for zabbix 2.4.x you should use zabbixapi 2.4.y
|
|
21
23
|
|
|
22
24
|
The PATCH (third digit) version of zabbixapi should not correspond to PATCH version of zabbix, for example
|
|
23
25
|
zabbixapi-2.0.x should works with all version of zabbix 2.0.y
|
|
24
26
|
|
|
25
|
-
We support only
|
|
27
|
+
We support only three last versions of zabbix (2.0, 2.2 and 2.4), so you should consider zabbixapi 0.6.x depricated.
|
|
26
28
|
|
|
27
29
|
## Installation
|
|
28
30
|
```
|
|
29
|
-
gem install zabbixapi -v 2.
|
|
31
|
+
gem install zabbixapi -v 2.4.0
|
|
30
32
|
```
|
|
31
33
|
|
|
32
34
|
## Getting Started
|
|
@@ -341,36 +343,6 @@ zbx.proxies.create(
|
|
|
341
343
|
)
|
|
342
344
|
```
|
|
343
345
|
|
|
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
|
-
|
|
374
346
|
### User and global macros
|
|
375
347
|
```ruby
|
|
376
348
|
zbx.usermacros.create(
|
|
@@ -404,4 +376,4 @@ zbx.query(
|
|
|
404
376
|
## Zabbix documentation
|
|
405
377
|
|
|
406
378
|
* [Zabbix Project Homepage](http://zabbix.com/)
|
|
407
|
-
* [Zabbix Api docs](https://www.zabbix.com/documentation/2.
|
|
379
|
+
* [Zabbix Api docs](https://www.zabbix.com/documentation/2.4/manual/api/reference)
|
data/lib/zabbixapi.rb
CHANGED
|
@@ -22,8 +22,6 @@ 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"
|
|
26
|
-
require "zabbixapi/classes/hostinterfaces"
|
|
27
25
|
|
|
28
26
|
class ZabbixApi
|
|
29
27
|
|
|
@@ -43,9 +41,6 @@ class ZabbixApi
|
|
|
43
41
|
|
|
44
42
|
def initialize(options = {})
|
|
45
43
|
@client = Client.new(options)
|
|
46
|
-
unless @client.api_version =~ /2\.2\.\d+/
|
|
47
|
-
raise "Zabbix API version: #{@client.api_version} is not support by this version of zabbixapi"
|
|
48
|
-
end
|
|
49
44
|
end
|
|
50
45
|
|
|
51
46
|
def server
|
|
@@ -90,7 +85,7 @@ class ZabbixApi
|
|
|
90
85
|
|
|
91
86
|
def screens
|
|
92
87
|
@screens ||= Screens.new(@client)
|
|
93
|
-
end
|
|
88
|
+
end
|
|
94
89
|
|
|
95
90
|
def usergroups
|
|
96
91
|
@usergroups ||= Usergroups.new(@client)
|
|
@@ -104,12 +99,6 @@ class ZabbixApi
|
|
|
104
99
|
@mediatypes ||= Mediatypes.new(@client)
|
|
105
100
|
end
|
|
106
101
|
|
|
107
|
-
def configurations
|
|
108
|
-
@configurations ||= Configurations.new(@client)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def hostinterfaces
|
|
112
|
-
@hostinterfaces ||= Hostinterfaces.new(@client)
|
|
113
|
-
end
|
|
114
102
|
end
|
|
115
103
|
|
|
104
|
+
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
class Hash
|
|
2
|
-
def <=> (other_hash)
|
|
3
|
-
self.keys.collect!{|key| key.to_s} <=> other_hash.keys.collect!{|key| key.to_s}
|
|
4
|
-
end
|
|
5
|
-
end
|
|
6
|
-
|
|
7
1
|
class ZabbixApi
|
|
8
2
|
class Basic
|
|
9
3
|
|
|
@@ -12,8 +6,8 @@ class ZabbixApi
|
|
|
12
6
|
end
|
|
13
7
|
|
|
14
8
|
def hash_equals?(a, b)
|
|
15
|
-
a_new =
|
|
16
|
-
b_new =
|
|
9
|
+
a_new = normalize_hash(a)
|
|
10
|
+
b_new = normalize_hash(b)
|
|
17
11
|
hash1 = a_new.merge(b_new)
|
|
18
12
|
hash2 = b_new.merge(a_new)
|
|
19
13
|
hash1 == hash2
|
|
@@ -25,22 +19,17 @@ class ZabbixApi
|
|
|
25
19
|
obj
|
|
26
20
|
end
|
|
27
21
|
|
|
28
|
-
def
|
|
29
|
-
result =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
result = obj.dup
|
|
39
|
-
result.collect! {|item| normalize_obj(item)}
|
|
40
|
-
else
|
|
41
|
-
result = obj.to_s
|
|
22
|
+
def normalize_hash(hash)
|
|
23
|
+
result = hash.dup
|
|
24
|
+
result.delete(:hostid) #TODO remove to logig. TemplateID and HostID has different id
|
|
25
|
+
result.each do |key, value|
|
|
26
|
+
case value
|
|
27
|
+
when Array
|
|
28
|
+
result.delete(key)
|
|
29
|
+
else
|
|
30
|
+
result[key] = value.to_s
|
|
31
|
+
end
|
|
42
32
|
end
|
|
43
|
-
result.sort! if result.respond_to?(:sort!)
|
|
44
33
|
result
|
|
45
34
|
end
|
|
46
35
|
|
|
@@ -18,14 +18,14 @@ class ZabbixApi
|
|
|
18
18
|
parse_keys result
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def create_or_update(data
|
|
21
|
+
def create_or_update(data)
|
|
22
22
|
log "[DEBUG] Call create_or_update with parametrs: #{data.inspect}"
|
|
23
23
|
|
|
24
24
|
id = get_id(indentify.to_sym => data[indentify.to_sym])
|
|
25
|
-
id ? update(data.merge(key.to_sym => id.to_s)
|
|
25
|
+
id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def update(data
|
|
28
|
+
def update(data)
|
|
29
29
|
log "[DEBUG] Call update with parametrs: #{data.inspect}"
|
|
30
30
|
|
|
31
31
|
dump = {}
|
|
@@ -34,14 +34,10 @@ class ZabbixApi
|
|
|
34
34
|
dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
dump
|
|
38
|
-
data.delete(key.to_sym)
|
|
39
|
-
|
|
40
|
-
if hash_equals?(dump, data) && !force
|
|
37
|
+
if hash_equals?(dump, data)
|
|
41
38
|
log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
|
|
42
39
|
item_id
|
|
43
40
|
else
|
|
44
|
-
data[key.to_sym] = item_id
|
|
45
41
|
data_update = array_flag ? [data] : data
|
|
46
42
|
result = @client.api_request(:method => "#{method_name}.update", :params => data_update)
|
|
47
43
|
parse_keys result
|
|
@@ -50,25 +46,22 @@ class ZabbixApi
|
|
|
50
46
|
end
|
|
51
47
|
|
|
52
48
|
def get_full_data(data)
|
|
53
|
-
log "[DEBUG] Call get_full_data with parametrs: #{data.inspect}
|
|
49
|
+
log "[DEBUG] Call get_full_data with parametrs: #{data.inspect}"
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
res = @client.api_request(
|
|
51
|
+
@client.api_request(
|
|
57
52
|
:method => "#{method_name}.get",
|
|
58
53
|
:params => {
|
|
59
54
|
:filter => {
|
|
60
55
|
indentify.to_sym => data[indentify.to_sym]
|
|
61
56
|
},
|
|
62
57
|
:output => "extend"
|
|
63
|
-
}
|
|
58
|
+
}
|
|
64
59
|
)
|
|
65
|
-
res
|
|
66
60
|
end
|
|
67
61
|
|
|
68
62
|
def dump_by_id(data)
|
|
69
|
-
log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}
|
|
63
|
+
log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}"
|
|
70
64
|
|
|
71
|
-
data[:params] ||= {}
|
|
72
65
|
@client.api_request(
|
|
73
66
|
:method => "#{method_name}.get",
|
|
74
67
|
:params => {
|
|
@@ -76,7 +69,7 @@ class ZabbixApi
|
|
|
76
69
|
key.to_sym => data[key.to_sym]
|
|
77
70
|
},
|
|
78
71
|
:output => "extend"
|
|
79
|
-
}
|
|
72
|
+
}
|
|
80
73
|
)
|
|
81
74
|
end
|
|
82
75
|
|
|
@@ -93,7 +86,7 @@ class ZabbixApi
|
|
|
93
86
|
|
|
94
87
|
result = symbolize_keys( get_full_data(data) )
|
|
95
88
|
id = nil
|
|
96
|
-
result.each { |item| id = item[key.to_sym].to_i if item[indentify.to_sym]
|
|
89
|
+
result.each { |item| id = item[key.to_sym].to_i if item[indentify.to_sym] == data[indentify.to_sym] }
|
|
97
90
|
id
|
|
98
91
|
end
|
|
99
92
|
|
|
@@ -1,8 +1,6 @@
|
|
|
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
|
-
|
|
6
4
|
def initialize(client)
|
|
7
5
|
@client = client
|
|
8
6
|
end
|
|
@@ -33,11 +31,7 @@ class ZabbixApi
|
|
|
33
31
|
end
|
|
34
32
|
|
|
35
33
|
def get_full_data(data)
|
|
36
|
-
|
|
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"}))
|
|
34
|
+
@client.api_request(:method => "application.get", :params => {:filter => data, :output => "extend"})
|
|
41
35
|
end
|
|
42
36
|
|
|
43
37
|
def get_id(data)
|
|
@@ -35,14 +35,9 @@ class ZabbixApi
|
|
|
35
35
|
result.empty? ? false : true
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
def create_or_update(data
|
|
38
|
+
def create_or_update(data)
|
|
39
39
|
hostid = get_id(:host => data[:host])
|
|
40
|
-
hostid ? update(data.merge(:hostid => hostid)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# to make delete call idempotent for all resources
|
|
44
|
-
def delete(hostid)
|
|
45
|
-
super(:hostid => hostid)
|
|
40
|
+
hostid ? update(data.merge(:hostid => hostid)) : create(data)
|
|
46
41
|
end
|
|
47
42
|
end
|
|
48
43
|
end
|
|
@@ -49,13 +49,10 @@ class ZabbixApi
|
|
|
49
49
|
|
|
50
50
|
log "[DEBUG] expression: #{dump[:expression]}\n data: #{data[:expression]}"
|
|
51
51
|
|
|
52
|
-
dump.delete(key.to_sym)
|
|
53
|
-
data.delete(key.to_sym)
|
|
54
52
|
if hash_equals?(dump, data)
|
|
55
53
|
log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
|
|
56
54
|
item_id
|
|
57
55
|
else
|
|
58
|
-
data[key.to_sym] = item_id
|
|
59
56
|
data[:expression] = old_expression
|
|
60
57
|
# disable old trigger
|
|
61
58
|
log "[DEBUG] disable :" + @client.api_request(:method => "#{method_name}.update", :params => [{:triggerid=> data[:triggerid], :status => "1" }]).inspect
|
data/lib/zabbixapi/client.rb
CHANGED
|
@@ -17,7 +17,7 @@ class ZabbixApi
|
|
|
17
17
|
|
|
18
18
|
def auth
|
|
19
19
|
api_request(
|
|
20
|
-
:method => 'user.
|
|
20
|
+
:method => 'user.login',
|
|
21
21
|
:params => {
|
|
22
22
|
:user => @options[:user],
|
|
23
23
|
:password => @options[:password],
|
|
@@ -33,6 +33,9 @@ class ZabbixApi
|
|
|
33
33
|
@proxy_port = @proxy_uri.port
|
|
34
34
|
@proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
|
|
35
35
|
end
|
|
36
|
+
unless api_version =~ /2\.4\.\d+/
|
|
37
|
+
raise "Zabbix API version: #{api_version} is not support by this version of zabbixapi"
|
|
38
|
+
end
|
|
36
39
|
@auth_hash = auth
|
|
37
40
|
end
|
|
38
41
|
|
|
@@ -40,10 +43,12 @@ class ZabbixApi
|
|
|
40
43
|
message = {
|
|
41
44
|
:method => body[:method],
|
|
42
45
|
:params => body[:params],
|
|
43
|
-
:auth => @auth_hash,
|
|
44
46
|
:id => id,
|
|
45
47
|
:jsonrpc => '2.0'
|
|
46
48
|
}
|
|
49
|
+
|
|
50
|
+
message[:auth] = @auth_hash unless body[:method] == 'apiinfo.version'
|
|
51
|
+
|
|
47
52
|
JSON.generate(message)
|
|
48
53
|
end
|
|
49
54
|
|
|
@@ -92,3 +97,4 @@ class ZabbixApi
|
|
|
92
97
|
|
|
93
98
|
end
|
|
94
99
|
end
|
|
100
|
+
|
data/lib/zabbixapi/version.rb
CHANGED
data/spec/host.rb
CHANGED
|
@@ -5,9 +5,7 @@ require 'spec_helper'
|
|
|
5
5
|
describe 'host' do
|
|
6
6
|
before :all do
|
|
7
7
|
@hostgroup = gen_name 'hostgroup'
|
|
8
|
-
@hostgroup3 = gen_name 'hostgroup'
|
|
9
8
|
@hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
|
|
10
|
-
@hostgroupid3 = zbx.hostgroups.create(:name => @hostgroup3)
|
|
11
9
|
end
|
|
12
10
|
|
|
13
11
|
context 'when name not exists' do
|
|
@@ -38,15 +36,15 @@ describe 'host' do
|
|
|
38
36
|
@hostgroupid2 = zbx.hostgroups.create(:name => gen_name('hostgroup'))
|
|
39
37
|
host = gen_name('host')
|
|
40
38
|
hostid = zbx.hosts.create(
|
|
41
|
-
:
|
|
42
|
-
:
|
|
43
|
-
:
|
|
44
|
-
{:
|
|
45
|
-
{:
|
|
39
|
+
host: host,
|
|
40
|
+
interfaces: [{ type: 1, main: 1, ip: '192.168.0.1', dns: 'server.example.org', port: 10050, useip: 0 }],
|
|
41
|
+
groups: [
|
|
42
|
+
{groupid: @hostgroupid},
|
|
43
|
+
{groupid: @hostgroupid2}
|
|
46
44
|
])
|
|
47
45
|
|
|
48
46
|
expect(hostid).to be_kind_of Integer
|
|
49
|
-
host = zbx.query(:
|
|
47
|
+
host = zbx.query(method: 'host.get', params: { hostids: [hostid], selectGroups: 'extend' }).first
|
|
50
48
|
|
|
51
49
|
expect(host['hostid'].to_i).to eq hostid
|
|
52
50
|
expect(host['groups'].size).to eq 2
|
|
@@ -92,11 +90,6 @@ describe 'host' do
|
|
|
92
90
|
it "should contains created host" do
|
|
93
91
|
expect(zbx.hosts.get_full_data(:host => @host)[0]).to include("host" => @host)
|
|
94
92
|
end
|
|
95
|
-
|
|
96
|
-
it "shoulld dump interfaces" do
|
|
97
|
-
expect(zbx.hosts.get_full_data(:host => @host, :params => {:selectInterfaces => "extend"})[0]["interfaces"][0]).to include("type" => "1")
|
|
98
|
-
expect(zbx.hosts.get_full_data(:host => @host, :params => {:selectInterfaces => "extend"})[0]["interfaces"][0]).to include("ip" => "10.20.48.88")
|
|
99
|
-
end
|
|
100
93
|
end
|
|
101
94
|
|
|
102
95
|
describe 'get_id' do
|
|
@@ -122,30 +115,6 @@ describe 'host' do
|
|
|
122
115
|
:groups => [:groupid => @hostgroupid]
|
|
123
116
|
).should eq @hostid
|
|
124
117
|
end
|
|
125
|
-
|
|
126
|
-
it "should add ghostgroup" do
|
|
127
|
-
zbx.hosts.create_or_update( {
|
|
128
|
-
:host => @host,
|
|
129
|
-
:interfaces => [
|
|
130
|
-
{
|
|
131
|
-
:type => 1,
|
|
132
|
-
:main => 1,
|
|
133
|
-
:ip => "10.20.48.89",
|
|
134
|
-
:port => 10050,
|
|
135
|
-
:useip => 1,
|
|
136
|
-
:dns => ''
|
|
137
|
-
}
|
|
138
|
-
],
|
|
139
|
-
:groups => [{:groupid => @hostgroupid},
|
|
140
|
-
{:groupid => @hostgroupid3}]
|
|
141
|
-
}, true)
|
|
142
|
-
zbx.hosts.get_full_data(
|
|
143
|
-
:host => @host,
|
|
144
|
-
:params => {
|
|
145
|
-
:selectGroups => "extend"
|
|
146
|
-
}
|
|
147
|
-
)[0]["groups"].collect { |group| group["groupid"].to_s }.sort.should eq [@hostgroupid, @hostgroupid3].collect{|item| item.to_s}.sort
|
|
148
|
-
end
|
|
149
118
|
end
|
|
150
119
|
|
|
151
120
|
describe 'update' do
|
data/spec/query.rb
CHANGED
|
@@ -5,9 +5,14 @@ require 'spec_helper'
|
|
|
5
5
|
describe "query" do
|
|
6
6
|
it "should works" do
|
|
7
7
|
zbx.query(
|
|
8
|
-
:
|
|
9
|
-
:
|
|
10
|
-
|
|
8
|
+
method: 'host.get',
|
|
9
|
+
params: {
|
|
10
|
+
filter: {
|
|
11
|
+
host: 'asdf'
|
|
12
|
+
},
|
|
13
|
+
selectInterfaces: 'refer'
|
|
14
|
+
}
|
|
15
|
+
).should be_kind_of(Array)
|
|
11
16
|
end
|
|
12
17
|
end
|
|
13
18
|
|
data/spec/server.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.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vasiliev D.V.
|
|
@@ -9,26 +9,26 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: json
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
requirements:
|
|
18
|
-
- -
|
|
18
|
+
- - ~>
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
20
|
version: '1.6'
|
|
21
|
-
- -
|
|
21
|
+
- - '>='
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
23
|
version: 1.6.0
|
|
24
24
|
type: :runtime
|
|
25
25
|
prerelease: false
|
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
|
27
27
|
requirements:
|
|
28
|
-
- -
|
|
28
|
+
- - ~>
|
|
29
29
|
- !ruby/object:Gem::Version
|
|
30
30
|
version: '1.6'
|
|
31
|
-
- -
|
|
31
|
+
- - '>='
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: 1.6.0
|
|
34
34
|
description: Allows you to work with zabbix api from ruby.
|
|
@@ -39,9 +39,9 @@ executables: []
|
|
|
39
39
|
extensions: []
|
|
40
40
|
extra_rdoc_files: []
|
|
41
41
|
files:
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
42
|
+
- .gitignore
|
|
43
|
+
- .rspec
|
|
44
|
+
- .travis.yml
|
|
45
45
|
- Gemfile
|
|
46
46
|
- Gemfile.lock
|
|
47
47
|
- README.md
|
|
@@ -52,11 +52,9 @@ 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
|
|
56
55
|
- lib/zabbixapi/classes/errors.rb
|
|
57
56
|
- lib/zabbixapi/classes/graphs.rb
|
|
58
57
|
- lib/zabbixapi/classes/hostgroups.rb
|
|
59
|
-
- lib/zabbixapi/classes/hostinterfaces.rb
|
|
60
58
|
- lib/zabbixapi/classes/hosts.rb
|
|
61
59
|
- lib/zabbixapi/classes/items.rb
|
|
62
60
|
- lib/zabbixapi/classes/mediatypes.rb
|
|
@@ -73,11 +71,9 @@ files:
|
|
|
73
71
|
- lib/zabbixapi/version.rb
|
|
74
72
|
- spec/application.rb
|
|
75
73
|
- spec/basic_func.rb
|
|
76
|
-
- spec/configuration.rb
|
|
77
74
|
- spec/graph.rb
|
|
78
75
|
- spec/host.rb
|
|
79
76
|
- spec/hostgroup.rb
|
|
80
|
-
- spec/hostinterface.rb
|
|
81
77
|
- spec/item.rb
|
|
82
78
|
- spec/mediatype.rb
|
|
83
79
|
- spec/query.rb
|
|
@@ -99,28 +95,26 @@ require_paths:
|
|
|
99
95
|
- lib
|
|
100
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
97
|
requirements:
|
|
102
|
-
- -
|
|
98
|
+
- - '>='
|
|
103
99
|
- !ruby/object:Gem::Version
|
|
104
100
|
version: '0'
|
|
105
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
102
|
requirements:
|
|
107
|
-
- -
|
|
103
|
+
- - '>='
|
|
108
104
|
- !ruby/object:Gem::Version
|
|
109
105
|
version: '0'
|
|
110
106
|
requirements: []
|
|
111
107
|
rubyforge_project: zabbixapi
|
|
112
|
-
rubygems_version: 2.
|
|
108
|
+
rubygems_version: 2.2.2
|
|
113
109
|
signing_key:
|
|
114
110
|
specification_version: 4
|
|
115
111
|
summary: Realization for Zabbix API.
|
|
116
112
|
test_files:
|
|
117
113
|
- spec/application.rb
|
|
118
114
|
- spec/basic_func.rb
|
|
119
|
-
- spec/configuration.rb
|
|
120
115
|
- spec/graph.rb
|
|
121
116
|
- spec/host.rb
|
|
122
117
|
- spec/hostgroup.rb
|
|
123
|
-
- spec/hostinterface.rb
|
|
124
118
|
- spec/item.rb
|
|
125
119
|
- spec/mediatype.rb
|
|
126
120
|
- spec/query.rb
|
|
@@ -1,36 +0,0 @@
|
|
|
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/spec/configuration.rb
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
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/hostinterface.rb
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
#encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe "hostinterface" do
|
|
6
|
-
before :all do
|
|
7
|
-
@hostgroup = gen_name 'hostgroup'
|
|
8
|
-
@hostgroupid = zbx.hostgroups.create(:name => @hostgroup)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context 'when interface not exists' do
|
|
12
|
-
before do
|
|
13
|
-
@host = gen_name 'host'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe 'create' do
|
|
17
|
-
it 'should return integer id' do
|
|
18
|
-
@hostid = zbx.hosts.create(:host => @host,
|
|
19
|
-
:interfaces => [
|
|
20
|
-
{
|
|
21
|
-
:type => 1,
|
|
22
|
-
:main => 1,
|
|
23
|
-
:ip => "10.20.48.88",
|
|
24
|
-
:dns => "",
|
|
25
|
-
:port => 10050,
|
|
26
|
-
:useip => 1
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
:groups => [:groupid => @hostgroupid]
|
|
30
|
-
)
|
|
31
|
-
interfaceid = zbx.hostinterfaces.create(
|
|
32
|
-
:hostid => @hostid,
|
|
33
|
-
:dns => "",
|
|
34
|
-
:ip => "1.1.1.1",
|
|
35
|
-
:main => 0,
|
|
36
|
-
:port => '10050',
|
|
37
|
-
:type => 1,
|
|
38
|
-
:useip => 1
|
|
39
|
-
)
|
|
40
|
-
interfaceid.should be_kind_of(Integer)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe 'get_id' do
|
|
44
|
-
it "should return nil" do
|
|
45
|
-
random_id = gen_name('')
|
|
46
|
-
expect(zbx.hosts.get_id(:hostids => [random_id])).to be_kind_of(NilClass)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context 'when interface exists' do
|
|
53
|
-
before :all do
|
|
54
|
-
@host = gen_name 'host'
|
|
55
|
-
@hostid = zbx.hosts.create(
|
|
56
|
-
:host => @host,
|
|
57
|
-
:interfaces => [
|
|
58
|
-
{
|
|
59
|
-
:type => 1,
|
|
60
|
-
:main => 1,
|
|
61
|
-
:ip => "10.20.48.88",
|
|
62
|
-
:dns => "",
|
|
63
|
-
:port => 10050,
|
|
64
|
-
:useip => 1
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
:groups => [:groupid => @hostgroupid]
|
|
68
|
-
)
|
|
69
|
-
@interfaceid1 = zbx.hostinterfaces.create(:hostid => @hostid, :type => 1, :main => 0, :ip => "10.20.48.88", :dns => "", :port => 10050, :useip => 1)
|
|
70
|
-
@interfaceid2 = zbx.hostinterfaces.create(:hostid => @hostid, :type => 1, :main => 0, :ip => "10.20.48.88", :dns => "", :port => 10050, :useip => 1)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
describe 'get_full_data' do
|
|
74
|
-
it "should contains created host" do
|
|
75
|
-
expect(zbx.hostinterfaces.get_full_data(:params => {:filter => {:hostid => "#{@hostid}"}})[0]).to include("hostid" => "#{@hostid}")
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
describe 'get_id' do
|
|
80
|
-
it "should update existing interface" do
|
|
81
|
-
zbx.hostinterfaces.create_or_update(:interfaceid => @interfaceid1, :type => 2, :ip => "8.8.8.8")
|
|
82
|
-
dump = zbx.hostinterfaces.get_full_data(:interfaceid => @interfaceid1)
|
|
83
|
-
dump[0]["type"].to_s.should eq 2.to_s
|
|
84
|
-
dump[0]["ip"].to_s.should eq "8.8.8.8"
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|