rubix 0.4.3 → 0.5.0
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 +1 -1
- data/bin/zabbix_api +45 -27
- data/lib/rubix.rb +17 -0
- data/lib/rubix/associations.rb +7 -1
- data/lib/rubix/associations/belongs_to_action.rb +31 -0
- data/lib/rubix/associations/belongs_to_media_type.rb +33 -0
- data/lib/rubix/associations/belongs_to_user.rb +33 -0
- data/lib/rubix/associations/belongs_to_user_group.rb +32 -0
- data/lib/rubix/associations/has_many_conditions.rb +23 -0
- data/lib/rubix/associations/has_many_user_groups.rb +32 -0
- data/lib/rubix/associations/has_many_users.rb +32 -0
- data/lib/rubix/models.rb +17 -10
- data/lib/rubix/models/action.rb +117 -0
- data/lib/rubix/models/application.rb +1 -3
- data/lib/rubix/models/condition.rb +99 -0
- data/lib/rubix/models/host.rb +9 -11
- data/lib/rubix/models/host_group.rb +1 -4
- data/lib/rubix/models/item.rb +12 -27
- data/lib/rubix/models/media_type.rb +19 -21
- data/lib/rubix/models/medium.rb +86 -0
- data/lib/rubix/models/model.rb +53 -1
- data/lib/rubix/models/operation.rb +134 -0
- data/lib/rubix/models/script.rb +49 -0
- data/lib/rubix/models/template.rb +2 -2
- data/lib/rubix/models/trigger.rb +8 -9
- data/lib/rubix/models/user.rb +145 -0
- data/lib/rubix/models/user_group.rb +94 -0
- data/lib/rubix/models/user_macro.rb +10 -20
- data/spec/requests/action_request_spec.rb +45 -0
- data/spec/requests/connection_request_spec.rb +3 -3
- data/spec/requests/media_type_request_spec.rb +8 -8
- data/spec/requests/script_request_spec.rb +54 -0
- data/spec/requests/user_group_request_spec.rb +97 -0
- data/spec/requests/user_request_spec.rb +84 -0
- data/spec/support/integration_helper.rb +105 -33
- data/spec/test.yml +0 -2
- metadata +22 -4
@@ -8,13 +8,11 @@ module Rubix
|
|
8
8
|
|
9
9
|
def initialize properties={}
|
10
10
|
super(properties)
|
11
|
-
@name = properties[:name]
|
12
|
-
|
13
11
|
self.host_id = properties[:host_id]
|
14
12
|
self.host = properties[:host]
|
15
13
|
end
|
16
14
|
|
17
|
-
|
15
|
+
zabbix_attr :name, :required => true
|
18
16
|
|
19
17
|
#
|
20
18
|
# == Associations ==
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module Rubix
|
2
|
+
|
3
|
+
class Condition < Model
|
4
|
+
|
5
|
+
# Numeric codes for the operator to use to join conditions for
|
6
|
+
# this action. Default is 'and_or'.
|
7
|
+
JOIN_CODES = {
|
8
|
+
:and_or => 0,
|
9
|
+
:and => 1,
|
10
|
+
:or => 2
|
11
|
+
}.freeze
|
12
|
+
JOIN_NAMES = JOIN_CODES.invert.freeze
|
13
|
+
|
14
|
+
# 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
|
41
|
+
|
42
|
+
# Numeric codes for the operator used to compare a condition's
|
43
|
+
# type to its value.
|
44
|
+
OPERATOR_CODES = {
|
45
|
+
:equal => 0,
|
46
|
+
:not_equal => 1,
|
47
|
+
:like => 2,
|
48
|
+
:not_like => 3,
|
49
|
+
:in => 4,
|
50
|
+
:gte => 5,
|
51
|
+
:lte => 6,
|
52
|
+
:not_in => 7,
|
53
|
+
}.freeze
|
54
|
+
OPERATOR_NAMES = OPERATOR_CODES.invert.freeze
|
55
|
+
|
56
|
+
#
|
57
|
+
# == Properties & Finding ==
|
58
|
+
#
|
59
|
+
|
60
|
+
zabbix_attr :type, :required => true
|
61
|
+
zabbix_attr :operator, :required => true, :default => :equal
|
62
|
+
zabbix_attr :value, :required => true
|
63
|
+
|
64
|
+
def initialize properties=nil
|
65
|
+
if properties.is_a?(Array)
|
66
|
+
raise ArgumentError.new("Must provide a condition type, operator, and value when initializing a condition with an array.") unless properties.size == 3
|
67
|
+
super({
|
68
|
+
:type => properties[0],
|
69
|
+
:operator => properties[1],
|
70
|
+
:value => properties[2]
|
71
|
+
})
|
72
|
+
else
|
73
|
+
super(properties || {})
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# == Requests ==
|
79
|
+
#
|
80
|
+
|
81
|
+
def create_params
|
82
|
+
{
|
83
|
+
:conditiontype => self.class::TYPE_CODES[type],
|
84
|
+
:operator => self.class::OPERATOR_CODES[operator],
|
85
|
+
:value => value.to_s
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.build condition
|
90
|
+
new({
|
91
|
+
:id => condition[id_field].to_i,
|
92
|
+
:type => self::TYPE_NAMES[condition['conditiontype'].to_i],
|
93
|
+
:operator => self::OPERATOR_NAMES[condition['operator'].to_i],
|
94
|
+
:value => condition['value'].to_s
|
95
|
+
})
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
data/lib/rubix/models/host.rb
CHANGED
@@ -24,20 +24,18 @@ module Rubix
|
|
24
24
|
:proxy_passive => 6
|
25
25
|
}.freeze
|
26
26
|
STATUS_NAMES = STATUS_CODES.invert.freeze
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
|
28
|
+
zabbix_attr :name
|
29
|
+
zabbix_attr :ip
|
30
|
+
zabbix_attr :port
|
31
|
+
zabbix_attr :profile
|
32
|
+
zabbix_attr :dns
|
33
|
+
zabbix_attr :status
|
34
|
+
zabbix_attr :use_ip, :default => true
|
35
|
+
zabbix_attr :monitored, :default => true
|
30
36
|
|
31
37
|
def initialize properties={}
|
32
38
|
super(properties)
|
33
|
-
@name = properties[:name]
|
34
|
-
@ip = properties[:ip]
|
35
|
-
@port = properties[:port]
|
36
|
-
@profile = properties[:profile]
|
37
|
-
@monitored = properties[:monitored]
|
38
|
-
@dns = properties[:dns]
|
39
|
-
@use_ip = properties[:use_ip]
|
40
|
-
@status = properties[:status]
|
41
39
|
|
42
40
|
self.host_group_ids = properties[:host_group_ids]
|
43
41
|
self.host_groups = properties[:host_groups]
|
@@ -8,14 +8,11 @@ module Rubix
|
|
8
8
|
|
9
9
|
def initialize properties={}
|
10
10
|
super(properties)
|
11
|
-
@name = properties[:name]
|
12
|
-
|
13
11
|
self.host_ids = properties[:host_ids]
|
14
12
|
self.hosts = properties[:hosts]
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
zabbix_attr :name, :required => true
|
19
16
|
|
20
17
|
def self.id_field
|
21
18
|
'groupid'
|
data/lib/rubix/models/item.rb
CHANGED
@@ -79,24 +79,21 @@ module Rubix
|
|
79
79
|
def self.value_code_from_value value
|
80
80
|
self::VALUE_CODES[value_type_from_value(value)]
|
81
81
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
|
83
|
+
zabbix_attr :type, :default => :zabbix
|
84
|
+
zabbix_attr :value_type, :default => :character
|
85
|
+
zabbix_attr :data_type, :default => :decimal
|
86
|
+
zabbix_attr :key, :required => true
|
87
|
+
zabbix_attr :description
|
88
|
+
zabbix_attr :units
|
89
|
+
zabbix_attr :multiply_by
|
90
|
+
zabbix_attr :history
|
91
|
+
zabbix_attr :trends
|
92
|
+
zabbix_attr :status
|
93
|
+
zabbix_attr :frequency
|
85
94
|
|
86
95
|
def initialize properties={}
|
87
96
|
super(properties)
|
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
|
-
|
100
97
|
self.host = properties[:host]
|
101
98
|
self.host_id = properties[:host_id]
|
102
99
|
|
@@ -111,18 +108,6 @@ module Rubix
|
|
111
108
|
"#{self.class.resource_name} #{self.key || self.id}"
|
112
109
|
end
|
113
110
|
|
114
|
-
def value_type
|
115
|
-
@value_type ||= :character
|
116
|
-
end
|
117
|
-
|
118
|
-
def data_type
|
119
|
-
@data_type ||= :decimal
|
120
|
-
end
|
121
|
-
|
122
|
-
def type
|
123
|
-
@type ||= :zabbix
|
124
|
-
end
|
125
|
-
|
126
111
|
#
|
127
112
|
# == Associations ==
|
128
113
|
#
|
@@ -18,25 +18,23 @@ module Rubix
|
|
18
18
|
# == Properties & Finding ==
|
19
19
|
#
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
attr_writer :type
|
24
|
-
def type
|
25
|
-
@type ||= :script
|
26
|
-
end
|
21
|
+
zabbix_attr :type, :default => :script, :required => true
|
22
|
+
zabbix_attr :name
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
# email
|
25
|
+
zabbix_attr :server
|
26
|
+
zabbix_attr :helo
|
27
|
+
zabbix_attr :email
|
28
|
+
|
29
|
+
# script
|
30
|
+
zabbix_attr :path
|
31
|
+
|
32
|
+
# sms
|
33
|
+
zabbix_attr :modem
|
34
|
+
|
35
|
+
# jabber
|
36
|
+
zabbix_attr :username
|
37
|
+
zabbix_attr :password
|
40
38
|
|
41
39
|
#
|
42
40
|
# == Requests ==
|
@@ -44,7 +42,7 @@ module Rubix
|
|
44
42
|
|
45
43
|
def create_params
|
46
44
|
{
|
47
|
-
:description =>
|
45
|
+
:description => name,
|
48
46
|
:type => TYPE_CODES[type]
|
49
47
|
}.tap do |p|
|
50
48
|
case type
|
@@ -64,14 +62,14 @@ module Rubix
|
|
64
62
|
end
|
65
63
|
|
66
64
|
def self.find_params options={}
|
67
|
-
get_params.merge(:filter => {id_field => options[:id], :description => options[:
|
65
|
+
get_params.merge(:filter => {id_field => options[:id], :description => options[:name]})
|
68
66
|
end
|
69
67
|
|
70
68
|
def self.build media_type
|
71
69
|
new({
|
72
70
|
:id => media_type[id_field].to_i,
|
73
71
|
:type => self::TYPE_NAMES[media_type['type'].to_i],
|
74
|
-
:
|
72
|
+
:name => media_type['description'],
|
75
73
|
:server => media_type['smtp_server'],
|
76
74
|
:helo => media_type['smtp_helo'],
|
77
75
|
:email => media_type['smtp_email'],
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Rubix
|
2
|
+
|
3
|
+
class Medium < Model
|
4
|
+
|
5
|
+
# Numeric codes that correspond to accepting triggers that are any
|
6
|
+
# priority less than or equal to that listed. More fine grained
|
7
|
+
# control is possible, i.e. - accepting :not_classified and
|
8
|
+
# :wanring triggers but rejejcting :information triggers. In the
|
9
|
+
# interests of simplicity, we avoid exposing that degree of
|
10
|
+
# freedom here.
|
11
|
+
PRIORITY_CODES = {
|
12
|
+
:none => 0,
|
13
|
+
:not_classified => 1,
|
14
|
+
:information => 3,
|
15
|
+
:warning => 7,
|
16
|
+
:average => 15,
|
17
|
+
:high => 31,
|
18
|
+
:disaster => 63,
|
19
|
+
:all => 63,
|
20
|
+
nil => 63
|
21
|
+
}.freeze
|
22
|
+
PRIORITY_NAMES = PRIORITY_CODES.invert.freeze
|
23
|
+
|
24
|
+
#
|
25
|
+
# == Properties & Finding ==
|
26
|
+
#
|
27
|
+
|
28
|
+
zabbix_attr :address, :required => true
|
29
|
+
zabbix_attr :priority, :required => true, :default => :all
|
30
|
+
zabbix_attr :timeframe, :required => true, :default => '1-7,00:00-23:59'
|
31
|
+
zabbix_attr :enabled, :required => true, :default => true
|
32
|
+
|
33
|
+
attr_writer :severity
|
34
|
+
def severity
|
35
|
+
@severity ||= self.class::PRIORITY_CODES[priority]
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.id_field
|
39
|
+
'mediaid'
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize properties={}
|
43
|
+
super(properties)
|
44
|
+
self.severity = properties[:severity].to_i if properties[:severity]
|
45
|
+
self.user = properties[:user]
|
46
|
+
self.user_id = properties[:user_id]
|
47
|
+
self.media_type = properties[:media_type]
|
48
|
+
self.media_type_id = properties[:media_type_id]
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# == Associations ==
|
53
|
+
#
|
54
|
+
|
55
|
+
include Associations::BelongsToUser
|
56
|
+
include Associations::BelongsToMediaType
|
57
|
+
|
58
|
+
#
|
59
|
+
# == Requests ==
|
60
|
+
#
|
61
|
+
|
62
|
+
def create_params
|
63
|
+
{
|
64
|
+
:mediatypeid => media_type_id,
|
65
|
+
:userid => user_id,
|
66
|
+
:sendto => address,
|
67
|
+
:active => (enabled ? 0 : 1),
|
68
|
+
:severity => (severity || self.class::PRIORITY_CODES[priority]),
|
69
|
+
:period => timeframe
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.build medium
|
74
|
+
new({
|
75
|
+
:id => medium[id_field].to_i,
|
76
|
+
:address => medium['sendto'],
|
77
|
+
:severity => medium['severity'].to_i,
|
78
|
+
:priority => self::PRIORITY_NAMES[medium['severity'].to_i],
|
79
|
+
:timeframe => medium['period'],
|
80
|
+
:enabled => (medium['active'].to_i == 0),
|
81
|
+
:user_id => medium['userid'].to_i,
|
82
|
+
:media_type_id => medium['mediatypeid'].to_i
|
83
|
+
})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/rubix/models/model.rb
CHANGED
@@ -70,6 +70,9 @@ module Rubix
|
|
70
70
|
# @option properties [Fixnum] id the ID of the resource in Zabbix (typically blank for a new resource)
|
71
71
|
def initialize properties={}
|
72
72
|
@properties = properties
|
73
|
+
self.class.properties.keys.each do |property|
|
74
|
+
self.send("#{property}=", properties[property])
|
75
|
+
end
|
73
76
|
@id = properties[:id]
|
74
77
|
end
|
75
78
|
|
@@ -126,9 +129,19 @@ module Rubix
|
|
126
129
|
#
|
127
130
|
# @return [true, false]
|
128
131
|
def validate
|
132
|
+
self.class.properties.each_pair do |property, options|
|
133
|
+
raise ValidationError.new("A #{self.class.resource_name} must have a #{property}") if options[:required] && (self.send(property).nil? || self.send(property).empty?)
|
134
|
+
end
|
129
135
|
true
|
130
136
|
end
|
131
137
|
|
138
|
+
# Return this object as a Hash.
|
139
|
+
#
|
140
|
+
# @return [Hash]
|
141
|
+
def to_hash
|
142
|
+
update_params
|
143
|
+
end
|
144
|
+
|
132
145
|
#
|
133
146
|
# == Create ==
|
134
147
|
#
|
@@ -161,6 +174,12 @@ module Rubix
|
|
161
174
|
error("Error creating Zabbix #{resource_name}: #{response.error_message}")
|
162
175
|
return false
|
163
176
|
end
|
177
|
+
after_create
|
178
|
+
end
|
179
|
+
|
180
|
+
# Run this hook after creating a new resource.
|
181
|
+
def after_create
|
182
|
+
true
|
164
183
|
end
|
165
184
|
|
166
185
|
#
|
@@ -171,7 +190,11 @@ module Rubix
|
|
171
190
|
#
|
172
191
|
# @return [Hash]
|
173
192
|
def update_params
|
174
|
-
|
193
|
+
if id
|
194
|
+
create_params.merge({id_field => id})
|
195
|
+
else
|
196
|
+
create_params
|
197
|
+
end
|
175
198
|
end
|
176
199
|
|
177
200
|
# Send a request to update this resource.
|
@@ -372,6 +395,10 @@ module Rubix
|
|
372
395
|
end
|
373
396
|
end
|
374
397
|
|
398
|
+
#
|
399
|
+
# == List ==
|
400
|
+
#
|
401
|
+
|
375
402
|
def self.list ids
|
376
403
|
return [] if ids.nil? || ids.empty?
|
377
404
|
response = request("#{zabbix_name}.get", get_params.merge((id_field + 's') => ids))
|
@@ -386,6 +413,31 @@ module Rubix
|
|
386
413
|
error("Error listing Zabbix #{resource_name}s: #{response.error_message}")
|
387
414
|
end
|
388
415
|
end
|
416
|
+
|
417
|
+
#
|
418
|
+
# == Helpers ==
|
419
|
+
#
|
420
|
+
|
421
|
+
def self.properties
|
422
|
+
@properties ||= {}
|
423
|
+
end
|
424
|
+
|
425
|
+
def self.zabbix_attr name, options={}
|
426
|
+
name = name.to_s.to_sym
|
427
|
+
@properties ||= {}
|
428
|
+
@properties[name] = options
|
429
|
+
|
430
|
+
if options[:default].nil?
|
431
|
+
attr_accessor name
|
432
|
+
else
|
433
|
+
attr_writer name
|
434
|
+
define_method name do
|
435
|
+
current_value = instance_variable_get("@#{name}")
|
436
|
+
return current_value unless current_value.nil?
|
437
|
+
instance_variable_set("@#{name}", options[:default])
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
389
441
|
|
390
442
|
end
|
391
443
|
end
|