rubix 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rubix/models/item.rb +28 -34
- data/spec/requests/item_request_spec.rb +4 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/lib/rubix/models/item.rb
CHANGED
@@ -8,8 +8,7 @@ module Rubix
|
|
8
8
|
|
9
9
|
# The numeric codes for the various item types.
|
10
10
|
#
|
11
|
-
# Items without a type will be set to '
|
12
|
-
# easily written to manually.
|
11
|
+
# Items without a type will be set to 'zabbix'.
|
13
12
|
TYPE_CODES = {
|
14
13
|
:zabbix => 0,
|
15
14
|
:snmpv1 => 1,
|
@@ -81,21 +80,22 @@ module Rubix
|
|
81
80
|
self::VALUE_CODES[value_type_from_value(value)]
|
82
81
|
end
|
83
82
|
|
84
|
-
attr_accessor :key, :description, :units
|
85
|
-
attr_writer :type, :value_type
|
83
|
+
attr_accessor :key, :description, :units, :multiply_by, :data_type, :history, :trends, :status, :frequency
|
84
|
+
attr_writer :type, :value_type
|
86
85
|
|
87
86
|
def initialize properties={}
|
88
87
|
super(properties)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
self.value_type
|
95
|
-
self.data_type
|
96
|
-
self.history
|
97
|
-
self.trends
|
98
|
-
self.status
|
88
|
+
self.key = properties[:key]
|
89
|
+
self.description = properties[:description]
|
90
|
+
self.type = properties[:type]
|
91
|
+
self.units = properties[:units]
|
92
|
+
self.multiply_by = properties[:multiply_by]
|
93
|
+
self.value_type = properties[:value_type]
|
94
|
+
self.data_type = properties[:data_type]
|
95
|
+
self.history = properties[:history]
|
96
|
+
self.trends = properties[:trends]
|
97
|
+
self.status = properties[:status]
|
98
|
+
self.frequency = properties[:frequency]
|
99
99
|
|
100
100
|
self.host = properties[:host]
|
101
101
|
self.host_id = properties[:host_id]
|
@@ -120,21 +120,8 @@ module Rubix
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def type
|
123
|
-
@type ||= :
|
124
|
-
end
|
125
|
-
|
126
|
-
def history
|
127
|
-
@history ||= 90
|
128
|
-
end
|
129
|
-
|
130
|
-
def trends
|
131
|
-
@trends ||= 365
|
132
|
-
end
|
133
|
-
|
134
|
-
def status
|
135
|
-
@status ||= :active
|
123
|
+
@type ||= :zabbix
|
136
124
|
end
|
137
|
-
|
138
125
|
|
139
126
|
#
|
140
127
|
# == Associations ==
|
@@ -155,13 +142,18 @@ module Rubix
|
|
155
142
|
:type => self.class::TYPE_CODES[type],
|
156
143
|
:key_ => key,
|
157
144
|
:value_type => self.class::VALUE_CODES[value_type],
|
158
|
-
:data_type => self.class::DATA_CODES[data_type],
|
159
|
-
:history => history,
|
160
|
-
:trends => trends,
|
161
|
-
:status => self.class::STATUS_CODES[status],
|
162
145
|
}.tap do |p|
|
163
146
|
p[:applications] = application_ids if application_ids
|
164
|
-
p[:units] = units
|
147
|
+
p[:units] = units if units
|
148
|
+
p[:data_type] = self.class::DATA_CODES[data_type] if data_type
|
149
|
+
p[:history] = history.to_i if history
|
150
|
+
p[:trends] = trends.to_i if trends
|
151
|
+
p[:status] = self.class::STATUS_CODES[status] if status
|
152
|
+
p[:delay] = frequency if frequency
|
153
|
+
if multiply_by && multiply_by.to_f != 0.0
|
154
|
+
p[:multiplier] = 1
|
155
|
+
p[:formula] = multiply_by.to_f
|
156
|
+
end
|
165
157
|
end
|
166
158
|
end
|
167
159
|
|
@@ -194,7 +186,9 @@ module Rubix
|
|
194
186
|
:status => STATUS_NAMES[item['status'].to_i],
|
195
187
|
:application_ids => (item['applications'] || []).map { |app| app['applicationid'].to_i },
|
196
188
|
:key => item['key_'],
|
197
|
-
:units => item['units']
|
189
|
+
:units => item['units'],
|
190
|
+
:frequency => item['delay'].to_i,
|
191
|
+
:multiply_by => ((item['multiplier'].to_i == 1 && item['formula'].to_f != 0.0) ? item['formula'].to_f : nil)
|
198
192
|
})
|
199
193
|
end
|
200
194
|
|
@@ -45,6 +45,8 @@ describe "Items" do
|
|
45
45
|
@item.history = 91
|
46
46
|
@item.trends = 400
|
47
47
|
@item.status = :disabled
|
48
|
+
@item.frequency = 31
|
49
|
+
@item.multiply_by = 0.1
|
48
50
|
@item.host_id = @host_2.id
|
49
51
|
@item.units = 'MB'
|
50
52
|
@item.applications = [@app_2]
|
@@ -60,6 +62,8 @@ describe "Items" do
|
|
60
62
|
new_item.trends.should == 400
|
61
63
|
new_item.status.should == :disabled
|
62
64
|
new_item.type.should == :external
|
65
|
+
new_item.frequency.should == 31
|
66
|
+
new_item.multiply_by.should == 0.1
|
63
67
|
new_item.host.name.should == @host_2.name
|
64
68
|
new_item.units.should == 'MB'
|
65
69
|
new_item.applications.map(&:name).should include(@app_2.name)
|