Class: Rubix::Trigger
- Defined in:
- lib/rubix/models/trigger.rb
Constant Summary collapse
- PRIORITY_NAMES =
Properties & Finding ==
{ :not_classified => 0, :information => 1, :warning => 2, :average => 3, :high => 4, :disaster => 5 }.freeze
- PRIORITY_CODES =
PRIORITY_NAMES.invert.freeze
- STATUS_NAMES =
{ :enabled => 0, :disabled => 1 }.freeze
- STATUS_CODES =
STATUS_NAMES.invert.freeze
Instance Attribute Summary collapse
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#description ⇒ Object
Returns the value of attribute description.
-
#expression ⇒ Object
Returns the value of attribute expression.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#status ⇒ Object
Returns the value of attribute status.
-
#url ⇒ Object
Returns the value of attribute url.
Attributes inherited from Model
Class Method Summary collapse
- .build(trigger) ⇒ Object
- .find_params(options = {}) ⇒ Object
- .get_params ⇒ Object
- .host_or_template_params_from_id(id) ⇒ Object
Instance Method Summary collapse
-
#create_params ⇒ Object
Requests ==.
-
#initialize(properties = {}) ⇒ Trigger
constructor
A new instance of Trigger.
Methods included from Associations::HasManyItems
#item_ids, #item_ids=, #items, #items=
Methods included from Associations::BelongsToTemplate
#template, #template=, #template_id, #template_id=
Methods included from Associations::BelongsToHost
#host, #host=, #host_id, #host_id=
Methods inherited from Model
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, #new_record?, request, #request, #resource_name, resource_name, #save, #update, #update_params, #update_request, #validate, zabbix_name
Methods included from Logs
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(properties = {}) ⇒ Trigger
Returns a new instance of Trigger.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rubix/models/trigger.rb', line 28 def initialize properties={} super(properties) @description = properties[:description] @url = properties[:url] @status = properties[:status] @priority = properties[:priority] @comments = properties[:comments] self.expression = properties[:expression] self.host = properties[:host] self.template = properties[:template] self.template_id = properties[:template_id] self.host_id = properties[:host_id] self.items = properties[:items] self.item_ids = properties[:item_ids] end |
Instance Attribute Details
#comments ⇒ Object
Returns the value of attribute comments.
25 26 27 |
# File 'lib/rubix/models/trigger.rb', line 25 def comments @comments end |
#description ⇒ Object
Returns the value of attribute description.
25 26 27 |
# File 'lib/rubix/models/trigger.rb', line 25 def description @description end |
#expression ⇒ Object
Returns the value of attribute expression.
26 27 28 |
# File 'lib/rubix/models/trigger.rb', line 26 def expression @expression end |
#priority ⇒ Object
Returns the value of attribute priority.
25 26 27 |
# File 'lib/rubix/models/trigger.rb', line 25 def priority @priority end |
#status ⇒ Object
Returns the value of attribute status.
25 26 27 |
# File 'lib/rubix/models/trigger.rb', line 25 def status @status end |
#url ⇒ Object
Returns the value of attribute url.
25 26 27 |
# File 'lib/rubix/models/trigger.rb', line 25 def url @url end |
Class Method Details
.build(trigger) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rubix/models/trigger.rb', line 107 def self.build trigger new({ :id => trigger[id_field].to_i, :description => trigger['description'], :expression => trigger['expression'], :comments => trigger['comments'], :url => trigger['url'], :status => STATUS_CODES[trigger['status'].to_i], :priority => PRIORITY_CODES[trigger['priority'].to_i], :item_ids => (trigger['items'] || []).map { |item| item['itemid'].to_i } }.merge(host_or_template_params_from_id(trigger['templateid'].to_i))) end |
.find_params(options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rubix/models/trigger.rb', line 91 def self.find_params ={} fp = { :filter => { :description => [:description] } }.tap do |fp| case when [:template_id] fp[:templateids] = [[:template_id]] when [:host_id] fp[:hostids] = [[:host_id]] end end super().merge(fp) end |
.get_params ⇒ Object
87 88 89 |
# File 'lib/rubix/models/trigger.rb', line 87 def self.get_params super().merge(:select_items => :refer) end |
.host_or_template_params_from_id(id) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rubix/models/trigger.rb', line 120 def self.host_or_template_params_from_id id template_or_host = Template.find(:id => id) || Host.find(:id => id) case template_or_host when Template { :template => template_or_host } when Host { :host => template_or_host } else {} end end |
Instance Method Details
#create_params ⇒ Object
Requests ==
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubix/models/trigger.rb', line 75 def create_params { :templateid => (template_id || host_id), :description => (description || 'Unknown'), :expression => expression, :priority => self.class::PRIORITY_CODES[priority], :status => self.class::STATUS_CODES[status], :comments => comments, :url => url } end |