class SystemdMon::Notifiers::Hipchat

Attributes

client[RW]
options[RW]

Public Class Methods

new(*) click to toggle source
Calls superclass method SystemdMon::Notifiers::Base::new
# File lib/systemd_mon/notifiers/hipchat.rb, line 12
def initialize(*)
  super
  self.client = ::HipChat::Client.new(
      options['token'],
      :api_version => 'v2')
end

Public Instance Methods

notify!(notification) click to toggle source
# File lib/systemd_mon/notifiers/hipchat.rb, line 29
def notify!(notification)
  unit = notification.unit
  message = "#{notification.type_text}: systemd unit #{unit.name} on #{notification.hostname} #{unit.state_change.status_text}: #{unit.state.active} (#{unit.state.sub})"

  chat message,
       color(notification.type)

  log "sent hipchat notification"
end
notify_start!(hostname) click to toggle source
# File lib/systemd_mon/notifiers/hipchat.rb, line 19
def notify_start!(hostname)
  chat "SystemdMon is starting on #{hostname}",
       'green'
end
notify_stop!(hostname) click to toggle source
# File lib/systemd_mon/notifiers/hipchat.rb, line 24
def notify_stop!(hostname)
  chat "SystemdMon is stopping on #{hostname}",
       'yellow'
end

Protected Instance Methods

chat(message, shade) click to toggle source
# File lib/systemd_mon/notifiers/hipchat.rb, line 42
def chat(message, shade)
  client[options['room']].send(
    options['username'],
    message,
    :color => shade)
end
color(type) click to toggle source
# File lib/systemd_mon/notifiers/hipchat.rb, line 49
def color(type)
  case type
  when :alert
    'red'
  when :warning
    'yellow'
  when :info
    'purple'
  else
    'green'
  end
end