rubix 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
@@ -3,12 +3,11 @@ module Rubix
3
3
  class Action < Model
4
4
 
5
5
  # Numeric codes for the event source. Default will be 'triggers'.
6
- EVENT_SOURCE_CODES = {
6
+ zabbix_define :EVENT_SOURCE, {
7
7
  :triggers => 0,
8
8
  :discovery => 1,
9
9
  :auto_registration => 2
10
- }.freeze
11
- EVENT_SOURCE_NAMES = EVENT_SOURCE_CODES.invert.freeze
10
+ }
12
11
 
13
12
  # The default subject for messages.
14
13
  MESSAGE_SUBJECT = "{TRIGGER.NAME}: {TRIGGER.STATUS}"
@@ -4,44 +4,42 @@ module Rubix
4
4
 
5
5
  # Numeric codes for the operator to use to join conditions for
6
6
  # this action. Default is 'and_or'.
7
- JOIN_CODES = {
7
+ zabbix_define :JOIN, {
8
8
  :and_or => 0,
9
9
  :and => 1,
10
10
  :or => 2
11
- }.freeze
12
- JOIN_NAMES = JOIN_CODES.invert.freeze
11
+ }
13
12
 
14
13
  # Numeric codes for the event source.
15
- TYPE_CODES = {
16
- :host_group => 0,
17
- :host => 1,
18
- :trigger => 2,
19
- :trigger_name => 3,
20
- :trigger_severity => 4,
21
- :trigger_value => 5,
22
- :time_period => 6,
23
- :dhost_ip => 7,
24
- :dservice_type => 8,
25
- :dservice_port => 9,
26
- :dstatus => 10,
27
- :duptime => 11,
28
- :dvalue => 12,
29
- :host_template => 13,
30
- :event_acknowledged => 14,
31
- :application => 15,
32
- :maintenance => 16,
33
- :node => 17,
34
- :drule => 18,
35
- :dcheck => 19,
36
- :proxy => 20,
37
- :dobject => 21,
38
- :host_name => 22
39
- }.freeze
40
- TYPE_NAMES = TYPE_CODES.invert.freeze
14
+ zabbix_define :TYPE, {
15
+ :host_group => 0,
16
+ :host => 1,
17
+ :trigger => 2,
18
+ :trigger_name => 3,
19
+ :trigger_severity => 4,
20
+ :trigger_value => 5,
21
+ :time_period => 6,
22
+ :dhost_ip => 7,
23
+ :dservice_type => 8,
24
+ :dservice_port => 9,
25
+ :dstatus => 10,
26
+ :duptime => 11,
27
+ :dvalue => 12,
28
+ :host_template => 13,
29
+ :event_acknowledged => 14,
30
+ :application => 15,
31
+ :maintenance => 16,
32
+ :node => 17,
33
+ :drule => 18,
34
+ :dcheck => 19,
35
+ :proxy => 20,
36
+ :dobject => 21,
37
+ :host_name => 22
38
+ }
41
39
 
42
40
  # Numeric codes for the operator used to compare a condition's
43
41
  # type to its value.
44
- OPERATOR_CODES = {
42
+ zabbix_define :OPERATOR, {
45
43
  :equal => 0,
46
44
  :not_equal => 1,
47
45
  :like => 2,
@@ -49,9 +47,8 @@ module Rubix
49
47
  :in => 4,
50
48
  :gte => 5,
51
49
  :lte => 6,
52
- :not_in => 7,
53
- }.freeze
54
- OPERATOR_NAMES = OPERATOR_CODES.invert.freeze
50
+ :not_in => 7
51
+ }
55
52
 
56
53
  #
57
54
  # == Properties & Finding ==
@@ -14,7 +14,7 @@ module Rubix
14
14
  DEFAULT_PORT = 10050
15
15
 
16
16
  # The numeric codes for the various status types.
17
- STATUS_CODES = {
17
+ zabbix_define :STATUS, {
18
18
  :monitored => 0,
19
19
  :not_monitored => 1,
20
20
  :unreachable => 2,
@@ -22,8 +22,7 @@ module Rubix
22
22
  :deleted => 4,
23
23
  :proxy_active => 5,
24
24
  :proxy_passive => 6
25
- }.freeze
26
- STATUS_NAMES = STATUS_CODES.invert.freeze
25
+ }
27
26
 
28
27
  zabbix_attr :name
29
28
  zabbix_attr :ip
@@ -9,7 +9,7 @@ module Rubix
9
9
  # The numeric codes for the various item types.
10
10
  #
11
11
  # Items without a type will be set to 'zabbix'.
12
- TYPE_CODES = {
12
+ zabbix_define :TYPE, {
13
13
  :zabbix => 0,
14
14
  :snmpv1 => 1,
15
15
  :trapper => 2,
@@ -26,42 +26,38 @@ module Rubix
26
26
  :ssh => 13,
27
27
  :telnet => 14,
28
28
  :calculated => 15
29
- }.freeze
30
- TYPE_NAMES = TYPE_CODES.invert.freeze
29
+ }
31
30
 
32
31
  # The numeric codes for the value types of a Zabbix item.
33
32
  #
34
33
  # This Hash is used by ZabbixPipe#value_code_from_value to
35
34
  # dynamically set the type of a value when creating a new Zabbix
36
35
  # item.
37
- VALUE_CODES = {
36
+ zabbix_define :VALUE, {
38
37
  :float => 0, # Numeric (float)
39
38
  :character => 1, # Character
40
39
  :log_line => 2, # Log
41
40
  :unsigned_int => 3, # Numeric (unsigned)
42
41
  :text => 4 # Text
43
- }.freeze
44
- VALUE_NAMES = VALUE_CODES.invert.freeze
42
+ }
45
43
 
46
44
  # The numeric codes for the data types of a Zabbix item.
47
45
  #
48
46
  # The default will be <tt>:decimal</tt>
49
- DATA_CODES = {
47
+ zabbix_define :DATA, {
50
48
  :decimal => 0,
51
49
  :octal => 1,
52
50
  :hexadecimal => 2
53
- }.freeze
54
- DATA_NAMES = DATA_CODES.invert.freeze
51
+ }
55
52
 
56
53
  # The numeric codes for the status of a Zabbix item.
57
54
  #
58
55
  # The default will be <tt>:active</tt>
59
- STATUS_CODES = {
56
+ zabbix_define :STATUS, {
60
57
  :active => 0,
61
58
  :disabled => 1,
62
59
  :not_supported => 3
63
- }.freeze
64
- STATUS_NAMES = STATUS_CODES.invert.freeze
60
+ }
65
61
 
66
62
  # Return the +value_type+ name (:float, :text, &c.) for a Zabbix
67
63
  # item's value type by examining the given +value+.
@@ -5,14 +5,13 @@ module Rubix
5
5
  # The numeric codes corresponding to each media type.
6
6
  #
7
7
  # The default will be 'script'.
8
- TYPE_CODES = {
8
+ zabbix_define :TYPE, {
9
9
  :email => 0,
10
10
  :script => 1,
11
11
  :sms => 2,
12
12
  :jabber => 3,
13
13
  :ez_texting => 100
14
- }.freeze
15
- TYPE_NAMES = TYPE_CODES.invert.freeze
14
+ }
16
15
 
17
16
  #
18
17
  # == Properties & Finding ==
@@ -8,7 +8,7 @@ module Rubix
8
8
  # and :warning triggers but rejecting :information triggers. In
9
9
  # the interests of simplicity, we avoid exposing that degree of
10
10
  # freedom here.
11
- PRIORITY_CODES = {
11
+ zabbix_define :PRIORITY, {
12
12
  :none => 0,
13
13
  :not_classified => 63,
14
14
  :information => 62,
@@ -18,8 +18,7 @@ module Rubix
18
18
  :disaster => 32,
19
19
  :all => 63,
20
20
  nil => 63
21
- }.freeze
22
- PRIORITY_NAMES = PRIORITY_CODES.invert.freeze
21
+ }
23
22
 
24
23
  #
25
24
  # == Properties & Finding ==
@@ -32,7 +31,7 @@ module Rubix
32
31
 
33
32
  attr_writer :severity
34
33
  def severity
35
- @severity ||= self.class::PRIORITY_CODES[priority]
34
+ @severity ||= self.class::PRIORITY_CODES[(priority || :all)]
36
35
  end
37
36
 
38
37
  def self.id_field
@@ -65,7 +64,7 @@ module Rubix
65
64
  :userid => user_id,
66
65
  :sendto => address,
67
66
  :active => (enabled ? 0 : 1),
68
- :severity => (severity || self.class::PRIORITY_CODES[priority]),
67
+ :severity => (severity || self.class::PRIORITY_CODES[(priority || :all)]),
69
68
  :period => timeframe
70
69
  }
71
70
  end
@@ -438,6 +438,17 @@ module Rubix
438
438
  end
439
439
  end
440
440
  end
441
+
442
+ def self.zabbix_define defname, hash
443
+ codes = hash
444
+ names = hash.invert.freeze
445
+ codes.keys.each do |key|
446
+ codes[key.to_s] = codes[key]
447
+ end
448
+ codes.freeze
449
+ const_set "#{defname}_CODES", codes
450
+ const_set "#{defname}_NAMES", names
451
+ end
441
452
 
442
453
  end
443
454
  end
@@ -3,7 +3,7 @@ module Rubix
3
3
  class Operation < Model
4
4
 
5
5
  # Numeric codes for the action's type.
6
- TYPE_CODES = {
6
+ zabbix_define :TYPE, {
7
7
  :message => 0,
8
8
  :command => 1,
9
9
  :host_add => 2,
@@ -14,16 +14,14 @@ module Rubix
14
14
  :template_remove => 7,
15
15
  :host_enable => 8,
16
16
  :host_disable => 9
17
- }.freeze
18
- TYPE_NAMES = TYPE_CODES.invert.freeze
17
+ }
19
18
 
20
19
  # Numeric codes for the type of object that should be notified.
21
20
  # Default will be 'group'.
22
- NOTIFICATION_OBJECT_CODES = {
21
+ zabbix_define :NOTIFICATION_OBJECT, {
23
22
  :user => 0,
24
23
  :user_group => 1
25
- }.freeze
26
- NOTIFICATION_OBJECT_NAMES = NOTIFICATION_OBJECT_CODES.invert.freeze
24
+ }
27
25
 
28
26
  #
29
27
  # == Properties & Finding ==
@@ -6,11 +6,10 @@ module Rubix
6
6
  # a host.
7
7
  #
8
8
  # Default is 'read'.
9
- ACCESS_CODES = {
9
+ zabbix_define :ACCESS, {
10
10
  :read => 2,
11
11
  :write => 3
12
- }.freeze
13
- ACCESS_NAMES = ACCESS_CODES.invert.freeze
12
+ }
14
13
 
15
14
  #
16
15
  # == Properties & Finding ==
@@ -6,21 +6,19 @@ module Rubix
6
6
  # == Properties & Finding ==
7
7
  #
8
8
 
9
- PRIORITY_NAMES = {
9
+ zabbix_define :PRIORITY, {
10
10
  :not_classified => 0,
11
11
  :information => 1,
12
12
  :warning => 2,
13
13
  :average => 3,
14
14
  :high => 4,
15
15
  :disaster => 5
16
- }.freeze
17
- PRIORITY_CODES = PRIORITY_NAMES.invert.freeze
16
+ }
18
17
 
19
- STATUS_NAMES = {
18
+ zabbix_define :STATUS, {
20
19
  :enabled => 0,
21
20
  :disabled => 1
22
- }.freeze
23
- STATUS_CODES = STATUS_NAMES.invert.freeze
21
+ }
24
22
 
25
23
  zabbix_attr :description
26
24
  zabbix_attr :url
@@ -59,6 +57,10 @@ module Rubix
59
57
  @expression = e
60
58
  end
61
59
 
60
+ def resource_name
61
+ "#{self.class.resource_name} #{self.description || self.id}"
62
+ end
63
+
62
64
  #
63
65
  # == Associations ==
64
66
  #
@@ -76,8 +78,8 @@ module Rubix
76
78
  :templateid => (template_id || host_id),
77
79
  :description => (description || 'Unknown'),
78
80
  :expression => expression,
79
- :priority => self.class::PRIORITY_NAMES[priority],
80
- :status => self.class::STATUS_NAMES[status],
81
+ :priority => self.class::PRIORITY_CODES[priority],
82
+ :status => self.class::STATUS_CODES[status],
81
83
  :comments => comments,
82
84
  :url => url
83
85
  }
@@ -110,8 +112,8 @@ module Rubix
110
112
  :expression => trigger['expression'],
111
113
  :comments => trigger['comments'],
112
114
  :url => trigger['url'],
113
- :status => STATUS_CODES[trigger['status'].to_i],
114
- :priority => PRIORITY_CODES[trigger['priority'].to_i],
115
+ :status => STATUS_NAMES[trigger['status'].to_i],
116
+ :priority => PRIORITY_NAMES[trigger['priority'].to_i],
115
117
  :item_ids => (trigger['items'] || []).map { |item| item['itemid'].to_i }
116
118
  }.merge(host_or_template_params_from_id(trigger['templateid'].to_i)))
117
119
  end
@@ -5,12 +5,11 @@ module Rubix
5
5
  class User < Model
6
6
 
7
7
  # Numeric codes for the various user types.
8
- TYPE_CODES = {
8
+ zabbix_define :TYPE, {
9
9
  :normal => 1,
10
10
  :admin => 2,
11
11
  :super_admin => 3
12
- }.freeze
13
- TYPE_NAMES = TYPE_CODES.invert.freeze
12
+ }
14
13
 
15
14
  #
16
15
  # == Properties & Finding ==
@@ -41,9 +40,14 @@ module Rubix
41
40
  self.media = properties[:media]
42
41
  end
43
42
 
43
+ def resource_name
44
+ "#{self.class.resource_name} #{self.username || self.id}"
45
+ end
46
+
44
47
  #
45
48
  # == Validations ==
46
49
  #
50
+
47
51
  def validate
48
52
  super()
49
53
  raise ValidationError.new("A new user must have a password") if new_record? && (password.nil? || password.empty?)
@@ -4,12 +4,11 @@ module Rubix
4
4
 
5
5
  # Numeric codes for the types of access allowed to the GUI for
6
6
  # users in the group. Default is, well, 'default'.
7
- GUI_ACCESS_CODES = {
7
+ zabbix_define :GUI_ACCESS, {
8
8
  :default => 0,
9
9
  :internal => 1,
10
10
  :disabled => 2
11
- }.freeze
12
- GUI_ACCESS_NAMES = GUI_ACCESS_CODES.invert.freeze
11
+ }
13
12
 
14
13
  #
15
14
  # == Properties & Finding ==
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubix::Model do
4
+
5
+ before do
6
+ @model_wrapper = Class.new(Rubix::Model)
7
+ @model_wrapper.zabbix_define :FOO, { :bar => 0, :booz => 1 }
8
+ @model_wrapper.zabbix_attr :snap
9
+ @model_wrapper.zabbix_attr :crackle, :default => 'how'
10
+ @model_wrapper.zabbix_attr :pop, :required => true
11
+ end
12
+
13
+ it "can define attributes" do
14
+ @model = @model_wrapper.new
15
+ @model.snap.should be_nil
16
+ @model.snap = 3
17
+ @model.snap.should == 3
18
+ end
19
+
20
+ it "can define attributes with defaults" do
21
+ @model_wrapper.new.crackle.should == 'how'
22
+ end
23
+
24
+ it "can define required attributs" do
25
+ lambda { @model_wrapper.new.validate }.should raise_error(Rubix::ValidationError)
26
+ end
27
+
28
+ it "will define a lookup hash for translating between names and integer codes" do
29
+ @model_wrapper::FOO_CODES[:bar].should == 0
30
+ @model_wrapper::FOO_CODES[:booz].should == 1
31
+ @model_wrapper::FOO_NAMES[0].should == :bar
32
+ @model_wrapper::FOO_NAMES[1].should == :booz
33
+ end
34
+
35
+ it "will define a lookup hash that acts as a Mash when looking up names to codes" do
36
+ @model_wrapper::FOO_CODES[:bar].should == 0
37
+ @model_wrapper::FOO_CODES['bar'].should == 0
38
+ end
39
+
40
+ end
41
+
metadata CHANGED
@@ -1,102 +1,82 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rubix
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 5
8
- - 1
9
- version: 0.5.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Dhruv Bansal
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-02-17 00:00:00 -06:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-27 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &21980180 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :development
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: mysql2
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *21980180
25
+ - !ruby/object:Gem::Dependency
26
+ name: mysql2
27
+ requirement: &21979680 !ruby/object:Gem::Requirement
37
28
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
44
33
  type: :development
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: json
48
34
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *21979680
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &21977020 !ruby/object:Gem::Requirement
50
39
  none: false
51
- requirements:
40
+ requirements:
52
41
  - - <=
53
- - !ruby/object:Gem::Version
54
- segments:
55
- - 1
56
- - 6
57
- - 1
42
+ - !ruby/object:Gem::Version
58
43
  version: 1.6.1
59
44
  type: :runtime
60
- version_requirements: *id003
61
- - !ruby/object:Gem::Dependency
62
- name: configliere
63
45
  prerelease: false
64
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *21977020
47
+ - !ruby/object:Gem::Dependency
48
+ name: configliere
49
+ requirement: &21976500 !ruby/object:Gem::Requirement
65
50
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
- - 4
72
- - 8
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
73
54
  version: 0.4.8
74
55
  type: :runtime
75
- version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- name: multipart-post
78
56
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *21976500
58
+ - !ruby/object:Gem::Dependency
59
+ name: multipart-post
60
+ requirement: &21976060 !ruby/object:Gem::Requirement
80
61
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- segments:
85
- - 0
86
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
87
66
  type: :runtime
88
- version_requirements: *id005
89
- description: Rubix provides abstractions for connecting to Zabbix's API, an ORM for wrapping Zabbix resources, a set of scripts for writing data to Zabbix, and a collection of Monitor classes for building periodic monitors.
90
- email:
67
+ prerelease: false
68
+ version_requirements: *21976060
69
+ description: Rubix provides abstractions for connecting to Zabbix's API, an ORM for
70
+ wrapping Zabbix resources, a set of scripts for writing data to Zabbix, and a collection
71
+ of Monitor classes for building periodic monitors.
72
+ email:
91
73
  - dhruv@infochimps.com
92
- executables:
74
+ executables:
93
75
  - zabbix_api
94
76
  - zabbix_pipe
95
77
  extensions: []
96
-
97
78
  extra_rdoc_files: []
98
-
99
- files:
79
+ files:
100
80
  - bin/zabbix_api
101
81
  - bin/zabbix_pipe
102
82
  - lib/rubix.rb
@@ -150,6 +130,7 @@ files:
150
130
  - lib/rubix/connection.rb
151
131
  - lib/rubix/associations.rb
152
132
  - spec/test.yml
133
+ - spec/rubix/model_spec.rb
153
134
  - spec/rubix/auto_sender_spec.rb
154
135
  - spec/rubix/monitors/monitor_spec.rb
155
136
  - spec/rubix/monitors/chef_monitor_spec.rb
@@ -180,37 +161,28 @@ files:
180
161
  - LICENSE
181
162
  - README.rdoc
182
163
  - VERSION
183
- has_rdoc: true
184
164
  homepage: http://github.com/dhruvbansal/rubix
185
165
  licenses: []
186
-
187
166
  post_install_message:
188
167
  rdoc_options: []
189
-
190
- require_paths:
168
+ require_paths:
191
169
  - lib
192
- required_ruby_version: !ruby/object:Gem::Requirement
170
+ required_ruby_version: !ruby/object:Gem::Requirement
193
171
  none: false
194
- requirements:
195
- - - ">="
196
- - !ruby/object:Gem::Version
197
- segments:
198
- - 0
199
- version: "0"
200
- required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
177
  none: false
202
- requirements:
203
- - - ">="
204
- - !ruby/object:Gem::Version
205
- segments:
206
- - 0
207
- version: "0"
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
208
182
  requirements: []
209
-
210
183
  rubyforge_project:
211
- rubygems_version: 1.3.7
184
+ rubygems_version: 1.8.17
212
185
  signing_key:
213
186
  specification_version: 3
214
187
  summary: A Ruby client for configuring and writing data to Zabbix
215
188
  test_files: []
216
-