Class: Rubix::Medium

Inherits:
Model
  • Object
show all
Includes:
Associations::BelongsToMediaType, Associations::BelongsToUser
Defined in:
lib/rubix/models/medium.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#id, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Associations::BelongsToMediaType

#media_type, #media_type=, #media_type_id, #media_type_id=

Methods included from Associations::BelongsToUser

#user, #user=, #user_id, #user_id=

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, 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 = {}) ⇒ Medium

Returns a new instance of Medium


41
42
43
44
45
46
47
48
# File 'lib/rubix/models/medium.rb', line 41

def initialize properties={}
  super(properties)
  self.severity      = properties[:severity].to_i if properties[:severity]
  self.user          = properties[:user]
  self.user_id       = properties[:user_id]
  self.media_type    = properties[:media_type]
  self.media_type_id = properties[:media_type_id]
end

Instance Attribute Details

#severityObject


33
34
35
# File 'lib/rubix/models/medium.rb', line 33

def severity
  @severity ||= self.class::PRIORITY_CODES[(priority || :all)]
end

Class Method Details

.build(medium) ⇒ Object


72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rubix/models/medium.rb', line 72

def self.build medium
  new({
        :id            => medium[id_field].to_i,
        :address       => medium['sendto'],
        :severity      => medium['severity'].to_i,
        :priority      => self::PRIORITY_NAMES[medium['severity'].to_i],
        :timeframe     => medium['period'],
        :enabled       => (medium['active'].to_i == 0),
        :user_id       => medium['userid'].to_i,
        :media_type_id => medium['mediatypeid'].to_i
      })
end

.id_fieldObject


37
38
39
# File 'lib/rubix/models/medium.rb', line 37

def self.id_field
  'mediaid'
end

Instance Method Details

#create_paramsObject

Requests ==


61
62
63
64
65
66
67
68
69
70
# File 'lib/rubix/models/medium.rb', line 61

def create_params
  {
    :mediatypeid => media_type_id,
    :userid      => user_id,
    :sendto      => address,
    :active      => (enabled ? 0 : 1),
    :severity    => (severity || self.class::PRIORITY_CODES[(priority || :all)]),
    :period      => timeframe
  }
end