Class: Rubix::Operation
- Includes:
- Associations::BelongsToMediaType, Associations::BelongsToUser, Associations::BelongsToUserGroup, Associations::HasManyConditions
- Defined in:
- lib/rubix/models/operation.rb
Instance Attribute Summary
Attributes inherited from Model
Class Method Summary collapse
Instance Method Summary collapse
-
#create_params ⇒ Object
Requests ==.
-
#initialize(properties = {}) ⇒ Operation
constructor
A new instance of Operation.
- #notification_object_id ⇒ Object
- #notification_object_name ⇒ Object
- #step=(s) ⇒ Object
Methods included from Associations::BelongsToMediaType
#media_type, #media_type=, #media_type_id, #media_type_id=
Methods included from Associations::BelongsToUserGroup
#user_group, #user_group=, #user_group_id, #user_group_id=
Methods included from Associations::BelongsToUser
#user, #user=, #user_id, #user_id=
Methods included from 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_params, find_request, get_params, id_field, #id_field, list, #new_record?, properties, request, #request, #resource_name, resource_name, #save, #to_hash, #update, #update_params, #update_request, #validate, web_request, zabbix_attr, zabbix_define, zabbix_name
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ Operation
Returns a new instance of Operation.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubix/models/operation.rb', line 43 def initialize properties={} super(properties) self.step = properties[:step] if properties[:step] self.user_id = properties[:user_id] self.user = properties[:user] self.user_group_id = properties[:user_group_id] self.user_group = properties[:user_group] self.conditions = (properties[:conditions] || []) self.media_type = properties[:media_type] self.media_type_id = properties[:media_type_id] end |
Class Method Details
.build(operation) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rubix/models/operation.rb', line 107 def self.build operation new({ :id => operation[id_field].to_i, :type => self::TYPE_NAMES[operation['operationtype'].to_i], :message_subject => operation['shortdata'], :message_body => operation['longdata'], :escalation_period => operation['esc_period'].to_i, :use_default_message => (operation['default_msg'].to_i == 1), :condition_operator => Condition::JOIN_NAMES[operation['evaltype'].to_i], :conditions => (operation['opconditions'] || []).map { |c| Condition.build(c) }, :start => operation['esc_step_from'].to_i, :stop => operation['esc_step_to'].to_i }).tap do |o| if self::NOTIFICATION_OBJECT_NAMES[operation['object'].to_i] == :user o.user_id = operation['objectid'] else o.user_group_id = operation['objectid'] end if (operation['opmediatypes'] || []).first o.media_type_id = (operation['opmediatypes'] || []).first['mediatypeid'].to_i end end end |
Instance Method Details
#create_params ⇒ Object
Requests ==
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rubix/models/operation.rb', line 89 def create_params { :operationtype => self.class::TYPE_CODES[type], :object => self.class::NOTIFICATION_OBJECT_CODES[notification_object_name], :objectid => notification_object_id, :shortdata => , :longdata => , :default_msg => ( ? 1 : 0), :evaltype => Condition::JOIN_CODES[condition_operator], :esc_period => escalation_time, :esc_step_from => start, :esc_step_to => stop }.tap do |cp| cp[:opconditions] = conditions.map(&:to_hash) unless conditions.empty? cp[:opmediatypes] = [{ :mediatypeid => media_type_id }] if media_type_id end end |
#notification_object_id ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/rubix/models/operation.rb', line 68 def notification_object_id if user_id || user_group_id return user_id || user_group_id else raise Error.new("An #{resource_name} must have either a user or a user group.") end end |
#notification_object_name ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/rubix/models/operation.rb', line 59 def notification_object_name case when user_id then :user when user_group_id then :user_group else raise Error.new("An #{resource_name} must have either a user or a user group.") end end |
#step=(s) ⇒ Object
38 39 40 41 |
# File 'lib/rubix/models/operation.rb', line 38 def step= s self.start = s self.stop = s end |