Class: SystemdMon::Notifiers::Slack
- Defined in:
- lib/systemd_mon/notifiers/slack.rb
Instance Method Summary collapse
-
#initialize ⇒ Slack
constructor
A new instance of Slack.
- #notify!(notification) ⇒ Object
- #notify_start!(hostname) ⇒ Object
- #notify_stop!(hostname) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize ⇒ Slack
Returns a new instance of Slack.
12 13 14 15 16 17 18 19 20 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 12 def initialize(*) super self.notifier = ::Slack::Notifier.new( .fetch('webhook_url'), channel: ['channel'], username: ['username'], icon_emoji: ['icon_emoji'], icon_url: ['icon_url']) end |
Instance Method Details
#notify!(notification) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 46 def notify!(notification) unit = notification.unit = "@channel #{notification.type_text}: systemd unit #{unit.name} on #{notification.hostname} #{unit.state_change.status_text}" if notification.type == :info = "#{notification.type_text}: systemd unit #{unit.name} on #{notification.hostname} #{unit.state_change.status_text}" end attach = { fallback: "@channel #{}: #{unit.state.active} (#{unit.state.sub})", color: color(notification.type), fields: fields(notification) } debug("sending slack message with attachment: ") debug(attach.inspect) notifier.ping , attachments: [attach] log "sent slack notification" end |
#notify_start!(hostname) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 22 def notify_start!(hostname) = "@channel SystemdMon is starting on #{hostname}" attach = { fallback: , text: , color: "good" } notifier.ping "", attachments: [attach] end |
#notify_stop!(hostname) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 34 def notify_stop!(hostname) = "@channel SystemdMon is stopping on #{hostname}" attach = { fallback: , text: , color: "danger" } notifier.ping "", attachments: [attach] end |