zapix 0.1.1 → 0.1.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.
@@ -1,21 +1,21 @@
1
- require_relative 'basic'
1
+ require_relative 'base'
2
2
 
3
- class Actions < Basic
3
+ class Actions < Base
4
4
  def exists?(options)
5
- @client.action_exists(options)
5
+ client.action_exists(options)
6
6
  end
7
7
 
8
8
  def create(options)
9
- @client.action_create(options) unless exists?(options)
9
+ client.action_create(options) unless exists?(options)
10
10
  end
11
11
 
12
12
  def get_id(options)
13
- result = @client.action_get({
13
+ result = client.action_get({
14
14
  'filter' => {'name' => options['name']}})
15
15
  result.first['actionid']
16
16
  end
17
17
 
18
18
  def delete(*action_ids)
19
- @client.action_delete(action_ids)
19
+ client.action_delete(action_ids)
20
20
  end
21
21
  end
@@ -1,18 +1,18 @@
1
- require_relative 'basic'
1
+ require_relative 'base'
2
2
 
3
- class Applications < Basic
3
+ class Applications < Base
4
4
 
5
5
  def create(options)
6
- @client.application_create(options) unless exists?(options)
6
+ client.application_create(options) unless exists?(options)
7
7
  end
8
8
 
9
9
  def exists?(options)
10
- @client.application_exists(options)
10
+ client.application_exists(options)
11
11
  end
12
12
 
13
13
  def get_id(options)
14
14
  if exists?(options)
15
- @client.application_get({
15
+ client.application_get({
16
16
  'filter' => {'name' => options['name'],
17
17
  'hostid' => options['hostid']}}).first['applicationid']
18
18
  else
@@ -1,6 +1,6 @@
1
- require_relative 'basic'
1
+ require_relative 'base'
2
2
 
3
- class HostGroups < Basic
3
+ class HostGroups < Base
4
4
 
5
5
  def mass_create(*names)
6
6
  names.each do |group_name|
@@ -9,25 +9,25 @@ class HostGroups < Basic
9
9
  end
10
10
 
11
11
  def create(name)
12
- @client.hostgroup_create({'name' => name}) unless exists?(name)
12
+ client.hostgroup_create({'name' => name}) unless exists?(name)
13
13
  end
14
14
 
15
15
  def create_or_update(name)
16
16
  if(exists?(name))
17
17
  id = get_id(name)
18
- @client.hostgroup_update({'groupid' => id,'name' => name})
18
+ client.hostgroup_update({'groupid' => id,'name' => name})
19
19
  else
20
20
  create(name)
21
21
  end
22
22
  end
23
23
 
24
24
  def exists?(name)
25
- @client.hostgroup_exists({'name' => name})
25
+ client.hostgroup_exists({'name' => name})
26
26
  end
27
27
 
28
28
  def get_id(name)
29
29
  if(exists?(name))
30
- result = @client.hostgroup_get({'filter' => {'name' => [name]}})
30
+ result = client.hostgroup_get({'filter' => {'name' => [name]}})
31
31
  result[0]['groupid']
32
32
  else
33
33
  raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
@@ -41,18 +41,14 @@ class HostGroups < Basic
41
41
  end
42
42
 
43
43
  def get_host_ids_of(hostgroup)
44
- result = @client.hostgroup_get('filter' => {'name' => [hostgroup]}, 'selectHosts' => 'refer')
44
+ result = client.hostgroup_get('filter' => {'name' => [hostgroup]}, 'selectHosts' => 'refer')
45
45
  extract_host_ids(result)
46
46
  end
47
47
 
48
48
  def any_hosts?(hostgroup)
49
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
50
+ result = client.hostgroup_get('filter' => {'name' => [hostgroup]}, 'selectHosts' => 'count').first['hosts'].to_i
51
+ result >= 1 ? true : false
56
52
  end
57
53
 
58
54
  def delete(name)
@@ -63,12 +59,12 @@ class HostGroups < Basic
63
59
  # delete all hosts attached to a hostgroup
64
60
  host_ids = get_host_ids_of(name)
65
61
  host_ids.each do |id|
66
- @client.host_delete(['hostid' => id])
62
+ client.host_delete(['hostid' => id])
67
63
  end
68
64
  # now it is ok to delete the group
69
- @client.hostgroup_delete([get_id(name)])
65
+ client.hostgroup_delete([get_id(name)])
70
66
  else
71
- @client.hostgroup_delete([get_id(name)])
67
+ client.hostgroup_delete([get_id(name)])
72
68
  end
73
69
  else
74
70
  raise NonExistingHostgroup, "Hostgroup #{name} does not exist !"
@@ -78,7 +74,7 @@ class HostGroups < Basic
78
74
  def get_all
79
75
  # the fucking API also returns the ids and that's
80
76
  # why we need to extract the names
81
- host_groups_with_ids = @client.hostgroup_get({'output' => ['name']})
77
+ host_groups_with_ids = client.hostgroup_get({'output' => ['name']})
82
78
  extract_host_groups(host_groups_with_ids)
83
79
  end
84
80
 
@@ -1,21 +1,17 @@
1
- require_relative 'basic'
1
+ require_relative 'base'
2
2
 
3
- class Hostinterfaces < Basic
3
+ class Hostinterfaces < Base
4
4
 
5
5
  def create(options)
6
- @client.hostinterface_create(options) unless exists?(options)
6
+ client.hostinterface_create(options) unless exists?(options)
7
7
  end
8
8
 
9
9
  def exists?(options)
10
- if get(options).empty?
11
- false
12
- else
13
- true
14
- end
10
+ get(options).empty? ? false : true
15
11
  end
16
12
 
17
13
  def get(options)
18
- @client.hostinterface_get(
14
+ client.hostinterface_get(
19
15
  {'filter' => {'hostid' => options['hostid'],
20
16
  'port' => options['port'],
21
17
  'type' => options['type']},
@@ -1,16 +1,16 @@
1
- require_relative 'basic'
2
- class Hosts < Basic
1
+ require_relative 'base'
2
+ class Hosts < Base
3
3
 
4
4
  def get_id(name)
5
5
  if(exists?(name))
6
- @client.host_get({'filter' => {'host' => name}}).first['hostid']
6
+ client.host_get({'filter' => {'host' => name}}).first['hostid']
7
7
  else
8
8
  raise NonExistingHost, "Host #{name} does not exist !"
9
9
  end
10
10
  end
11
11
 
12
12
  def create(options={})
13
- @client.host_create(options) unless exists?(options["host"])
13
+ client.host_create(options) unless exists?(options["host"])
14
14
  end
15
15
 
16
16
  def create_or_update(options={})
@@ -18,7 +18,7 @@ class Hosts < Basic
18
18
  if exists?(options['host'])
19
19
  id = get_id(options['host'])
20
20
  options.merge!('hostid' => id)
21
- @client.host_update(options)
21
+ client.host_update(options)
22
22
  else
23
23
  create(options)
24
24
  end
@@ -26,24 +26,24 @@ class Hosts < Basic
26
26
 
27
27
  def unlink_and_clear_templates(options={})
28
28
  template_ids = options['template_ids'].map { |id| {'templateid' => id}}
29
- @client.host_update({'hostid' => options['host_id'], 'templates_clear' => template_ids})
29
+ client.host_update({'hostid' => options['host_id'], 'templates_clear' => template_ids})
30
30
  end
31
31
 
32
32
  def update_templates(options={})
33
33
  template_ids = options['template_ids'].map { |id| {'templateid' => id}}
34
- @client.host_update({'hostid' => options['host_id'], 'templates' => template_ids})
34
+ client.host_update({'hostid' => options['host_id'], 'templates' => template_ids})
35
35
  end
36
36
 
37
37
  def update_macros(options={})
38
- @client.host_update('hostid' => options['host_id'], 'macros' => options['macros'])
38
+ client.host_update('hostid' => options['host_id'], 'macros' => options['macros'])
39
39
  end
40
40
 
41
41
  def exists?(name)
42
- @client.host_exists({'host' => name})
42
+ client.host_exists({'host' => name})
43
43
  end
44
44
 
45
45
  def get_all
46
- host_names_and_ids = @client.host_get({'output' => ['name']})
46
+ host_names_and_ids = client.host_get({'output' => ['name']})
47
47
 
48
48
  # the fucking api ALWAYS returns the ids and that's
49
49
  # why we need to extract the names separately
@@ -53,7 +53,7 @@ class Hosts < Basic
53
53
 
54
54
  def delete(name)
55
55
  if exists?(name)
56
- @client.host_delete(['hostid' => get_id(name)])
56
+ client.host_delete(['hostid' => get_id(name)])
57
57
  else
58
58
  raise NonExistingHost, "Host #{name} cannot be deleted because it does not exist !"
59
59
  end
@@ -62,7 +62,7 @@ class Hosts < Basic
62
62
  class NonExistingHost < StandardError; end
63
63
  class EmptyHostname < StandardError; end
64
64
 
65
- private
65
+ private
66
66
 
67
67
  def extract_host_names(hosts_and_ids)
68
68
  hosts_and_ids.map do |current_host|
@@ -1,29 +1,26 @@
1
- require_relative 'basic'
1
+ require_relative 'base'
2
2
 
3
- class Scenarios < Basic
3
+ class Scenarios < Base
4
4
  def create(options)
5
- @client.webcheck_create(options) unless exists?(options)
5
+ client.webcheck_create(options) unless exists?(options)
6
6
  end
7
7
 
8
8
  def get_id(options)
9
- @client.webcheck_get({
9
+ client.webcheck_get({
10
10
  'filter' => {'name' => options['name'],
11
11
  'hostid' => options['hostid']}})
12
12
  end
13
13
 
14
14
  def delete(options)
15
- @client.webcheck_delete(options)
15
+ client.webcheck_delete(options)
16
16
  end
17
17
 
18
18
  def exists?(options)
19
- result = @client.webcheck_get({
19
+ result = client.webcheck_get({
20
20
  'countOutput' => true,
21
21
  'filter' => {'name' => options['name'],
22
22
  'hostid' => options['hostid']}})
23
- if result.to_i >= 1
24
- true
25
- else
26
- false
27
- end
23
+
24
+ result.to_i >= 1 ? true : false
28
25
  end
29
26
  end
@@ -1,22 +1,21 @@
1
- require_relative 'basic'
2
- class Templates < Basic
1
+ require_relative 'base'
2
+ class Templates < Base
3
3
 
4
4
  def exists?(name)
5
- @client.template_exists({'name' => name})
5
+ client.template_exists({'name' => name})
6
6
  end
7
7
 
8
8
  def get_id(name)
9
9
  if(exists?(name))
10
- @client.template_get({'filter' => {'name' => name}}).first['templateid']
10
+ client.template_get({'filter' => {'name' => name}}).first['templateid']
11
11
  else
12
12
  raise NonExistingTemplate, "Template #{name} does not exist !"
13
13
  end
14
14
  end
15
15
 
16
16
  def get_templates_for_host(id)
17
- @client.template_get({'hostids' => [id]}).map { |result_set| result_set['templateid'] }
17
+ client.template_get({'hostids' => [id]}).map { |result_set| result_set['templateid'] }
18
18
  end
19
19
 
20
20
  class NonExistingTemplate < StandardError; end
21
-
22
21
  end
@@ -1,20 +1,20 @@
1
- require_relative 'basic'
2
- class Triggers < Basic
1
+ require_relative 'base'
2
+ class Triggers < Base
3
3
 
4
4
  def exists?(options)
5
- @client.trigger_exists(options)
5
+ client.trigger_exists(options)
6
6
  end
7
7
 
8
8
  def create(options)
9
- @client.trigger_create(options) unless exists?(options)
9
+ client.trigger_create(options) unless exists?(options)
10
10
  end
11
11
 
12
12
  def delete(*trigger_ids)
13
- @client.trigger_delete(trigger_ids)
13
+ client.trigger_delete(trigger_ids)
14
14
  end
15
15
 
16
16
  def get_id(options)
17
- result = @client.trigger_get({'output' => 'extend',
17
+ result = client.trigger_get({'output' => 'extend',
18
18
  'expandExpression' => true})
19
19
  id = extract_id(result, options['expression'])
20
20
  unless id.nil?
@@ -26,7 +26,7 @@ class Triggers < Basic
26
26
 
27
27
  class NonExistingTrigger < StandardError; end
28
28
 
29
- private
29
+ private
30
30
 
31
31
  def extract_id(triggers, expression)
32
32
  result = nil
@@ -1,18 +1,18 @@
1
- require_relative 'basic'
1
+ require_relative 'base'
2
2
 
3
- class Usergroups < Basic
3
+ class Usergroups < Base
4
4
 
5
5
  def create(options)
6
- @client.usergroup_create(options) unless exists?(options)
6
+ client.usergroup_create(options) unless exists?(options)
7
7
  end
8
8
 
9
9
  def exists?(options)
10
- @client.usergroup_exists(options)
10
+ client.usergroup_exists(options)
11
11
  end
12
12
 
13
13
  def get_id(options)
14
14
  if(exists?(options))
15
- result = @client.usergroup_get({
15
+ result = client.usergroup_get({
16
16
  'filter' => {'name' => options['name']}})
17
17
  result.first['usrgrpid']
18
18
  else
@@ -21,7 +21,7 @@ class Usergroups < Basic
21
21
  end
22
22
 
23
23
  def delete(*group_ids)
24
- @client.usergroup_delete(group_ids)
24
+ client.usergroup_delete(group_ids)
25
25
  end
26
26
 
27
27
  class NonExistingUsergroup < StandardError; end
@@ -1,29 +1,25 @@
1
- require_relative 'basic'
1
+ require_relative 'base'
2
2
 
3
- class Users < Basic
3
+ class Users < Base
4
4
  def create(options)
5
- @client.user_create(options) unless exists?(options)
5
+ client.user_create(options) unless exists?(options)
6
6
  end
7
7
 
8
8
  def exists?(options)
9
- result = @client.user_get({'filter' => {'alias' => options['alias']}})
10
- if result.empty?
11
- false
12
- else
13
- true
14
- end
9
+ result = client.user_get({'filter' => {'alias' => options['alias']}})
10
+ result.empty? ? false : true
15
11
  end
16
12
 
17
13
  def get_id(options)
18
14
  if(exists?(options))
19
- @client.user_get({'filter' => {'alias' => options['alias']}}).first['userid']
15
+ client.user_get({'filter' => {'alias' => options['alias']}}).first['userid']
20
16
  else
21
17
  raise NonExistingUser, "User #{options['alias']} does not exist !"
22
18
  end
23
19
  end
24
20
 
25
21
  def delete(usergroup_ids)
26
- @client.user_delete(usergroup_ids)
22
+ client.user_delete(usergroup_ids)
27
23
  end
28
24
 
29
25
  class NonExistingUser < StandardError; end
data/lib/zapix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zapix
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/zapix.rb CHANGED
@@ -2,7 +2,7 @@ require 'zapix/version'
2
2
  require_relative 'zapix/zabbix_rpc_client'
3
3
 
4
4
  class ZabbixAPI
5
- attr :client
5
+ attr_reader :client
6
6
 
7
7
  def self.connect(options = {})
8
8
  new(options)
@@ -15,43 +15,43 @@ class ZabbixAPI
15
15
  end
16
16
 
17
17
  def hostgroups
18
- @hostgroups ||= HostGroups.new(@client)
18
+ @hostgroups ||= HostGroups.new(client)
19
19
  end
20
20
 
21
21
  def hosts
22
- @hosts ||= Hosts.new(@client)
22
+ @hosts ||= Hosts.new(client)
23
23
  end
24
24
 
25
25
  def templates
26
- @templates ||= Templates.new(@client)
26
+ @templates ||= Templates.new(client)
27
27
  end
28
28
 
29
29
  def applications
30
- @applications ||= Applications.new(@client)
30
+ @applications ||= Applications.new(client)
31
31
  end
32
32
 
33
33
  def scenarios
34
- @scenarios ||= Scenarios.new(@client)
34
+ @scenarios ||= Scenarios.new(client)
35
35
  end
36
36
 
37
37
  def triggers
38
- @triggers ||= Triggers.new(@client)
38
+ @triggers ||= Triggers.new(client)
39
39
  end
40
40
 
41
41
  def hostinterfaces
42
- @hostinterfaces ||= Hostinterfaces.new(@client)
42
+ @hostinterfaces ||= Hostinterfaces.new(client)
43
43
  end
44
44
 
45
45
  def actions
46
- @actions ||= Actions.new(@client)
46
+ @actions ||= Actions.new(client)
47
47
  end
48
48
 
49
49
  def usergroups
50
- @usergroups ||= Usergroups.new(@client)
50
+ @usergroups ||= Usergroups.new(client)
51
51
  end
52
52
 
53
53
  def users
54
- @users ||= Users.new(@client)
54
+ @users ||= Users.new(client)
55
55
  end
56
56
 
57
57
  end
data/spec/zapix_specs.rb CHANGED
@@ -21,7 +21,7 @@ non_existing_trigger_expression = '{vfs.file.cksum[/etc/passwd].diff(0)}>0'
21
21
  existing_action_name = 'Report problems to Zabbix administrators'
22
22
  non_existing_action_name = 'No action defined'
23
23
  test_usergroup = 'Operation managers test'
24
- existing_usergroup = 'Admins'
24
+ existing_usergroup = 'Zabbix administrators'
25
25
  non_existing_usergroup = 'Smurfs'
26
26
  existing_user = 'Admin'
27
27
  non_existing_user = 'Tweegle'
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.1.1
4
+ version: 0.1.2
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-29 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -107,7 +107,6 @@ files:
107
107
  - lib/zapix.rb
108
108
  - lib/zapix/proxies/actions.rb
109
109
  - lib/zapix/proxies/applications.rb
110
- - lib/zapix/proxies/basic.rb
111
110
  - lib/zapix/proxies/hostgroups.rb
112
111
  - lib/zapix/proxies/hostinterfaces.rb
113
112
  - lib/zapix/proxies/hosts.rb
@@ -138,7 +137,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
137
  version: '0'
139
138
  segments:
140
139
  - 0
141
- hash: 531610970119711934
140
+ hash: -3541308116562665514
142
141
  required_rubygems_version: !ruby/object:Gem::Requirement
143
142
  none: false
144
143
  requirements:
@@ -147,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
146
  version: '0'
148
147
  segments:
149
148
  - 0
150
- hash: 531610970119711934
149
+ hash: -3541308116562665514
151
150
  requirements: []
152
151
  rubyforge_project:
153
152
  rubygems_version: 1.8.24
@@ -1,5 +0,0 @@
1
- class Basic
2
- def initialize(client)
3
- @client = client
4
- end
5
- end