rubix 0.4.2 → 0.4.3

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
data/lib/rubix/models.rb CHANGED
@@ -8,4 +8,5 @@ module Rubix
8
8
  autoload :UserMacro, 'rubix/models/user_macro'
9
9
  autoload :Trigger, 'rubix/models/trigger'
10
10
  autoload :TimeSeries, 'rubix/models/time_series'
11
+ autoload :MediaType, 'rubix/models/media_type'
11
12
  end
@@ -0,0 +1,86 @@
1
+ module Rubix
2
+
3
+ class MediaType < Model
4
+
5
+ # The numeric codes corresponding to each media type.
6
+ #
7
+ # The default will be 'script'.
8
+ TYPE_CODES = {
9
+ :email => 0,
10
+ :script => 1,
11
+ :sms => 2,
12
+ :jabber => 3,
13
+ :ez_texting => 100
14
+ }.freeze
15
+ TYPE_NAMES = TYPE_CODES.invert.freeze
16
+
17
+ #
18
+ # == Properties & Finding ==
19
+ #
20
+
21
+ attr_accessor :description, :server, :helo, :email, :path, :modem, :username, :password
22
+
23
+ attr_writer :type
24
+ def type
25
+ @type ||= :script
26
+ end
27
+
28
+ def initialize properties={}
29
+ super(properties)
30
+ self.description = properties[:description]
31
+ self.type = properties[:type]
32
+ self.server = properties[:server]
33
+ self.helo = properties[:helo]
34
+ self.email = properties[:email]
35
+ self.path = properties[:path]
36
+ self.modem = properties[:modem]
37
+ self.username = properties[:username]
38
+ self.password = properties[:password]
39
+ end
40
+
41
+ #
42
+ # == Requests ==
43
+ #
44
+
45
+ def create_params
46
+ {
47
+ :description => description,
48
+ :type => TYPE_CODES[type]
49
+ }.tap do |p|
50
+ case type
51
+ when :email
52
+ p[:smtp_server] = server if server
53
+ p[:smtp_helo] = helo if helo
54
+ p[:smtp_email] = email if email
55
+ when :script
56
+ p[:exec_path] = path if path
57
+ when :sms
58
+ p[:gsm_modem] = modem if modem
59
+ when :jabber
60
+ p[:username] = username if username
61
+ p[:passwd] = password if password
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.find_params options={}
67
+ get_params.merge(:filter => {id_field => options[:id], :description => options[:description]})
68
+ end
69
+
70
+ def self.build media_type
71
+ new({
72
+ :id => media_type[id_field].to_i,
73
+ :type => self::TYPE_NAMES[media_type['type'].to_i],
74
+ :description => media_type['description'],
75
+ :server => media_type['smtp_server'],
76
+ :helo => media_type['smtp_helo'],
77
+ :email => media_type['smtp_email'],
78
+ :path => media_type['exec_path'],
79
+ :modem => media_type['gsm_modem'],
80
+ :username => media_type['username'],
81
+ :password => media_type['passwd']
82
+ })
83
+ end
84
+
85
+ end
86
+ end
@@ -190,7 +190,7 @@ module Rubix
190
190
  return false unless before_update
191
191
  response = update_request
192
192
  case
193
- when response.has_data? && response.result.values.first.map(&:to_i).include?(id)
193
+ when response.has_data? && (response.result.values.first == true || response.result.values.first.map(&:to_i).include?(id))
194
194
  info("Updated Zabbix #{resource_name}")
195
195
  true
196
196
  when response.has_data?
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe "MediaTypes" do
4
+
5
+ before do
6
+ integration_test
7
+ end
8
+
9
+ after do
10
+ truncate_all_tables
11
+ end
12
+
13
+ describe "when not existing" do
14
+
15
+ it "returns nil on find" do
16
+ Rubix::MediaType.find(:description => 'rubix_spec_media_type_1').should be_nil
17
+ end
18
+
19
+ it "can be created" do
20
+ mt = Rubix::MediaType.new(:description => 'rubix_spec_media_type_1', :path => 'foo')
21
+ mt.save.should be_true
22
+ end
23
+
24
+ end
25
+
26
+ describe "when existing" do
27
+
28
+ before do
29
+ @mt = ensure_save(Rubix::MediaType.new(:description => 'rubix_spec_media_type_1', :path => 'foo'))
30
+ end
31
+
32
+ it "can be found" do
33
+ Rubix::MediaType.find(:description => 'rubix_spec_media_type_1').should_not be_nil
34
+ end
35
+
36
+ it "can have its properties changed" do
37
+ @mt.description = 'rubix_spec_media_type_2'
38
+ @mt.type = :sms
39
+ @mt.modem = '/foo/bar'
40
+ @mt.save
41
+ Rubix::MediaType.find(:description => 'rubix_spec_media_type_1').should be_nil
42
+ new_mt = Rubix::MediaType.find(:description => 'rubix_spec_media_type_2')
43
+ new_mt.should_not be_nil
44
+ new_mt.type.should == :sms
45
+ new_mt.modem.should == '/foo/bar'
46
+ end
47
+
48
+ it "can be destroyed" do
49
+ @mt.destroy
50
+ Rubix::MediaType.find(:description => 'rubix_spec_media_type_1').should be_nil
51
+ end
52
+ end
53
+
54
+ end
@@ -76,7 +76,7 @@ module Rubix
76
76
  $RUBIX_INTEGRATION_TEST = api_connection
77
77
  end
78
78
 
79
- RUBIX_TABLES_TO_TRUNCATE = %w[applications groups hostmacro hosts hosts_groups hosts_profiles hosts_profiles_ext hosts_templates items items_applications profiles triggers trigger_depends history sessions]
79
+ RUBIX_TABLES_TO_TRUNCATE = %w[applications groups hostmacro hosts hosts_groups hosts_profiles hosts_profiles_ext hosts_templates items items_applications profiles triggers trigger_depends history sessions media_type]
80
80
 
81
81
  def self.truncate_all_tables
82
82
  return unless $RUBIX_INTEGRATION_TEST
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 2
9
- version: 0.4.2
8
+ - 3
9
+ version: 0.4.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dhruv Bansal
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-02-13 00:00:00 -06:00
17
+ date: 2012-02-14 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -102,6 +102,7 @@ files:
102
102
  - lib/rubix.rb
103
103
  - lib/rubix/models/template.rb
104
104
  - lib/rubix/models/trigger.rb
105
+ - lib/rubix/models/media_type.rb
105
106
  - lib/rubix/models/user_macro.rb
106
107
  - lib/rubix/models/item.rb
107
108
  - lib/rubix/models/host.rb
@@ -144,6 +145,7 @@ files:
144
145
  - spec/rubix/sender_spec.rb
145
146
  - spec/rubix/connection_spec.rb
146
147
  - spec/requests/time_series_request_spec.rb
148
+ - spec/requests/media_type_request_spec.rb
147
149
  - spec/requests/item_request_spec.rb
148
150
  - spec/requests/host_group_request_spec.rb
149
151
  - spec/requests/user_macro_request_spec.rb