class Notifu::Actor
Attributes
desc[RW]
name[RW]
retry[RW]
contacts[RW]
issue[RW]
Public Instance Methods
act()
click to toggle source
`act` function must be defined in child classes (provides notification actors modularity)
# File lib/notifu/workers/actor.rb, line 39 def act exit 1 end
apply_template(t)
click to toggle source
# File lib/notifu/workers/actor.rb, line 66 def apply_template t @data ||= OpenStruct.new({ notifu_id: self.issue.notifu_id, datacenter: self.issue.datacenter, host: self.issue.host, service: self.issue.service, status: self.issue.code.to_state, code: self.issue.code.to_s, message: self.issue.message, first_event: Time.at(self.issue.time_created.to_i), duration: (Time.now.to_i - self.issue.time_created.to_i).duration, interval: self.issue.interval.duration, refresh: self.issue.refresh.duration, occurrences_count: self.issue.occurrences_count, occurrences_trigger: self.issue.occurrences_trigger, uchiwa_url: "#{Notifu::CONFIG[:uchiwa_url]}/#/client/#{self.issue.datacenter}/#{self.issue.host}?check=#{self.issue.service}", playbook: self.issue.playbook }) begin ERB.new(t).result(@data.instance_eval { binding }) rescue Exception => e log "error", "Failed to render ERB template - #{e.class}: #{e.message}" ERB.new(default_template).result(@data.instance_eval {binding}) end end
default_template()
click to toggle source
# File lib/notifu/workers/actor.rb, line 92 def default_template "<%= status %> [<%= dc %>/<%= host %>/<%= service %>]: (<%= message %>) <%= duration %> [<%= notifu_id %>]" end
load_data(args)
click to toggle source
# File lib/notifu/workers/actor.rb, line 52 def load_data args self.issue = Notifu::Model::Issue.with(:notifu_id, args[0]) if self.issue == nil log "error", "Issue with NID #{args[0]} doesn't exist!" return false end self.contacts = Array.new args[1].each do |contact| c = Notifu::Model::Contact.with(:name, contact) self.contacts << c if c end return true end
perform(*args)
click to toggle source
# File lib/notifu/workers/actor.rb, line 46 def perform *args sleep 1 load_data args || return act end