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.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 6 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 41 def notify!(notification) unit = notification.unit = "Systemd unit #{unit.name} on #{notification.hostname} #{unit.state_change.status_text}" attach = { fallback: "#{}: #{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
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 17 def notify_start!(hostname) = "Startup notification for SystemdMon" attach = { fallback: , text: "SystemdMon is starting on #{hostname}", color: "good" } notifier.ping , attachments: [attach] end |
#notify_stop!(hostname) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/systemd_mon/notifiers/slack.rb', line 29 def notify_stop!(hostname) = "Shutdown alert for SystemdMon" attach = { fallback: , text: "SystemdMon is stopping on #{hostname}", color: "danger" } notifier.ping , attachments: [attach] end |