Class: Rubix::UserMacro
Instance Attribute Summary collapse
Attributes inherited from Model
#id, #properties
Class Method Summary
collapse
Instance Method Summary
collapse
#host, #host=, #host_id, #host_id=
Methods inherited from Model
#before_update, #create, #destroy, find, find_or_create, #new_record?, #request, request, #resource_name, resource_name, #save, #update
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ UserMacro
Returns a new instance of UserMacro.
11
12
13
14
15
16
17
18
|
# File 'lib/rubix/models/user_macro.rb', line 11
def initialize properties={}
super(properties)
@name = properties[:name] || self.class.unmacro_name(properties[:macro])
@value = properties[:value]
self.host = properties[:host]
self.host_id = properties[:host_id]
end
|
Instance Attribute Details
#name ⇒ Object
9
10
11
|
# File 'lib/rubix/models/user_macro.rb', line 9
def name
@name
end
|
#value ⇒ Object
9
10
11
|
# File 'lib/rubix/models/user_macro.rb', line 9
def value
@value
end
|
Class Method Details
.build(macro) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/rubix/models/user_macro.rb', line 24
def self.build macro
new({
:id => macro['hostmacroid'].to_i,
:name => unmacro_name(macro['macro']),
:value => macro['value'],
:host_id => macro['hostid']
})
end
|
.find_request(options = {}) ⇒ Object
20
21
22
|
# File 'lib/rubix/models/user_macro.rb', line 20
def self.find_request options={}
request('usermacro.get', 'hostids' => [options[:host_id]], 'filter' => {'macro' => macro_name(options[:name])}, "output" => "extend")
end
|
.id_field ⇒ Object
45
46
47
|
# File 'lib/rubix/models/user_macro.rb', line 45
def self.id_field
'hostmacroid'
end
|
.macro_name(name) ⇒ Object
37
38
39
|
# File 'lib/rubix/models/user_macro.rb', line 37
def self.macro_name name
"{$#{name.upcase}}"
end
|
.unmacro_name(name) ⇒ Object
33
34
35
|
# File 'lib/rubix/models/user_macro.rb', line 33
def self.unmacro_name name
(name || '').gsub(/^\{\$/, '').gsub(/\}$/, '').upcase
end
|
Instance Method Details
#create_request ⇒ Object
67
68
69
|
# File 'lib/rubix/models/user_macro.rb', line 67
def create_request
request('usermacro.massAdd', 'macros' => [{'macro' => macro_name, 'value' => value}], 'hosts' => [{'hostid' => host_id}])
end
|
#destroy_request ⇒ Object
75
76
77
|
# File 'lib/rubix/models/user_macro.rb', line 75
def destroy_request
request('usermacro.massRemove', 'hostids' => [host_id], 'macros' => [macro_name])
end
|
#macro_name ⇒ Object
41
42
43
|
# File 'lib/rubix/models/user_macro.rb', line 41
def macro_name
self.class.macro_name(name)
end
|
#update_request ⇒ Object
71
72
73
|
# File 'lib/rubix/models/user_macro.rb', line 71
def update_request
request('usermacro.massUpdate', 'macros' => [{'macro' => macro_name, 'value' => value}], 'hosts' => [{'hostid' => host_id}])
end
|
#validate ⇒ Object
58
59
60
61
|
# File 'lib/rubix/models/user_macro.rb', line 58
def validate
raise ValidationError.new("A user macro must have both a 'name' and a 'value'") if name.nil? || name.strip.empty? || value.nil? || value.strip.empty?
true
end
|