Class: Notifu::Actor
- Includes:
- Util, Sidekiq::Worker
- Defined in:
- lib/notifu/workers/actor.rb
Direct Known Subclasses
Notifu::Actors::GammuSmsBridge, Notifu::Actors::Pagerduty, Notifu::Actors::Slack, Notifu::Actors::Stdout, Notifu::Actors::TwilioCall
Class Attribute Summary collapse
-
.desc ⇒ Object
Returns the value of attribute desc.
-
.name ⇒ Object
Returns the value of attribute name.
-
.retry ⇒ Object
Returns the value of attribute retry.
Instance Attribute Summary collapse
-
#contacts ⇒ Object
Returns the value of attribute contacts.
-
#issue ⇒ Object
Returns the value of attribute issue.
Instance Method Summary collapse
-
#act ⇒ Object
`act` function must be defined in child classes (provides notification actors modularity).
- #apply_template(t) ⇒ Object
- #default_template ⇒ Object
- #load_data(args) ⇒ Object
- #perform(*args) ⇒ Object
Methods included from Util
Class Attribute Details
.desc ⇒ Object
Returns the value of attribute desc
32 33 34 |
# File 'lib/notifu/workers/actor.rb', line 32 def desc @desc end |
.name ⇒ Object
Returns the value of attribute name
31 32 33 |
# File 'lib/notifu/workers/actor.rb', line 31 def name @name end |
.retry ⇒ Object
Returns the value of attribute retry
33 34 35 |
# File 'lib/notifu/workers/actor.rb', line 33 def retry @retry end |
Instance Attribute Details
#contacts ⇒ Object
Returns the value of attribute contacts
28 29 30 |
# File 'lib/notifu/workers/actor.rb', line 28 def contacts @contacts end |
#issue ⇒ Object
Returns the value of attribute issue
27 28 29 |
# File 'lib/notifu/workers/actor.rb', line 27 def issue @issue end |
Instance Method Details
#act ⇒ Object
`act` function must be defined in child classes (provides notification actors modularity)
39 40 41 |
# File 'lib/notifu/workers/actor.rb', line 39 def act exit 1 end |
#apply_template(t) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# 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., 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.}" ERB.new(default_template).result(@data.instance_eval {binding}) end end |
#default_template ⇒ Object
92 93 94 |
# File 'lib/notifu/workers/actor.rb', line 92 def default_template "<%= status %> [<%= dc %>/<%= host %>/<%= service %>]: (<%= message %>) <%= duration %> [<%= notifu_id %>]" end |
#load_data(args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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) ⇒ Object
46 47 48 49 50 |
# File 'lib/notifu/workers/actor.rb', line 46 def perform *args sleep 1 load_data args || return act end |