zapix 0.0.9 → 0.1.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.
@@ -2,24 +2,24 @@ require_relative 'basic'
2
2
 
3
3
  class Applications < Basic
4
4
 
5
- def create(options)
6
- @client.application_create(options) unless exists?(options)
7
- end
5
+ def create(options)
6
+ @client.application_create(options) unless exists?(options)
7
+ end
8
8
 
9
- def exists?(options)
10
- @client.application_exists(options)
11
- end
9
+ def exists?(options)
10
+ @client.application_exists(options)
11
+ end
12
12
 
13
- def get_id(options)
14
- if exists?(options)
15
- @client.application_get({
16
- 'filter' => {'name' => options['name'],
17
- 'hostid' => options['hostid']}}).first['applicationid']
18
- else
19
- raise NonExistingApplication, "Application #{options['name']} does not exist !"
13
+ def get_id(options)
14
+ if exists?(options)
15
+ @client.application_get({
16
+ 'filter' => {'name' => options['name'],
17
+ 'hostid' => options['hostid']}}).first['applicationid']
18
+ else
19
+ raise NonExistingApplication, "Application #{options['name']} does not exist !"
20
+ end
20
21
  end
21
- end
22
22
 
23
- class NonExistingApplication < StandardError; end
23
+ class NonExistingApplication < StandardError; end
24
24
 
25
25
  end
@@ -2,97 +2,95 @@ require_relative 'basic'
2
2
 
3
3
  class HostGroups < Basic
4
4
 
5
- def mass_create(*names)
6
- names.each do |group_name|
7
- create(group_name)
5
+ def mass_create(*names)
6
+ names.each do |group_name|
7
+ create(group_name)
8
+ end
8
9
  end
9
- end
10
10
 
11
- def create(name)
12
- @client.hostgroup_create({'name' => name}) unless exists?(name)
13
- end
11
+ def create(name)
12
+ @client.hostgroup_create({'name' => name}) unless exists?(name)
13
+ end
14
14
 
15
- def create_or_update(name)
16
- if(exists?(name))
17
- id = get_id(name)
18
- @client.hostgroup_update({'groupid' => id,'name' => name})
19
- else
20
- create(name)
15
+ def create_or_update(name)
16
+ if(exists?(name))
17
+ id = get_id(name)
18
+ @client.hostgroup_update({'groupid' => id,'name' => name})
19
+ else
20
+ create(name)
21
+ end
21
22
  end
22
- end
23
23
 
24
- def exists?(name)
25
- @client.hostgroup_exists({'name' => name})
26
- end
24
+ def exists?(name)
25
+ @client.hostgroup_exists({'name' => name})
26
+ end
27
27
 
28
- def get_id(name)
29
- if(exists?(name))
30
- result = @client.hostgroup_get({'filter' => {'name' => [name]}})
31
- result[0]['groupid']
32
- else
33
- raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
28
+ def get_id(name)
29
+ if(exists?(name))
30
+ result = @client.hostgroup_get({'filter' => {'name' => [name]}})
31
+ result[0]['groupid']
32
+ else
33
+ raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
34
+ end
34
35
  end
35
- end
36
36
 
37
- def mass_delete(*names)
38
- names.each do |group_name|
39
- delete(group_name)
37
+ def mass_delete(*names)
38
+ names.each do |group_name|
39
+ delete(group_name)
40
+ end
40
41
  end
41
- end
42
42
 
43
- def get_host_ids_of(hostgroup)
44
- result = @client.hostgroup_get('filter' => {'name' => [hostgroup]}, 'selectHosts' => 'refer')
45
- extract_host_ids(result)
46
- end
43
+ def get_host_ids_of(hostgroup)
44
+ result = @client.hostgroup_get('filter' => {'name' => [hostgroup]}, 'selectHosts' => 'refer')
45
+ extract_host_ids(result)
46
+ end
47
47
 
48
- def any_hosts?(hostgroup)
49
- raise NonExistingHostgroup, "Hostgroup #{hostgroup} does not exist !" unless exists?(hostgroup)
50
- result = @client.hostgroup_get('filter' => {'name' => [hostgroup]}, 'selectHosts' => 'count').first['hosts'].to_i
51
- if(result >= 1)
52
- true
53
- else
54
- false
48
+ def any_hosts?(hostgroup)
49
+ raise NonExistingHostgroup, "Hostgroup #{hostgroup} does not exist !" unless exists?(hostgroup)
50
+ result = @client.hostgroup_get('filter' => {'name' => [hostgroup]}, 'selectHosts' => 'count').first['hosts'].to_i
51
+ if(result >= 1)
52
+ true
53
+ else
54
+ false
55
+ end
55
56
  end
56
- end
57
57
 
58
- def delete(name)
59
- if(exists?(name))
60
- # host cannot exist without a hostgroup, so we need to delete
61
- # the attached hosts also
62
- if(any_hosts?(name))
63
- # delete all hosts attached to a hostgroup
64
- host_ids = get_host_ids_of(name)
65
- host_ids.each do |id|
66
- @client.host_delete(['hostid' => id])
58
+ def delete(name)
59
+ if(exists?(name))
60
+ # host cannot exist without a hostgroup, so we need to delete
61
+ # the attached hosts also
62
+ if(any_hosts?(name))
63
+ # delete all hosts attached to a hostgroup
64
+ host_ids = get_host_ids_of(name)
65
+ host_ids.each do |id|
66
+ @client.host_delete(['hostid' => id])
67
+ end
68
+ # now it is ok to delete the group
69
+ @client.hostgroup_delete([get_id(name)])
70
+ else
71
+ @client.hostgroup_delete([get_id(name)])
67
72
  end
68
- # now it is ok to delete the group
69
- @client.hostgroup_delete([get_id(name)])
70
73
  else
71
- @client.hostgroup_delete([get_id(name)])
74
+ raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
72
75
  end
73
-
74
- else
75
- raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
76
76
  end
77
- end
78
77
 
79
- def get_all
80
- # the fucking API also returns the ids and that's
81
- # why we need to extract the names
82
- host_groups_with_ids = @client.hostgroup_get({'output' => ['name']})
83
- extract_host_groups(host_groups_with_ids)
84
- end
85
-
86
- def extract_host_ids(query_result)
87
- query_result.first['hosts'].map { |host| host['hostid'] }
88
- end
78
+ def get_all
79
+ # the fucking API also returns the ids and that's
80
+ # why we need to extract the names
81
+ host_groups_with_ids = @client.hostgroup_get({'output' => ['name']})
82
+ extract_host_groups(host_groups_with_ids)
83
+ end
89
84
 
90
- def extract_host_groups(group_names_and_ids)
91
- group_names_and_ids.map do |hostgroup|
92
- hostgroup['name']
85
+ def extract_host_ids(query_result)
86
+ query_result.first['hosts'].map { |host| host['hostid'] }
93
87
  end
94
- end
95
88
 
96
- class NonExistingHostgroup < StandardError; end
89
+ def extract_host_groups(group_names_and_ids)
90
+ group_names_and_ids.map do |hostgroup|
91
+ hostgroup['name']
92
+ end
93
+ end
97
94
 
95
+ class NonExistingHostgroup < StandardError; end
98
96
  end
@@ -0,0 +1,25 @@
1
+ require_relative 'basic'
2
+
3
+ class Hostinterfaces < Basic
4
+
5
+ def create(options)
6
+ @client.hostinterface_create(options) unless exists?(options)
7
+ end
8
+
9
+ def exists?(options)
10
+ if get(options).empty?
11
+ false
12
+ else
13
+ true
14
+ end
15
+ end
16
+
17
+ def get(options)
18
+ @client.hostinterface_get(
19
+ {'filter' => {'hostid' => options['hostid'],
20
+ 'port' => options['port'],
21
+ 'type' => options['type']},
22
+ 'output' => 'extend'})
23
+ end
24
+
25
+ end
@@ -59,15 +59,14 @@ class Hosts < Basic
59
59
  end
60
60
  end
61
61
 
62
- private
62
+ class NonExistingHost < StandardError; end
63
+ class EmptyHostname < StandardError; end
64
+
65
+ private
63
66
 
64
67
  def extract_host_names(hosts_and_ids)
65
68
  hosts_and_ids.map do |current_host|
66
69
  current_host['name']
67
70
  end
68
71
  end
69
-
70
- class NonExistingHost < StandardError; end
71
- class EmptyHostname < StandardError; end
72
-
73
72
  end
@@ -1,28 +1,22 @@
1
1
  require_relative 'basic'
2
2
  class Templates < Basic
3
3
 
4
- def exists?(name)
5
- @client.template_exists({'name' => name})
6
- end
7
-
8
- def create(name)
9
- end
10
-
11
- def delete(name)
12
- end
4
+ def exists?(name)
5
+ @client.template_exists({'name' => name})
6
+ end
13
7
 
14
- def get_id(name)
15
- if(exists?(name))
16
- @client.template_get({'filter' => {'name' => name}}).first['templateid']
17
- else
18
- raise NonExistingTemplate, "Template #{name} does not exist !"
8
+ def get_id(name)
9
+ if(exists?(name))
10
+ @client.template_get({'filter' => {'name' => name}}).first['templateid']
11
+ else
12
+ raise NonExistingTemplate, "Template #{name} does not exist !"
13
+ end
19
14
  end
20
- end
21
15
 
22
- def get_templates_for_host(id)
23
- @client.template_get({'hostids' => [id]}).map { |result_set| result_set['templateid'] }
24
- end
16
+ def get_templates_for_host(id)
17
+ @client.template_get({'hostids' => [id]}).map { |result_set| result_set['templateid'] }
18
+ end
25
19
 
26
- class NonExistingTemplate < StandardError; end
20
+ class NonExistingTemplate < StandardError; end
27
21
 
28
22
  end
@@ -0,0 +1,44 @@
1
+ require_relative 'basic'
2
+ class Triggers < Basic
3
+
4
+ def exists?(options)
5
+ @client.trigger_exists(options)
6
+ end
7
+
8
+ def create(options)
9
+ @client.trigger_create(options) unless exists?(options)
10
+ end
11
+
12
+ def delete(*trigger_ids)
13
+ @client.trigger_delete(trigger_ids)
14
+ end
15
+
16
+ def get_id(options)
17
+ result = @client.trigger_get({'output' => 'extend',
18
+ 'expandExpression' => true})
19
+ id = extract_id(result, options['expression'])
20
+ unless id.nil?
21
+ id
22
+ else
23
+ raise NonExistingTrigger, "Trigger with expression #{options['expression']} not found."
24
+ end
25
+ end
26
+
27
+ class NonExistingTrigger < StandardError; end
28
+
29
+ private
30
+
31
+ def extract_id(triggers, expression)
32
+ result = nil
33
+ triggers.each do |trigger|
34
+ if trigger['expression'] == expression
35
+ result = trigger['triggerid']
36
+ break
37
+ end
38
+ end
39
+ result
40
+ end
41
+
42
+ end
43
+
44
+
data/lib/zapix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zapix
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/zapix.rb CHANGED
@@ -34,4 +34,12 @@ class ZabbixAPI
34
34
  @scenarios ||= Scenarios.new(@client)
35
35
  end
36
36
 
37
+ def triggers
38
+ @triggers ||= Triggers.new(@client)
39
+ end
40
+
41
+ def hostinterfaces
42
+ @hostinterfaces ||= Hostinterfaces.new(@client)
43
+ end
44
+
37
45
  end
data/spec/zapix_specs.rb CHANGED
@@ -15,6 +15,9 @@ template_2 = 'Template App MySQL'
15
15
  application = 'web scenarios'
16
16
  host = 'hostname'
17
17
  scenario = 'scenario'
18
+ trigger_description = 'Webpage failed on {HOST.NAME}'
19
+ trigger_expression = "{#{host}:web.test.fail[#{scenario}].max(#3)}#0"
20
+ non_existing_trigger_expression = '{vfs.file.cksum[/etc/passwd].diff(0)}>0'
18
21
 
19
22
  describe ZabbixAPI do
20
23
 
@@ -73,7 +76,7 @@ describe ZabbixAPI do
73
76
  hostgroup_id = zrc.hostgroups.get_id(hostgroup_with_hosts)
74
77
  example_host = Host.new
75
78
  example_host.add_name(host)
76
- example_host.add_interfaces(create_interface)
79
+ example_host.add_interfaces(create_interface.to_hash)
77
80
  example_host.add_group_ids(hostgroup_id)
78
81
  example_host.add_template_ids(zrc.templates.get_id(template_1), zrc.templates.get_id(template_2))
79
82
  example_host.add_macros({'macro' => '{$TESTMACRO}', 'value' => 'test123'})
@@ -94,7 +97,7 @@ describe ZabbixAPI do
94
97
  hostgroup_id = zrc.hostgroups.get_id(hostgroup_with_hosts)
95
98
  example_host = Host.new
96
99
  example_host.add_name(host)
97
- example_host.add_interfaces(create_interface)
100
+ example_host.add_interfaces(create_interface.to_hash)
98
101
  example_host.add_macros({'macro' => '{$TESTMACRO}', 'value' => 'test123'})
99
102
  example_host.add_group_ids(hostgroup_id)
100
103
  example_host.add_template_ids(zrc.templates.get_id(template_1), zrc.templates.get_id(template_2))
@@ -113,146 +116,230 @@ describe ZabbixAPI do
113
116
  webcheck_options['applicationid'] = zrc.applications.get_id(application_options)
114
117
  webcheck_options['steps'] = [{'name' => 'Homepage', 'url' => 'm.test.de', 'status_codes' => 200, 'no' => 1}]
115
118
  zrc.scenarios.create(webcheck_options)
116
- end
117
-
118
- after(:each) do
119
- zrc.hostgroups.delete(hostgroup_with_hosts)
120
- end
121
-
122
- it 'returns true if a hostgroup has attached hosts' do
123
- zrc.hostgroups.any_hosts?(hostgroup_with_hosts).should be_true
124
- end
125
-
126
- it 'returns all the host ids of a hosts belonging to a hostgroup' do
127
- host_id = zrc.hosts.get_id(host)
128
- zrc.hostgroups.get_host_ids_of(hostgroup_with_hosts).should include(host_id)
129
- end
130
-
131
- it 'gets the right template id for host' do
132
- result = zrc.templates.get_templates_for_host(zrc.hosts.get_id(host))
133
- result.should include(zrc.templates.get_id(template_1))
134
- result.should include(zrc.templates.get_id(template_2))
135
- end
136
-
137
- it 'unlinks all templates for host' do
138
- host_id = zrc.hosts.get_id(host)
139
- options = {}
140
- options['template_ids'] = zrc.templates.get_templates_for_host(host_id)
141
- options['host_id'] = host_id
142
- result = zrc.hosts.unlink_and_clear_templates(options)
143
- result.should_not include(zrc.templates.get_id(template_1))
144
- result.should_not include(zrc.templates.get_id(template_2))
145
- end
146
-
147
- it 'throws an exception if updating a host without specifying the hostname' do
148
- example_host = Host.new
149
- example_host.add_interfaces(create_interface)
150
- expect { zrc.hosts.create_or_update(example_host.to_hash) }.to raise_error(Hosts::EmptyHostname)
151
- end
152
-
153
- it "updates host's interface after unlinking all belonging templates" do
154
- # unlinking all items
155
- host_id = zrc.hosts.get_id(host)
156
- options = {}
157
- zrc.templates.get_templates_for_host(host_id)
158
- options['template_ids'] = zrc.templates.get_templates_for_host(host_id)
159
- options['host_id'] = host_id
160
- result = zrc.hosts.unlink_and_clear_templates(options)
161
- #result = zrc.hosts.update_templates(options)
162
- # now it should be safe to update the interface of the host
163
- example_host = Host.new
164
- example_host.add_interfaces(create_interface)
165
- example_host.add_name(host)
166
- zrc.hosts.create_or_update(example_host.to_hash)
167
- # check
168
- end
169
-
170
- it "updates host's templates" do
171
- host_id = zrc.hosts.get_id(host)
172
- options = {}
173
- options['host_id'] = host_id
174
- template_id = zrc.templates.get_id('Template App Agentless')
175
- options['template_ids'] = [template_id]
176
- zrc.hosts.update_templates(options)
177
- zrc.templates.get_templates_for_host(host_id).should include(template_id)
178
- end
179
-
180
- it "updates host's macro" do
181
- host_id = zrc.hosts.get_id(host)
182
- options = {}
183
- options['host_id'] = host_id
184
- options['macros'] = [{'macro' => '{$TESTMACRO}', 'value' => 'this is only a test macro'}]
185
- zrc.hosts.update_macros(options)
186
- end
187
-
188
- it 'returns false if an application does not exist' do
189
- options = {}
190
- options['name'] = 'nonexisting'
191
- options['hostid'] = zrc.hosts.get_id(host)
192
- zrc.applications.exists?(options).should be_false
193
- end
194
119
 
195
- it 'returns true if an application exists' do
120
+ # creates a trigger
196
121
  options = {}
197
- options['name'] = application
198
- options['hostid'] = zrc.hosts.get_id(host)
199
- zrc.applications.exists?(options).should be_true
122
+ options['description'] = trigger_description
123
+ options['expression'] = trigger_expression
124
+ options['priority'] = '2' # 2 means Warning
125
+ zrc.triggers.create(options)
126
+
200
127
  end
201
128
 
202
- it 'get an application id by application name and host' do
203
- options = {}
204
- options['name'] = application
205
- options['hostid'] = zrc.hosts.get_id(host)
206
- result = zrc.applications.get_id(options)
207
- (result.to_i).should >= 0
208
- end
209
-
210
- it 'throws exception on non existing application' do
211
- options = {}
212
- options['name'] = "nonexisting"
213
- options['hostid'] = zrc.hosts.get_id(host)
214
- expect { zrc.applications.get_id(options) }.to raise_error(Applications::NonExistingApplication)
129
+ after(:each) do
130
+ zrc.hostgroups.delete(hostgroup_with_hosts)
215
131
  end
216
132
 
217
- it 'deletes an applications for host' do
218
- pending 'Not implemented'
133
+ describe 'hosts' do
134
+
135
+ it 'returns true if a hostgroup has attached hosts' do
136
+ zrc.hostgroups.any_hosts?(hostgroup_with_hosts).should be_true
137
+ end
138
+
139
+ it 'returns all the host ids of a hosts belonging to a hostgroup' do
140
+ host_id = zrc.hosts.get_id(host)
141
+ zrc.hostgroups.get_host_ids_of(hostgroup_with_hosts).should include(host_id)
142
+ end
143
+
144
+ it 'gets the right template id for host' do
145
+ result = zrc.templates.get_templates_for_host(zrc.hosts.get_id(host))
146
+ result.should include(zrc.templates.get_id(template_1))
147
+ result.should include(zrc.templates.get_id(template_2))
148
+ end
149
+
150
+ it 'unlinks all templates for host' do
151
+ host_id = zrc.hosts.get_id(host)
152
+ options = {}
153
+ options['template_ids'] = zrc.templates.get_templates_for_host(host_id)
154
+ options['host_id'] = host_id
155
+ result = zrc.hosts.unlink_and_clear_templates(options)
156
+ result.should_not include(zrc.templates.get_id(template_1))
157
+ result.should_not include(zrc.templates.get_id(template_2))
158
+ end
159
+
160
+ it 'throws an exception if updating a host without specifying the hostname' do
161
+ example_host = Host.new
162
+ example_host.add_interfaces(create_interface.to_hash)
163
+ expect { zrc.hosts.create_or_update(example_host.to_hash) }.to raise_error(Hosts::EmptyHostname)
164
+ end
165
+
166
+ it "updates host's interface after unlinking all belonging templates" do
167
+ # unlinking all items
168
+ host_id = zrc.hosts.get_id(host)
169
+ options = {}
170
+ zrc.templates.get_templates_for_host(host_id)
171
+ options['template_ids'] = zrc.templates.get_templates_for_host(host_id)
172
+ options['host_id'] = host_id
173
+ result = zrc.hosts.unlink_and_clear_templates(options)
174
+ # now it should be safe to update the interface of the host
175
+ example_host = Host.new
176
+ example_host.add_interfaces(create_interface.to_hash)
177
+ example_host.add_name(host)
178
+ zrc.hosts.create_or_update(example_host.to_hash)
179
+ end
180
+
181
+ it "updates host's templates" do
182
+ host_id = zrc.hosts.get_id(host)
183
+ options = {}
184
+ options['host_id'] = host_id
185
+ template_id = zrc.templates.get_id('Template App Agentless')
186
+ options['template_ids'] = [template_id]
187
+ zrc.hosts.update_templates(options)
188
+ zrc.templates.get_templates_for_host(host_id).should include(template_id)
189
+ end
190
+
191
+ it "updates host's macro" do
192
+ host_id = zrc.hosts.get_id(host)
193
+ options = {}
194
+ options['host_id'] = host_id
195
+ options['macros'] = [{'macro' => '{$TESTMACRO}', 'value' => 'this is only a test macro'}]
196
+ zrc.hosts.update_macros(options)
197
+ end
219
198
  end
220
199
 
221
- it 'returns true if web scenarios exists' do
222
- options = {}
223
- options['name'] = scenario
224
- options['hostid'] = zrc.hosts.get_id(host)
225
- zrc.scenarios.exists?(options).should be_true
200
+ describe 'applications' do
201
+ it 'returns false if an application does not exist' do
202
+ options = {}
203
+ options['name'] = 'nonexisting'
204
+ options['hostid'] = zrc.hosts.get_id(host)
205
+ zrc.applications.exists?(options).should be_false
206
+ end
207
+
208
+ it 'returns true if an application exists' do
209
+ options = {}
210
+ options['name'] = application
211
+ options['hostid'] = zrc.hosts.get_id(host)
212
+ zrc.applications.exists?(options).should be_true
213
+ end
214
+
215
+ it 'get an application id by application name and host' do
216
+ options = {}
217
+ options['name'] = application
218
+ options['hostid'] = zrc.hosts.get_id(host)
219
+ result = zrc.applications.get_id(options)
220
+ (result.to_i).should >= 0
221
+ end
222
+
223
+ it 'throws exception on non existing application' do
224
+ options = {}
225
+ options['name'] = "nonexisting"
226
+ options['hostid'] = zrc.hosts.get_id(host)
227
+ expect { zrc.applications.get_id(options) }.to raise_error(Applications::NonExistingApplication)
228
+ end
226
229
  end
227
230
 
228
- it 'gets the id of a web scenario' do
229
- options = {}
230
- options['name'] = scenario
231
- options['hostid'] = zrc.hosts.get_id(host)
232
- zrc.scenarios.exists?(options).should be_true
233
- zrc.scenarios.get_id(options)
231
+ describe 'web scenarios' do
232
+ it 'returns true if web scenarios exists' do
233
+ options = {}
234
+ options['name'] = scenario
235
+ options['hostid'] = zrc.hosts.get_id(host)
236
+ zrc.scenarios.exists?(options).should be_true
237
+ end
238
+
239
+ it 'gets the id of a web scenario' do
240
+ options = {}
241
+ options['name'] = scenario
242
+ options['hostid'] = zrc.hosts.get_id(host)
243
+ zrc.scenarios.exists?(options).should be_true
244
+ zrc.scenarios.get_id(options)
245
+ end
246
+
247
+ it 'returns false if a web scenario does not exist' do
248
+ options = {}
249
+ options['name'] = "nonexisting"
250
+ options['hostid'] = zrc.hosts.get_id(host)
251
+ zrc.scenarios.exists?(options).should be_false
252
+ end
253
+
254
+ it 'deletes a web scenario' do
255
+ pending 'Not ready'
256
+ options = {}
257
+ options['name'] = scenario
258
+ options['hostid'] = zrc.hosts.get_id(host)
259
+ zrc.scenarios.delete(options)
260
+ zrc.scenarios.exists?(options).should be_false
261
+ end
234
262
  end
235
263
 
236
- it 'returns false if a web scenario does not exist' do
237
- options = {}
238
- options['name'] = "nonexisting"
239
- options['hostid'] = zrc.hosts.get_id(host)
240
- zrc.scenarios.exists?(options).should be_false
264
+ describe 'triggers' do
265
+ it 'deletes a trigger' do
266
+ options = {}
267
+ options['expression'] = trigger_expression
268
+ zrc.triggers.exists?(options).should be_true
269
+ id = zrc.triggers.get_id(options)
270
+ zrc.triggers.delete(id)
271
+ zrc.triggers.exists?(options).should be_false
272
+ end
273
+
274
+ it 'gets an id of a trigger' do
275
+ options = {}
276
+ options['expression'] = trigger_expression
277
+ (zrc.triggers.get_id(options)).to_i.should >= 0
278
+ end
279
+
280
+ it 'throws exception if trying to get id of a non-existing trigger' do
281
+ options = {}
282
+ options['expression'] = non_existing_trigger_expression
283
+ expect { zrc.triggers.get_id(options) }.to raise_error(Triggers::NonExistingTrigger)
284
+ end
285
+
286
+ it 'returns true if a trigger exists' do
287
+ options = {}
288
+ options['expression'] = trigger_expression
289
+ zrc.triggers.exists?(options).should be_true
290
+ end
291
+
292
+ it 'returns false if a trigger does not exist' do
293
+ options = {}
294
+ options['expression'] = non_existing_trigger_expression
295
+ zrc.triggers.exists?(options).should be_false
296
+ end
241
297
  end
242
298
 
243
- it 'deletes a web scenario' do
244
- options = {}
245
- options['name'] = scenario
246
- options['hostid'] = zrc.hosts.get_id(host)
247
- zrc.scenarios.delete(options)
248
- zrc.scenarios.exists?(options).should be_false
299
+ describe 'hostinterfaces' do
300
+ it 'creates jmx interface for host' do
301
+ jmx_iface = create_jmx_interface
302
+ jmx_iface_hash = jmx_iface.to_hash
303
+ jmx_iface_hash['hostid'] = zrc.hosts.get_id(host)
304
+ zrc.hostinterfaces.create(jmx_iface_hash)
305
+ zrc.hostinterfaces.exists?(jmx_iface_hash).should be_true
306
+ end
307
+
308
+ it 'check if interface exists for host' do
309
+ options = {}
310
+ options['hostid'] = zrc.hosts.get_id(host)
311
+ options['port'] = 10050
312
+ options['type'] = 1
313
+ zrc.hostinterfaces.exists?(options).should be_true
314
+
315
+ options['port'] = 9003
316
+ options['type'] = 4
317
+ zrc.hostinterfaces.exists?(options).should be_false
318
+ end
319
+
320
+ it 'gets interface id' do
321
+ pending 'Not implemented'
322
+ end
323
+
324
+ it 'deletes an interface' do
325
+ pending 'Not implemented'
326
+ end
249
327
  end
250
328
  end
251
329
 
252
330
  def create_interface
253
331
  Interface.new(
254
- 'ip' => "127.0.0.#{random_int}",
255
- 'dns' => "#{random_string}.our-cloud.de").to_hash
332
+ 'ip' => random_local_ip,
333
+ 'dns' => random_domain)
334
+ end
335
+
336
+ def create_jmx_interface
337
+ Interface.new(
338
+ 'ip' => random_local_ip,
339
+ 'dns' => random_domain,
340
+ 'type' => 4, # JMX
341
+ 'main' => 1, # not default
342
+ 'port' => 9003)
256
343
  end
257
344
 
258
345
  def random_string
@@ -263,4 +350,12 @@ describe ZabbixAPI do
263
350
  rand(64)
264
351
  end
265
352
 
353
+ def random_local_ip
354
+ "127.0.0.#{random_int}"
355
+ end
356
+
357
+ def random_domain
358
+ "#{random_string}.our-cloud.de"
359
+ end
360
+
266
361
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zapix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-02 00:00:00.000000000 Z
12
+ date: 2013-07-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -108,9 +108,11 @@ files:
108
108
  - lib/zapix/proxies/applications.rb
109
109
  - lib/zapix/proxies/basic.rb
110
110
  - lib/zapix/proxies/hostgroups.rb
111
+ - lib/zapix/proxies/hostinterfaces.rb
111
112
  - lib/zapix/proxies/hosts.rb
112
113
  - lib/zapix/proxies/scenarios.rb
113
114
  - lib/zapix/proxies/templates.rb
115
+ - lib/zapix/proxies/triggers.rb
114
116
  - lib/zapix/version.rb
115
117
  - lib/zapix/zabbix_classes/host.rb
116
118
  - lib/zapix/zabbix_classes/interface.rb
@@ -133,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
135
  version: '0'
134
136
  segments:
135
137
  - 0
136
- hash: 1026072512535608840
138
+ hash: 463225029197809156
137
139
  required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  none: false
139
141
  requirements:
@@ -142,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  version: '0'
143
145
  segments:
144
146
  - 0
145
- hash: 1026072512535608840
147
+ hash: 463225029197809156
146
148
  requirements: []
147
149
  rubyforge_project:
148
150
  rubygems_version: 1.8.24