Class: Rubix::Application

Inherits:
Model
  • Object
show all
Includes:
Rubix::Associations::BelongsToHost
Defined in:
lib/rubix/models/application.rb

Instance Attribute Summary

Attributes inherited from Model

#id, #properties

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rubix::Associations::BelongsToHost

#host, #host=, #host_id, #host_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_request, get_params, id_field, #id_field, list, #new_record?, properties, request, #request, resource_name, #resource_name, #save, #to_hash, #update, #update_request, #validate, web_request, zabbix_attr, zabbix_define, zabbix_name

Methods included from Logs

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(properties = {}) ⇒ Application

Properties & Finding ==


9
10
11
12
13
# File 'lib/rubix/models/application.rb', line 9

def initialize properties={}
  super(properties)
  self.host_id = properties[:host_id]
  self.host    = properties[:host]
end

Class Method Details

.build(app) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rubix/models/application.rb', line 45

def self.build app
  params = {
    :id   => app[id_field].to_i,
    :name => app['name']
  }

  # use the host id if available, else use the template id
  if app['hosts'] && app['hosts'].first && app['hosts'].first['hostid']
    params[:host_id] = app['hosts'].first['hostid'].to_i
  else
    params[:host_id] = app['templateid']
  end
  new(params)
end

.find_params(options = {}) ⇒ Object


35
36
37
38
39
40
41
42
43
# File 'lib/rubix/models/application.rb', line 35

def self.find_params options={}
  super().merge({
                  :hostids => [options[:host_id]],
                  :filter => {
                    :name   => options[:name],
                    id_field => options[:id]
                  }
                })
end

Instance Method Details

#create_paramsObject

Requests ==


27
28
29
# File 'lib/rubix/models/application.rb', line 27

def create_params
  {:name => name, :hostid => host_id}
end

#update_paramsObject


31
32
33
# File 'lib/rubix/models/application.rb', line 31

def update_params
  { id_field => id, :name => name, :hosts => {:hostid => host_id}}
end