rubix 0.1.1 → 0.1.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.1.1
1
+ 0.1.2
@@ -16,7 +16,6 @@ module Rubix
16
16
  end
17
17
 
18
18
  def item_id= iid
19
- puts "I AM TRYING TO SET ITEM_ID=#{iid}"
20
19
  return unless iid
21
20
  @item_id = iid
22
21
  end
@@ -12,8 +12,21 @@ module Rubix
12
12
 
13
13
  # The default port.
14
14
  DEFAULT_PORT = 10050
15
+
16
+ # The numeric codes for the various status types.
17
+ STATUS_CODES = {
18
+ :monitored => 0,
19
+ :not_monitored => 1,
20
+ :unreachable => 2,
21
+ :template => 3,
22
+ :deleted => 4,
23
+ :proxy_active => 5,
24
+ :proxy_passive => 6
25
+ }.freeze
26
+ STATUS_NAMES = STATUS_CODES.invert.freeze
15
27
 
16
- attr_accessor :name, :ip, :port, :profile, :status
28
+ attr_accessor :name, :ip, :port, :profile, :dns, :status
29
+ attr_writer :use_ip, :monitored
17
30
 
18
31
  def initialize properties={}
19
32
  super(properties)
@@ -21,6 +34,9 @@ module Rubix
21
34
  @ip = properties[:ip]
22
35
  @port = properties[:port]
23
36
  @profile = properties[:profile]
37
+ @monitored = properties[:monitored]
38
+ @dns = properties[:dns]
39
+ @use_ip = properties[:use_ip]
24
40
  @status = properties[:status]
25
41
 
26
42
  self.host_group_ids = properties[:host_group_ids]
@@ -33,6 +49,16 @@ module Rubix
33
49
  self.user_macros = properties[:user_macros]
34
50
  end
35
51
 
52
+ def use_ip
53
+ return @use_ip if (!@use_ip.nil?)
54
+ @use_ip = true
55
+ end
56
+
57
+ def monitored
58
+ return @monitored if (!@monitored.nil?)
59
+ @monitored = true
60
+ end
61
+
36
62
  #
37
63
  # == Associations ==
38
64
  #
@@ -62,12 +88,17 @@ module Rubix
62
88
  :macros => user_macro_params
63
89
  }.tap do |hp|
64
90
  hp[:profile] = profile if profile
65
- hp[:status] = status if status
91
+ hp[:status] = (monitored ? 0 : 1) unless monitored.nil?
66
92
 
67
- if ip
68
- hp[:ip] = ip
69
- hp[:useip] = true
70
- hp[:port] = port || self.class::DEFAULT_PORT
93
+ case
94
+ when use_ip && (!ip.nil?) && (!ip.empty?)
95
+ hp[:useip] = 1
96
+ hp[:ip] = ip
97
+ hp[:port] = port || self.class::DEFAULT_PORT
98
+ when (!dns.nil?) && (!dns.empty?)
99
+ hp[:useip] = 0
100
+ hp[:dns] = dns
101
+ hp[:port] = port || self.class::DEFAULT_PORT
71
102
  else
72
103
  hp[:ip] = self.class::BLANK_IP
73
104
  end
@@ -110,7 +141,16 @@ module Rubix
110
141
  :template_ids => host['parentTemplates'].map { |template| (template['templateid'] || template[id_field]).to_i },
111
142
  :user_macros => host['macros'].map { |um| UserMacro.new(:host_id => um[id_field].to_i, :id => um['hostmacroid'], :value => um['value'], :macro => um['macro']) },
112
143
  :profile => host['profile'],
113
- :port => host['port']
144
+ :port => host['port'],
145
+ :ip => host['ip'],
146
+ :dns => host['dns'],
147
+ :use_ip => (host['useip'].to_i == '1'),
148
+
149
+ # If the status is '1' then this is an unmonitored host.
150
+ # Otherwise it's either '0' for monitored and ok or
151
+ # something else for monitored and *not* ok.
152
+ :monitored => (host['status'].to_i == 1 ? false : true),
153
+ :status => self::STATUS_NAMES[host['status'].to_i]
114
154
  })
115
155
  end
116
156
 
@@ -16,7 +16,6 @@ module Rubix
16
16
 
17
17
  self.item = properties[:item]
18
18
  self.item_id = properties[:item_id]
19
- puts "MY ITEM ID IS #{self.item_id}"
20
19
  end
21
20
 
22
21
  def self.zabbix_name
@@ -21,6 +21,8 @@ describe "Hosts" do
21
21
  it "can be created" do
22
22
  host = Rubix::Host.new(:name => 'rubix_spec_host_1', :host_groups => [@host_group_1])
23
23
  host.save.should be_true
24
+ host.monitored.should be_true
25
+ host.use_ip.should be_true
24
26
  end
25
27
  end
26
28
 
@@ -50,6 +52,16 @@ describe "Hosts" do
50
52
  new_host.host_groups.map(&:name).should include('rubix_spec_host_group_1', 'rubix_spec_host_group_2')
51
53
  end
52
54
 
55
+ it "can change its monitoring status" do
56
+ @host.monitored = false
57
+ @host.save
58
+
59
+ new_host = Rubix::Host.find(:name => 'rubix_spec_host_1')
60
+ new_host.should_not be_nil
61
+ new_host.monitored.should be_false
62
+ new_host.status.should == :not_monitored
63
+ end
64
+
53
65
  it "can change its templates" do
54
66
  @host.templates = [@template_1, @template_2]
55
67
  @host.save
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
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-01 00:00:00 -06:00
17
+ date: 2012-02-02 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency