Class: Rubix::Action
Constant Summary
collapse
- MESSAGE_SUBJECT =
The default subject for messages.
"{TRIGGER.NAME}: {TRIGGER.STATUS}"
- MESSAGE_BODY =
The default body for messages.
"{TRIGGER.NAME}: {TRIGGER.STATUS}\nLast value: {ITEM.LASTVALUE}\n\n{TRIGGER.URL}"
Instance Attribute Summary
Attributes inherited from Model
#id, #properties
Class Method Summary
collapse
Instance Method Summary
collapse
#conditions, #conditions=, included
Methods inherited from Model
#after_create, all, all_params, all_request, #before_destroy, #before_update, #create, #create_request, #destroy, #destroy_params, #destroy_request, each, find, find_or_create, find_request, id_field, #id_field, list, #new_record?, properties, request, #request, #resource_name, resource_name, #save, #to_hash, #update, #update_params, #update_request, web_request, zabbix_attr, zabbix_define, zabbix_name
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ Action
Returns a new instance of Action.
32
33
34
35
36
37
|
# File 'lib/rubix/models/action.rb', line 32
def initialize properties={}
super(properties)
self.operations = (properties[:operations] || [])
self.conditions = (properties[:conditions] || [])
end
|
Class Method Details
.build(action) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/rubix/models/action.rb', line 97
def self.build action
new({
:id => action[id_field].to_i,
:name => action['name'],
:event_source => self::EVENT_SOURCE_NAMES[action['eventsource'].to_i],
:condition_operator => Condition::JOIN_NAMES[action['evaltype'].to_i],
:enabled => (action['status'].to_i == 0),
:escalation_time => action['esc_period'].to_i,
:message_subject => action['def_shortdata'],
:message_body => action['def_longdata'],
:send_recovery_message => (action['recovery_msg'].to_i == 1),
:recovery_message_subject => action['r_shortdata'],
:recovery_message_body => action['r_longdata'],
:conditions => (action['conditions'] || []).map { |c| Condition.build(c) },
:operations => (action['operations'] || []).map { |o| Operation.build(o) }
})
end
|
.find_params(options = {}) ⇒ Object
89
90
91
|
# File 'lib/rubix/models/action.rb', line 89
def self.find_params options={}
get_params.merge(:filter => {id_field => options[:id], :name => options[:name]})
end
|
.get_params ⇒ Object
93
94
95
|
# File 'lib/rubix/models/action.rb', line 93
def self.get_params
super().merge({:select_conditions => :refer, :select_operations => :refer})
end
|
Instance Method Details
#create_params ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rubix/models/action.rb', line 71
def create_params
{
:name => name,
:eventsource => self.class::EVENT_SOURCE_CODES[event_source],
:evaltype => Condition::JOIN_CODES[condition_operator],
:status => (enabled ? 0 : 1),
:esc_period => escalation_time,
:def_shortdata => message_subject,
:def_longdata => message_body,
:recovery_msg => (send_recovery_message ? 1 : 0),
:r_shortdata => recovery_message_subject,
:r_longdata => recovery_message_body
}.tap do |cp|
cp[:conditions] = conditions.map(&:to_hash) unless conditions.empty?
cp[:operations] = operations.map(&:to_hash) unless operations.empty?
end
end
|
#operations ⇒ Object
45
46
47
|
# File 'lib/rubix/models/action.rb', line 45
def operations
@operations ||= []
end
|
#operations=(os) ⇒ Object
49
50
51
52
53
|
# File 'lib/rubix/models/action.rb', line 49
def operations= os
@operations = os.map do |o|
o.kind_of?(Operation) ? o : Operation.new(o)
end
end
|
#validate ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/rubix/models/action.rb', line 58
def validate
super()
raise ValidationError.new("An action must have at least one operation defined.") if operations.empty?
operations.each do |operation|
return false unless operation.validate
end
true
end
|