zapix 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ require_relative 'basic'
2
+
3
+ class Applications < Basic
4
+
5
+ def create(options)
6
+ @client.application_create(options) unless exists?(options)
7
+ end
8
+
9
+ def exists?(options)
10
+ @client.application_exists(options)
11
+ end
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 !"
20
+ end
21
+ end
22
+
23
+ class NonExistingApplication < StandardError; end
24
+
25
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'basic'
2
+
3
+ class Scenarios < Basic
4
+ def create(options)
5
+ @client.webcheck_create(options) unless exists?(options)
6
+ end
7
+
8
+ def get_id(options)
9
+ @client.webcheck_get({
10
+ 'filter' => {'name' => options['name'],
11
+ 'hostid' => options['hostid']}})
12
+ end
13
+
14
+ def delete(options)
15
+ @client.webcheck_delete(options)
16
+ end
17
+
18
+ def exists?(options)
19
+ result = @client.webcheck_get({
20
+ 'countOutput' => true,
21
+ 'filter' => {'name' => options['name'],
22
+ 'hostid' => options['hostid']}})
23
+ if result.to_i >= 1
24
+ true
25
+ else
26
+ false
27
+ end
28
+ end
29
+ end
data/lib/zapix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zapix
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/zapix.rb CHANGED
@@ -26,4 +26,12 @@ class ZabbixAPI
26
26
  @templates ||= Templates.new(@client)
27
27
  end
28
28
 
29
+ def applications
30
+ @applications ||= Applications.new(@client)
31
+ end
32
+
33
+ def scenarios
34
+ @scenarios ||= Scenarios.new(@client)
35
+ end
36
+
29
37
  end
data/spec/zapix_specs.rb CHANGED
@@ -12,8 +12,9 @@ another_hostgroup = 'anotherhostgroup'
12
12
  hostgroup_with_hosts = 'withhosts'
13
13
  template_1 = 'Template OS Linux'
14
14
  template_2 = 'Template App MySQL'
15
- application = 'application'
15
+ application = 'web scenarios'
16
16
  host = 'hostname'
17
+ scenario = 'scenario'
17
18
 
18
19
  describe ZabbixAPI do
19
20
 
@@ -87,7 +88,7 @@ describe ZabbixAPI do
87
88
 
88
89
  end
89
90
 
90
- context 'complex hostgroup should be easy to delete' do
91
+ context 'complex hostgroup' do
91
92
  before(:each) do
92
93
  zrc.hostgroups.create(hostgroup_with_hosts)
93
94
  hostgroup_id = zrc.hostgroups.get_id(hostgroup_with_hosts)
@@ -98,6 +99,20 @@ describe ZabbixAPI do
98
99
  example_host.add_group_ids(hostgroup_id)
99
100
  example_host.add_template_ids(zrc.templates.get_id(template_1), zrc.templates.get_id(template_2))
100
101
  zrc.hosts.create_or_update(example_host.to_hash)
102
+
103
+ # create application for the host
104
+ application_options = {}
105
+ application_options['name'] = application
106
+ application_options['hostid'] = zrc.hosts.get_id(host)
107
+ zrc.applications.create(application_options)
108
+
109
+ # creates web scenarios for host
110
+ webcheck_options = {}
111
+ webcheck_options['hostid'] = zrc.hosts.get_id(host)
112
+ webcheck_options['name'] = scenario
113
+ webcheck_options['applicationid'] = zrc.applications.get_id(application_options)
114
+ webcheck_options['steps'] = [{'name' => 'Homepage', 'url' => 'm.test.de', 'status_codes' => 200, 'no' => 1}]
115
+ zrc.scenarios.create(webcheck_options)
101
116
  end
102
117
 
103
118
  after(:each) do
@@ -169,6 +184,69 @@ describe ZabbixAPI do
169
184
  options['macros'] = [{'macro' => '{$TESTMACRO}', 'value' => 'this is only a test macro'}]
170
185
  zrc.hosts.update_macros(options)
171
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
+
195
+ it 'returns true if an application exists' do
196
+ options = {}
197
+ options['name'] = application
198
+ options['hostid'] = zrc.hosts.get_id(host)
199
+ zrc.applications.exists?(options).should be_true
200
+ end
201
+
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)
215
+ end
216
+
217
+ it 'deletes an applications for host' do
218
+ pending 'Not implemented'
219
+ end
220
+
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
226
+ end
227
+
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)
234
+ end
235
+
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
241
+ end
242
+
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
249
+ end
172
250
  end
173
251
 
174
252
  def create_interface
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.7
4
+ version: 0.0.8
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-06-26 00:00:00.000000000 Z
12
+ date: 2013-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -105,9 +105,11 @@ files:
105
105
  - README.md
106
106
  - Rakefile
107
107
  - lib/zapix.rb
108
+ - lib/zapix/proxies/applications.rb
108
109
  - lib/zapix/proxies/basic.rb
109
110
  - lib/zapix/proxies/hostgroups.rb
110
111
  - lib/zapix/proxies/hosts.rb
112
+ - lib/zapix/proxies/scenarios.rb
111
113
  - lib/zapix/proxies/templates.rb
112
114
  - lib/zapix/version.rb
113
115
  - lib/zapix/zabbix_classes/host.rb
@@ -131,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
133
  version: '0'
132
134
  segments:
133
135
  - 0
134
- hash: 1937690048835696292
136
+ hash: 298514097946572949
135
137
  required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  none: false
137
139
  requirements:
@@ -140,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
142
  version: '0'
141
143
  segments:
142
144
  - 0
143
- hash: 1937690048835696292
145
+ hash: 298514097946572949
144
146
  requirements: []
145
147
  rubyforge_project:
146
148
  rubygems_version: 1.8.24