Class: Rubix::Action
- Includes:
- Rubix::Associations::HasManyConditions
- Defined in:
- lib/rubix/models/action.rb
Constant Summary collapse
- EVENT_SOURCE_CODES =
Numeric codes for the event source. Default will be ‘triggers’.
{ :triggers => 0, :discovery => 1, :auto_registration => 2 }.freeze
- EVENT_SOURCE_NAMES =
EVENT_SOURCE_CODES.invert.freeze
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#create_params ⇒ Object
Requests ==.
-
#initialize(properties = {}) ⇒ Action
constructor
A new instance of Action.
- #operations ⇒ Object
- #operations=(os) ⇒ Object
-
#validate ⇒ Object
Validations ==.
Methods included from Rubix::Associations::HasManyConditions
#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_name
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ Action
Returns a new instance of Action.
33 34 35 36 37 38 |
# File 'lib/rubix/models/action.rb', line 33 def initialize properties={} super(properties) self.operations = (properties[:operations] || []) self.conditions = (properties[:conditions] || []) end |
Class Method Details
.build(action) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rubix/models/action.rb', line 98 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
90 91 92 |
# File 'lib/rubix/models/action.rb', line 90 def self.find_params ={} get_params.merge(:filter => {id_field => [:id], :name => [:name]}) end |
.get_params ⇒ Object
94 95 96 |
# File 'lib/rubix/models/action.rb', line 94 def self.get_params super().merge({:select_conditions => :refer, :select_operations => :refer}) end |
Instance Method Details
#create_params ⇒ Object
Requests ==
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rubix/models/action.rb', line 72 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 => , :def_longdata => , :recovery_msg => ( ? 1 : 0), :r_shortdata => , :r_longdata => }.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
46 47 48 |
# File 'lib/rubix/models/action.rb', line 46 def operations @operations ||= [] end |
#operations=(os) ⇒ Object
50 51 52 53 54 |
# File 'lib/rubix/models/action.rb', line 50 def operations= os @operations = os.map do |o| o.kind_of?(Operation) ? o : Operation.new(o) end end |
#validate ⇒ Object
Validations ==
59 60 61 62 63 64 65 66 |
# File 'lib/rubix/models/action.rb', line 59 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 |