zabbixapi 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/README.md +118 -9
- data/lib/zabbixapi/applications.rb +5 -1
- data/lib/zabbixapi/graphs.rb +22 -4
- data/lib/zabbixapi/hostgroups.rb +5 -1
- data/lib/zabbixapi/hosts.rb +10 -1
- data/lib/zabbixapi/items.rb +10 -1
- data/lib/zabbixapi/templates.rb +17 -2
- data/lib/zabbixapi/triggers.rb +10 -1
- data/lib/zabbixapi/users.rb +4 -9
- data/lib/zabbixapi/version.rb +1 -1
- data/spec/localhost.rb +52 -7
- data/spec/run.rb +51 -10
- data/zabbixapi.gemspec +1 -0
- metadata +8 -7
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format nested
|
data/README.md
CHANGED
@@ -17,6 +17,8 @@ gem install zabbixapi
|
|
17
17
|
|
18
18
|
### Connect
|
19
19
|
```ruby
|
20
|
+
require "zabbixapi"
|
21
|
+
|
20
22
|
zbx = ZabbixApi.connect(
|
21
23
|
:url => 'http://localhost/zabbix/api_jsonrpc.php',
|
22
24
|
:user => 'Admin',
|
@@ -52,29 +54,119 @@ zbx.items.create(
|
|
52
54
|
:hostid => zbx.templates.get_id(:host => "template"),
|
53
55
|
:applications => [zbx.applications.get_id(:name => "application")]
|
54
56
|
)
|
57
|
+
# or use (lib merge json):
|
58
|
+
zbx.items.create_or_update(
|
59
|
+
:description => "item",
|
60
|
+
:key_ => "proc.num[aaa]",
|
61
|
+
:type => 6,
|
62
|
+
:hostid => zbx.templates.get_id(:host => "template"),
|
63
|
+
:applications => [zbx.applications.get_id(:name => "application")]
|
64
|
+
)
|
65
|
+
```
|
66
|
+
|
67
|
+
### Update Item
|
68
|
+
```ruby
|
69
|
+
zbx.items.update(
|
70
|
+
:itemid => zbx.items.get_id(:description => "item"),
|
71
|
+
:status => 0
|
72
|
+
)
|
73
|
+
#You can check item:
|
74
|
+
puts zbx.items.get_full_data(:description => "item")
|
55
75
|
```
|
56
76
|
|
57
77
|
### Create host
|
58
78
|
```ruby
|
59
79
|
zbx.hosts.add(
|
60
80
|
:host => "hostname",
|
81
|
+
:usedns => 1,
|
61
82
|
:groups => [ :groupid => zbx.hostgroups.get_id(:name => "hostgroup") ]
|
62
83
|
)
|
84
|
+
#or use:
|
85
|
+
zbx.hosts.create_or_update(
|
86
|
+
:host => host,
|
87
|
+
:usedns => 0,
|
88
|
+
:ip => "10.20.48.89",
|
89
|
+
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
90
|
+
)
|
91
|
+
```
|
92
|
+
|
93
|
+
### Update host
|
94
|
+
```ruby
|
95
|
+
zbx.hosts.update(
|
96
|
+
:hostid => zbx.hosts.get_id(:host => "hostname"),
|
97
|
+
:status => 0
|
98
|
+
)
|
99
|
+
#You can check host:
|
100
|
+
puts zbx.hosts.get_full_data(:host => "hostname")
|
101
|
+
```
|
102
|
+
|
103
|
+
### Delete host
|
104
|
+
```ruby
|
105
|
+
zbx.hosts.delete zbx.hosts.get_id(:host => "hostname")
|
106
|
+
```
|
107
|
+
|
108
|
+
### Create graph
|
109
|
+
```ruby
|
110
|
+
gitems = {
|
111
|
+
:itemid => zbx.items.get_id(:description => "item"),
|
112
|
+
:calc_fnc => "2",
|
113
|
+
:type => "0",
|
114
|
+
:periods_cnt => "5"
|
115
|
+
}
|
116
|
+
|
117
|
+
zbx.graphs.create(
|
118
|
+
:gitems => [gitems],
|
119
|
+
:show_triggers => "0",
|
120
|
+
:name => "graph",
|
121
|
+
:width => "900",
|
122
|
+
:height => "200"
|
123
|
+
)
|
124
|
+
```
|
125
|
+
|
126
|
+
### Update graph
|
127
|
+
```ruby
|
128
|
+
zbx.graphs.update(
|
129
|
+
:graphid => zbx.graphs.get_id( :name => "graph"),
|
130
|
+
:ymax_type => 1
|
131
|
+
)
|
132
|
+
#Also you can use:
|
133
|
+
gitems = {
|
134
|
+
:itemid => zbx.items.get_id(:description => item),
|
135
|
+
:calc_fnc => "3",
|
136
|
+
:type => "0",
|
137
|
+
:periods_cnt => "5"
|
138
|
+
}
|
139
|
+
zbx.graphs.create_or_update(
|
140
|
+
:gitems => [gitems],
|
141
|
+
:show_triggers => "1",
|
142
|
+
:name => graph,
|
143
|
+
:width => "900",
|
144
|
+
:height => "200"
|
145
|
+
)
|
146
|
+
```
|
147
|
+
|
148
|
+
### Delete graph
|
149
|
+
```ruby
|
150
|
+
zbx.graphs.delete(zbx.graphs.get_id(:name => "graph"))
|
63
151
|
```
|
64
152
|
|
65
153
|
### Get all templates linked with host
|
66
154
|
```ruby
|
67
155
|
zbx.templates.get_ids_by_host( :hostids => [zbx.hosts.get_id(:host => "hostname")] )
|
68
|
-
returned hash:
|
69
|
-
{
|
70
|
-
"Templatename" => "10",
|
71
|
-
"Templatename" => "1021"
|
72
|
-
}
|
156
|
+
#returned hash:
|
157
|
+
#{
|
158
|
+
# "Templatename" => "10",
|
159
|
+
# "Templatename" => "1021"
|
160
|
+
#}
|
73
161
|
```
|
74
162
|
|
75
|
-
### Link host with templates
|
163
|
+
### Mass (Un)Link host with templates
|
76
164
|
```ruby
|
77
|
-
zbx.
|
165
|
+
zbx.templates.mass_add(
|
166
|
+
:hosts_id => [zbx.hosts.get_id(:host => "hostname")],
|
167
|
+
:templates_id => [111, 214]
|
168
|
+
)
|
169
|
+
zbx.templates.mass_remove(
|
78
170
|
:hosts_id => [zbx.hosts.get_id(:host => "hostname")],
|
79
171
|
:templates_id => [111, 214]
|
80
172
|
)
|
@@ -103,6 +195,16 @@ zbx.users.create(
|
|
103
195
|
)
|
104
196
|
```
|
105
197
|
|
198
|
+
### Update user
|
199
|
+
```ruby
|
200
|
+
zbx.users.update(:userid => zbx.users.get_id(:name => "user"), :name => "user2")
|
201
|
+
```
|
202
|
+
|
203
|
+
### Delete graph
|
204
|
+
```ruby
|
205
|
+
zbx.graphs.delete(zbx.graphs.get_id(:name => "graph"))
|
206
|
+
```
|
207
|
+
|
106
208
|
### Custom queries
|
107
209
|
```ruby
|
108
210
|
zbx.query(
|
@@ -117,7 +219,14 @@ zbx.query(
|
|
117
219
|
* net/https
|
118
220
|
* json
|
119
221
|
|
222
|
+
## Contributing
|
223
|
+
|
224
|
+
* Fork the project.
|
225
|
+
* Make your feature addition or bug fix, write tests.
|
226
|
+
* Commit, do not mess with rakefile, version.
|
227
|
+
* Make a pull request.
|
228
|
+
|
120
229
|
## Zabbix documentation
|
121
230
|
|
122
|
-
* Zabbix Project Homepage
|
123
|
-
* Zabbix Api docs
|
231
|
+
* [Zabbix Project Homepage](http://zabbix.com/)
|
232
|
+
* [Zabbix Api docs](http://www.zabbix.com/documentation/1.8/api)
|
@@ -30,7 +30,11 @@ class ZabbixApi
|
|
30
30
|
|
31
31
|
def get_id(data)
|
32
32
|
result = get_full_data(data)
|
33
|
-
|
33
|
+
applicationid = nil
|
34
|
+
result.each do |app|
|
35
|
+
applicationid = app['applicationid'].to_i if app['name'] == data[:name]
|
36
|
+
end
|
37
|
+
applicationid
|
34
38
|
end
|
35
39
|
|
36
40
|
end
|
data/lib/zabbixapi/graphs.rb
CHANGED
@@ -19,7 +19,7 @@ class ZabbixApi
|
|
19
19
|
result = @client.api_request(:method => "graph.delete", :params => [data])
|
20
20
|
case @client.api_version
|
21
21
|
when "1.3"
|
22
|
-
result ? 1 :
|
22
|
+
result ? 1 : nil #return "true" or "false" for this api version
|
23
23
|
else
|
24
24
|
result.empty? ? nil : result['graphids'][0].to_i
|
25
25
|
end
|
@@ -33,14 +33,32 @@ class ZabbixApi
|
|
33
33
|
@client.api_request(:method => "graph.get", :params => {:search => {:name => data}, :output => "extend"})
|
34
34
|
end
|
35
35
|
|
36
|
+
def get_items(data)
|
37
|
+
@client.api_request(:method => "graphitem.get", :params => { :graphids => [data], :output => "extend" } )
|
38
|
+
end
|
39
|
+
|
36
40
|
def get_id(data)
|
37
41
|
result = @client.api_request(:method => "graph.get", :params => {:filter => {:name=> data[:name]}, :output => "extend"})
|
38
|
-
|
42
|
+
graphid = nil
|
43
|
+
result.each do |graph|
|
44
|
+
graphid = graph['graphid'].to_i if graph['name'] == data[:name]
|
45
|
+
end
|
46
|
+
graphid
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_or_update(data)
|
50
|
+
graphid = get_id(:name => data[:name])
|
51
|
+
graphid ? update(data.merge(:graphid => graphid)) : create(data)
|
39
52
|
end
|
40
53
|
|
41
54
|
def update(data)
|
42
|
-
|
43
|
-
|
55
|
+
case @client.api_version
|
56
|
+
when "1.2"
|
57
|
+
return -1
|
58
|
+
else
|
59
|
+
result = @client.api_request(:method => "graph.update", :params => data)
|
60
|
+
result.empty? ? nil : result['graphids'][0].to_i
|
61
|
+
end
|
44
62
|
end
|
45
63
|
|
46
64
|
end
|
data/lib/zabbixapi/hostgroups.rb
CHANGED
@@ -35,7 +35,11 @@ class ZabbixApi
|
|
35
35
|
|
36
36
|
def get_id(data)
|
37
37
|
result = get_full_data(data)
|
38
|
-
|
38
|
+
hostgroupid = nil
|
39
|
+
result.each do |hgroup|
|
40
|
+
hostgroupid = hgroup['groupid'].to_i if hgroup['name'] == data[:name]
|
41
|
+
end
|
42
|
+
hostgroupid
|
39
43
|
end
|
40
44
|
|
41
45
|
end
|
data/lib/zabbixapi/hosts.rb
CHANGED
@@ -71,9 +71,18 @@ class ZabbixApi
|
|
71
71
|
@client.api_request(:method => "host.get", :params => {:filter => data, :output => "extend"})
|
72
72
|
end
|
73
73
|
|
74
|
+
def create_or_update(data)
|
75
|
+
hostid = get_id(:host => data[:host])
|
76
|
+
hostid ? update(data.merge(:hostid => hostid)) : create(data)
|
77
|
+
end
|
78
|
+
|
74
79
|
def get_id(data)
|
75
80
|
result = get_full_data(data)
|
76
|
-
|
81
|
+
hostid = nil
|
82
|
+
result.each do |host|
|
83
|
+
hostid = host['hostid'].to_i if host['host'] == data[:host]
|
84
|
+
end
|
85
|
+
hostid
|
77
86
|
end
|
78
87
|
|
79
88
|
end
|
data/lib/zabbixapi/items.rb
CHANGED
@@ -60,7 +60,16 @@ class ZabbixApi
|
|
60
60
|
|
61
61
|
def get_id(data)
|
62
62
|
result = get_full_data(data)
|
63
|
-
|
63
|
+
itemid = nil
|
64
|
+
result.each do |item|
|
65
|
+
itemid = item['itemid'].to_i if item['name'] == data[:name]
|
66
|
+
end
|
67
|
+
itemid
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_or_update(data)
|
71
|
+
itemid = get_id(:description => data[:description])
|
72
|
+
itemid ? update(data.merge(:itemid => itemid)) : create(data)
|
64
73
|
end
|
65
74
|
|
66
75
|
def update(data)
|
data/lib/zabbixapi/templates.rb
CHANGED
@@ -32,7 +32,7 @@ class ZabbixApi
|
|
32
32
|
result
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def mass_add(data)
|
36
36
|
result = @client.api_request(
|
37
37
|
:method => "template.massAdd",
|
38
38
|
:params => {
|
@@ -43,6 +43,17 @@ class ZabbixApi
|
|
43
43
|
result.empty? ? false : true
|
44
44
|
end
|
45
45
|
|
46
|
+
def mass_remove(data)
|
47
|
+
result = @client.api_request(
|
48
|
+
:method => "template.massRemove",
|
49
|
+
:params => {
|
50
|
+
:hosts => data[:hosts_id].map { |t| {:hostid => t} },
|
51
|
+
:templates => data[:templates_id].map { |t| {:templateid => t} }
|
52
|
+
}
|
53
|
+
)
|
54
|
+
result.empty? ? false : true
|
55
|
+
end
|
56
|
+
|
46
57
|
def all
|
47
58
|
result = {}
|
48
59
|
case @client.api_version
|
@@ -71,7 +82,11 @@ class ZabbixApi
|
|
71
82
|
|
72
83
|
def get_id(data)
|
73
84
|
result = get_full_data(data)
|
74
|
-
|
85
|
+
templateid = nil
|
86
|
+
result.each do |template|
|
87
|
+
templateid = template['templateid'].to_i if template['host'] == data[:host]
|
88
|
+
end
|
89
|
+
templateid
|
75
90
|
end
|
76
91
|
|
77
92
|
end
|
data/lib/zabbixapi/triggers.rb
CHANGED
@@ -29,13 +29,22 @@ class ZabbixApi
|
|
29
29
|
result.empty? ? nil : result['triggerid'][0].to_i
|
30
30
|
end
|
31
31
|
|
32
|
+
def create_or_update(data)
|
33
|
+
triggerid = get_id(:description => data[:description])
|
34
|
+
triggerid ? update(data.merge(:triggerid => triggerid)) : create(data)
|
35
|
+
end
|
36
|
+
|
32
37
|
def get_full_data(data)
|
33
38
|
@client.api_request(:method => "trigger.get", :params => {:filter => data, :output => "extend"})
|
34
39
|
end
|
35
40
|
|
36
41
|
def get_id(data)
|
37
42
|
result = get_full_data(data)
|
38
|
-
|
43
|
+
triggerid = nil
|
44
|
+
result.each do |template|
|
45
|
+
triggerid = template['triggerid'].to_i if template['name'] == data[:name]
|
46
|
+
end
|
47
|
+
triggerid
|
39
48
|
end
|
40
49
|
|
41
50
|
end
|
data/lib/zabbixapi/users.rb
CHANGED
@@ -38,16 +38,11 @@ class ZabbixApi
|
|
38
38
|
|
39
39
|
def get_id(data)
|
40
40
|
result = get_full_data(data)
|
41
|
-
userid =
|
42
|
-
|
43
|
-
|
44
|
-
result.each do |usr|
|
45
|
-
userid = usr['userid'] if usr['name'] == data[:name]
|
46
|
-
end
|
47
|
-
userid
|
48
|
-
else
|
49
|
-
result.empty? ? nil : result[0]['userid']
|
41
|
+
userid = nil
|
42
|
+
result.each do |usr|
|
43
|
+
userid = usr['userid'].to_i if usr['name'] == data[:name]
|
50
44
|
end
|
45
|
+
userid
|
51
46
|
end
|
52
47
|
|
53
48
|
def update(data)
|
data/lib/zabbixapi/version.rb
CHANGED
data/spec/localhost.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'zabbixapi'
|
2
2
|
|
3
3
|
# settings
|
4
|
-
api_url = 'http://
|
4
|
+
#api_url = 'http://zabbix/zabbix12/api_jsonrpc.php'
|
5
|
+
api_url = 'http://zabbix/zabbix13/api_jsonrpc.php'
|
6
|
+
#api_url = 'http://zabbix/zabbix20/api_jsonrpc.php'
|
7
|
+
|
5
8
|
api_login = 'Admin'
|
6
9
|
api_password = 'zabbix'
|
7
10
|
|
@@ -22,6 +25,8 @@ user = "user____1"
|
|
22
25
|
user2 = "user____2"
|
23
26
|
graph = "graph___a"
|
24
27
|
|
28
|
+
puts "### Zabbix API server version #{zbx.server.version} ###"
|
29
|
+
|
25
30
|
describe ZabbixApi, "test_api" do
|
26
31
|
|
27
32
|
it "SERVER: Get version api" do
|
@@ -84,7 +89,7 @@ describe ZabbixApi, "test_api" do
|
|
84
89
|
:key_ => "proc.num[aaa]",
|
85
90
|
:hostid => zbx.templates.get_id(:host => template),
|
86
91
|
:applications => [zbx.applications.get_id(:name => application)]
|
87
|
-
)
|
92
|
+
).should be_kind_of(Integer)
|
88
93
|
end
|
89
94
|
|
90
95
|
it "ITEM: Full info check" do
|
@@ -102,6 +107,16 @@ describe ZabbixApi, "test_api" do
|
|
102
107
|
).should be_kind_of(Integer)
|
103
108
|
end
|
104
109
|
|
110
|
+
it "ITEM: Create or update" do
|
111
|
+
zbx.items.create_or_update(
|
112
|
+
:description => item,
|
113
|
+
:key_ => "proc.num[aaa]",
|
114
|
+
:type => 6,
|
115
|
+
:hostid => zbx.templates.get_id(:host => template),
|
116
|
+
:applications => [zbx.applications.get_id(:name => application)]
|
117
|
+
).should be_kind_of(Integer)
|
118
|
+
end
|
119
|
+
|
105
120
|
it "ITEM: Get unknown" do
|
106
121
|
zbx.items.get_id(:description => "#{item}_____")
|
107
122
|
end
|
@@ -114,6 +129,14 @@ describe ZabbixApi, "test_api" do
|
|
114
129
|
).should be_kind_of(Integer)
|
115
130
|
end
|
116
131
|
|
132
|
+
it "HOST: Update or create" do
|
133
|
+
zbx.hosts.create_or_update(
|
134
|
+
:host => host,
|
135
|
+
:ip => "10.20.48.89",
|
136
|
+
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
137
|
+
).should be_kind_of(Integer)
|
138
|
+
end
|
139
|
+
|
117
140
|
it "HOST: Find unknown" do
|
118
141
|
zbx.hosts.get_id(:host => "#{host}___").should be_kind_of(NilClass)
|
119
142
|
end
|
@@ -135,15 +158,18 @@ describe ZabbixApi, "test_api" do
|
|
135
158
|
).should be_kind_of(Array)
|
136
159
|
end
|
137
160
|
|
138
|
-
it "
|
139
|
-
zbx.
|
161
|
+
it "TEMPLATE: Linked hosts with templates" do
|
162
|
+
zbx.templates.mass_add(
|
140
163
|
:hosts_id => [zbx.hosts.get_id(:host => host)],
|
141
164
|
:templates_id => [zbx.templates.get_id(:host => template)]
|
142
165
|
).should be_kind_of(TrueClass)
|
143
166
|
end
|
144
167
|
|
145
|
-
it "TEMPLATE: Unlink
|
146
|
-
|
168
|
+
it "TEMPLATE: Unlink hosts from templates" do
|
169
|
+
zbx.templates.mass_remove(
|
170
|
+
:hosts_id => [zbx.hosts.get_id(:host => host)],
|
171
|
+
:templates_id => [zbx.templates.get_id(:host => template)]
|
172
|
+
).should be_kind_of(TrueClass)
|
147
173
|
end
|
148
174
|
|
149
175
|
it "TEMPLATE: Get all" do
|
@@ -180,7 +206,10 @@ describe ZabbixApi, "test_api" do
|
|
180
206
|
:width => "900",
|
181
207
|
:height => "200"
|
182
208
|
).should be_kind_of(Integer)
|
183
|
-
|
209
|
+
end
|
210
|
+
|
211
|
+
it "GRAPH: Find ugititems" do
|
212
|
+
zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
|
184
213
|
end
|
185
214
|
|
186
215
|
it "GRAPH: Find" do
|
@@ -197,6 +226,22 @@ describe ZabbixApi, "test_api" do
|
|
197
226
|
).should be_kind_of(Integer)
|
198
227
|
end
|
199
228
|
|
229
|
+
it "GRAPH: Create or Update" do
|
230
|
+
gitems = {
|
231
|
+
:itemid => zbx.items.get_id(:description => item),
|
232
|
+
:calc_fnc => "3",
|
233
|
+
:type => "0",
|
234
|
+
:periods_cnt => "5"
|
235
|
+
}
|
236
|
+
zbx.graphs.create_or_update(
|
237
|
+
:gitems => [gitems],
|
238
|
+
:show_triggers => "1",
|
239
|
+
:name => graph,
|
240
|
+
:width => "900",
|
241
|
+
:height => "200"
|
242
|
+
).should be_kind_of(Integer)
|
243
|
+
end
|
244
|
+
|
200
245
|
it "GRAPH: Delete" do
|
201
246
|
zbx.graphs.delete(zbx.graphs.get_id(:name => graph)).should be_kind_of(Integer)
|
202
247
|
end
|
data/spec/run.rb
CHANGED
@@ -22,8 +22,9 @@ user = "user"
|
|
22
22
|
user2 = "user2"
|
23
23
|
graph = "graph"
|
24
24
|
|
25
|
-
|
25
|
+
puts "### Zabbix API server version #{zbx.server.version} ###"
|
26
26
|
|
27
|
+
describe ZabbixApi, "test_api" do
|
27
28
|
|
28
29
|
it "SERVER: Get version api" do
|
29
30
|
zbx.server.version.should be_kind_of(String)
|
@@ -85,7 +86,7 @@ describe ZabbixApi, "test_api" do
|
|
85
86
|
:key_ => "proc.num[aaa]",
|
86
87
|
:hostid => zbx.templates.get_id(:host => template),
|
87
88
|
:applications => [zbx.applications.get_id(:name => application)]
|
88
|
-
)
|
89
|
+
).should be_kind_of(Integer)
|
89
90
|
end
|
90
91
|
|
91
92
|
it "ITEM: Full info check" do
|
@@ -103,6 +104,16 @@ describe ZabbixApi, "test_api" do
|
|
103
104
|
).should be_kind_of(Integer)
|
104
105
|
end
|
105
106
|
|
107
|
+
it "ITEM: Create or update" do
|
108
|
+
zbx.items.create_or_update(
|
109
|
+
:description => item,
|
110
|
+
:key_ => "proc.num[aaa]",
|
111
|
+
:type => 6,
|
112
|
+
:hostid => zbx.templates.get_id(:host => template),
|
113
|
+
:applications => [zbx.applications.get_id(:name => application)]
|
114
|
+
).should be_kind_of(Integer)
|
115
|
+
end
|
116
|
+
|
106
117
|
it "ITEM: Get unknown" do
|
107
118
|
zbx.items.get_id(:description => "#{item}_____")
|
108
119
|
end
|
@@ -115,6 +126,14 @@ describe ZabbixApi, "test_api" do
|
|
115
126
|
).should be_kind_of(Integer)
|
116
127
|
end
|
117
128
|
|
129
|
+
it "HOST: Update or create" do
|
130
|
+
zbx.hosts.create_or_update(
|
131
|
+
:host => host,
|
132
|
+
:ip => "10.20.48.89",
|
133
|
+
:groups => [:groupid => zbx.hostgroups.get_id(:name => hostgroup)]
|
134
|
+
).should be_kind_of(Integer)
|
135
|
+
end
|
136
|
+
|
118
137
|
it "HOST: Find unknown" do
|
119
138
|
zbx.hosts.get_id(:host => "#{host}___").should be_kind_of(NilClass)
|
120
139
|
end
|
@@ -136,15 +155,18 @@ describe ZabbixApi, "test_api" do
|
|
136
155
|
).should be_kind_of(Array)
|
137
156
|
end
|
138
157
|
|
139
|
-
it "
|
140
|
-
zbx.
|
158
|
+
it "TEMPLATE: Linked hosts with templates" do
|
159
|
+
zbx.templates.mass_add(
|
141
160
|
:hosts_id => [zbx.hosts.get_id(:host => host)],
|
142
161
|
:templates_id => [zbx.templates.get_id(:host => template)]
|
143
162
|
).should be_kind_of(TrueClass)
|
144
163
|
end
|
145
164
|
|
146
|
-
it "TEMPLATE: Unlink
|
147
|
-
|
165
|
+
it "TEMPLATE: Unlink hosts from templates" do
|
166
|
+
zbx.templates.mass_remove(
|
167
|
+
:hosts_id => [zbx.hosts.get_id(:host => host)],
|
168
|
+
:templates_id => [zbx.templates.get_id(:host => template)]
|
169
|
+
).should be_kind_of(TrueClass)
|
148
170
|
end
|
149
171
|
|
150
172
|
it "TEMPLATE: Get all" do
|
@@ -181,7 +203,10 @@ describe ZabbixApi, "test_api" do
|
|
181
203
|
:width => "900",
|
182
204
|
:height => "200"
|
183
205
|
).should be_kind_of(Integer)
|
184
|
-
|
206
|
+
end
|
207
|
+
|
208
|
+
it "GRAPH: Find ugititems" do
|
209
|
+
zbx.graphs.get_items( zbx.graphs.get_id(:name => graph) )
|
185
210
|
end
|
186
211
|
|
187
212
|
it "GRAPH: Find" do
|
@@ -198,6 +223,22 @@ describe ZabbixApi, "test_api" do
|
|
198
223
|
).should be_kind_of(Integer)
|
199
224
|
end
|
200
225
|
|
226
|
+
it "GRAPH: Create or Update" do
|
227
|
+
gitems = {
|
228
|
+
:itemid => zbx.items.get_id(:description => item),
|
229
|
+
:calc_fnc => "3",
|
230
|
+
:type => "0",
|
231
|
+
:periods_cnt => "5"
|
232
|
+
}
|
233
|
+
zbx.graphs.create_or_update(
|
234
|
+
:gitems => [gitems],
|
235
|
+
:show_triggers => "1",
|
236
|
+
:name => graph,
|
237
|
+
:width => "900",
|
238
|
+
:height => "200"
|
239
|
+
).should be_kind_of(Integer)
|
240
|
+
end
|
241
|
+
|
201
242
|
it "GRAPH: Delete" do
|
202
243
|
zbx.graphs.delete(zbx.graphs.get_id(:name => graph)).should be_kind_of(Integer)
|
203
244
|
end
|
@@ -257,9 +298,9 @@ describe ZabbixApi, "test_api" do
|
|
257
298
|
|
258
299
|
it "QUERY" do
|
259
300
|
zbx.query(
|
260
|
-
|
261
|
-
|
301
|
+
:method => "apiinfo.version",
|
302
|
+
:params => {}
|
262
303
|
).should be_kind_of(String)
|
263
304
|
end
|
264
305
|
|
265
|
-
end
|
306
|
+
end
|
data/zabbixapi.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "https://github.com/vadv/zabbixapi"
|
11
11
|
s.summary = %q{Realization for Zabbix API.}
|
12
12
|
s.description = %q{Allows you to work with zabbix api from ruby.}
|
13
|
+
s.licenses = ["MIT"]
|
13
14
|
|
14
15
|
s.rubyforge_project = "zabbixapi"
|
15
16
|
|
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: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-20 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Allows you to work with zabbix api from ruby.
|
16
16
|
email:
|
@@ -19,6 +19,8 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- .gitignore
|
23
|
+
- .rspec
|
22
24
|
- .travis.yml
|
23
25
|
- Gemfile
|
24
26
|
- Gemfile.lock
|
@@ -41,7 +43,8 @@ files:
|
|
41
43
|
- spec/run.rb
|
42
44
|
- zabbixapi.gemspec
|
43
45
|
homepage: https://github.com/vadv/zabbixapi
|
44
|
-
licenses:
|
46
|
+
licenses:
|
47
|
+
- MIT
|
45
48
|
post_install_message:
|
46
49
|
rdoc_options: []
|
47
50
|
require_paths:
|
@@ -54,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
57
|
version: '0'
|
55
58
|
segments:
|
56
59
|
- 0
|
57
|
-
hash:
|
60
|
+
hash: 4393999547783440369
|
58
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
62
|
none: false
|
60
63
|
requirements:
|
@@ -67,6 +70,4 @@ rubygems_version: 1.8.24
|
|
67
70
|
signing_key:
|
68
71
|
specification_version: 3
|
69
72
|
summary: Realization for Zabbix API.
|
70
|
-
test_files:
|
71
|
-
- spec/localhost.rb
|
72
|
-
- spec/run.rb
|
73
|
+
test_files: []
|