Sha256: 0f101bb839d9f9515911f8cd5a8426c9cb41fef609f02421107d791b4b94383d

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

#!/usr/bin/env ruby

require 'flapjack/pikelet'
require 'flapjack/gateways/sms/messagenet'

module Flapjack
  module Gateways

    class Sms
      extend Flapjack::Gateways::Resque

      class << self

        def perform(notification)
          @logger.debug "Woo, got a notification to send out: #{notification.inspect}"
          dispatch(notification, :logger => @logger, :redis => ::Resque.redis)
        end

        def dispatch(notification, opts = {})
          notification_type  = notification['notification_type']
          contact_first_name = notification['contact_first_name']
          contact_last_name  = notification['contact_last_name']
          state              = notification['state']
          summary            = notification['summary']
          time               = notification['time']
          entity, check      = notification['event_id'].split(':')

          headline_map = {'problem'         => 'PROBLEM: ',
                          'recovery'        => 'RECOVERY: ',
                          'acknowledgement' => 'ACK: ',
                          'test'            => 'TEST NOTIFICATION: ',
                          'unknown'         => '',
                          ''                => '',
                         }

          headline = headline_map[notification_type] || ''

          message = "#{headline}'#{check}' on #{entity}"
          message += " is #{state.upcase}" unless ['acknowledgement', 'test'].include?(notification_type)
          message += " at #{Time.at(time).strftime('%-d %b %H:%M')}, #{summary}"

          notification['message'] = message
          Flapjack::Gateways::Sms::Messagenet.sender(notification,
            :logger => opts[:logger],
            :config => Flapjack::Gateways::Sms.instance_variable_get('@config'))
        end

      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flapjack-0.6.46 lib/flapjack/gateways/sms.rb
flapjack-0.6.45 lib/flapjack/gateways/sms.rb
flapjack-0.6.44 lib/flapjack/gateways/sms.rb