Class: Zabbirc::Zabbix::Trigger

Inherits:
Resource::Base show all
Defined in:
lib/zabbirc/zabbix/trigger.rb

Instance Method Summary collapse

Methods inherited from Resource::Base

#[], api, #api, #id, id_attr_name, #initialize, #method_missing, model_name, set_id_attr_name, set_model_name

Methods included from Resource::Associations

#has_many, #has_one

Methods included from Resource::Finders

#find, #get

Constructor Details

This class inherits a constructor from Zabbirc::Zabbix::Resource::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zabbirc::Zabbix::Resource::Base

Instance Method Details

#changed_atObject



33
34
35
# File 'lib/zabbirc/zabbix/trigger.rb', line 33

def changed_at
  Time.at(lastchange.to_i)
end

#format_label(fmt) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/zabbirc/zabbix/trigger.rb', line 37

def format_label fmt
  fmt.gsub("%priority-code", "#{priority.code}").
      gsub("%priority-num", "#{priority.number}").
      gsub("%time", "#{changed_at.to_formatted_s(:short)}").
      gsub("%msg", "#{message}").
      gsub("%id", "#{id}").
      gsub("%value", "#{value}")
end

#labelObject



29
30
31
# File 'lib/zabbirc/zabbix/trigger.rb', line 29

def label
  format_label "%time [%priority-code] %msg - %value"
end

#messageObject



21
22
23
24
25
26
27
# File 'lib/zabbirc/zabbix/trigger.rb', line 21

def message
  if description.include?("{HOST.NAME}")
    description.sub("{HOST.NAME}", hosts.collect(&:host).join(', '))
  else
    "#{description} on #{hosts.collect(&:host).join(', ')}"
  end
end

#priorityObject



6
7
8
# File 'lib/zabbirc/zabbix/trigger.rb', line 6

def priority
  Priority.new(super.to_i)
end

#valueObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/zabbirc/zabbix/trigger.rb', line 10

def value
  case @attrs[:value].to_i
  when 0
    :ok
  when 1
    :problem
  else
    @attrs[:value]
  end
end