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
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 12 def initialize(*) super self.notifier = ::Slack::Notifier.new( .fetch('team'), .fetch('token'), channel: ['channel'], username: ['username'], icon_emoji: ['icon_emoji'], icon_url: ['icon_url']) end |
Instance Method Details
#notify!(notification) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 47 def notify!(notification) unit = notification.unit = "#{notification.type_text}: systemd unit #{unit.name} on #{notification.hostname} #{unit.state_change.status_text}" attach = { fallback: "#{message}: #{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
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 23 def notify_start!(hostname) = "SystemdMon is starting on #{hostname}" attach = { fallback: , text: , color: "good" } notifier.ping "", attachments: [attach] end |
#notify_stop!(hostname) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 35 def notify_stop!(hostname) = "SystemdMon is stopping on #{hostname}" attach = { fallback: , text: , color: "danger" } notifier.ping "", attachments: [attach] end |