Class: Notifu::Actors::Slack
- Inherits:
-
Notifu::Actor
- Object
- Notifu::Actor
- Notifu::Actors::Slack
- Defined in:
- lib/notifu/actors/slack.rb
Instance Attribute Summary
Attributes inherited from Notifu::Actor
Instance Method Summary collapse
Methods inherited from Notifu::Actor
Methods included from Util
Instance Method Details
#act ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/notifu/actors/slack.rb', line 82 def act self.contacts.each do |contact| Excon.post(contact.slack_url, tcp_nodelay: true, headers: { "ContentType" => "application/json" }, body: self.post_data, expects: [ 200 ], idempotent: true ) end end |
#color ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/notifu/actors/slack.rb', line 54 def color case self.issue.code when 0 "good" when 1 "warning" when 2 "danger" else "#999999" end end |
#post_data ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/notifu/actors/slack.rb', line 16 def post_data { username: "notifu", icon_emoji: ":loudspeaker:", attachments: [ { fallback: self.text, color: self.color, title: "#{self.issue.host} - #{self.issue.service}", title_link: "https://sensu.skypicker.com/#/client/#{Notifu::CONFIG[:actors][:slack][:dc]}/#{self.issue.host}?check=#{self.issue.service}", text: self.issue., fields: [ { title: "duration", value: (Time.now.to_i - self.issue.time_created.to_i).duration, short: true }, { title: "started", value: Time.at(self.issue.time_created.to_i), short: true }, { title: "occurrences/trigger", value: "#{self.issue.occurrences_count}/#{self.issue.occurrences_trigger}", short: true }, { title: "notifu ID", value: self.issue.notifu_id, short: true } ] } ] }.to_json end |
#template ⇒ Object
12 13 14 |
# File 'lib/notifu/actors/slack.rb', line 12 def template "<%= data[:status] %> [<%= data[:host] %>/<%= data[:service] %>]: <%= data[:message] %> (<%= data[:duration] %>) NID:<%= data[:notifu_id] %>]" end |
#text ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/notifu/actors/slack.rb', line 67 def text data = OpenStruct.new({ notifu_id: self.issue.notifu_id, host: self.issue.host, service: self.issue.service, message: self.issue., status: self.issue.code.to_state, first_event: Time.at(self.issue.time_created.to_i), duration: (Time.now.to_i - self.issue.time_created.to_i).duration, occurrences_count: self.issue.occurrences_count, occurrences_trigger: self.issue.occurrences_trigger }) ERB.new(self.template).result(data.instance_eval {binding}) end |