Class: Notification::Send
- Inherits:
-
Object
- Object
- Notification::Send
- Includes:
- Logging
- Defined in:
- lib/gaddygaddy-client/notification.rb
Instance Method Summary collapse
- #event ⇒ Object
- #event=(event) ⇒ Object
-
#initialize(options = {}) ⇒ Send
constructor
A new instance of Send.
-
#language ⇒ Object
Language is english for now, we need to add a language parameter to the user info or config for gaddygaddy.
- #message_as_text ⇒ Object
-
#notify(device_id) ⇒ Object
Will do notifications to different sources like log file, web site and even speak.
Methods included from Logging
create_logger, #logger, logger, set_log_conf, #set_log_file, #set_log_level
Constructor Details
#initialize(options = {}) ⇒ Send
Returns a new instance of Send.
27 28 29 30 |
# File 'lib/gaddygaddy-client/notification.rb', line 27 def initialize( = {}) I18n.load_path += Dir[File.join(File.dirname(__FILE__), '..','..','locales', '*.yml').to_s] @speech_enabled = [:speech_enabled] end |
Instance Method Details
#event ⇒ Object
41 42 43 |
# File 'lib/gaddygaddy-client/notification.rb', line 41 def event @event end |
#event=(event) ⇒ Object
37 38 39 |
# File 'lib/gaddygaddy-client/notification.rb', line 37 def event= event @event = JSON.parse(event) end |
#language ⇒ Object
Language is english for now, we need to add a language parameter to the user info or config for gaddygaddy
33 34 35 |
# File 'lib/gaddygaddy-client/notification.rb', line 33 def language 'en' end |
#message_as_text ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/gaddygaddy-client/notification.rb', line 45 def logger.debug "Will create message from event #{event['message_key']}" translated_text = I18n.t event['message_key'], {locale: language} count_values = translated_text.split("%").count - 1 if event['message_values']||count_values > 0 if count_values == event['message_values'].length translated_text % event['message_values'] else raise "Mismatch between the text for #{event['message_key']} - #{translated_text} have #{count_values} %s and the size of event values array is #{event['message_values'].length}" end else translated_text end end |
#notify(device_id) ⇒ Object
Will do notifications to different sources like log file, web site and even speak
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gaddygaddy-client/notification.rb', line 62 def notify(device_id) event['event_time'] = Time.now unless event['event_time'] event['device_id'] = device_id # Need to test before we put stuff in log file should_speak = ! Notification::FileNotification.text_in_log_file() Notification::Wall.notify(event, ) Notification::FileNotification.notify(event, ) Notification::Sensu.notify(event, ) Notification::ESpeakNotification.notify(event, ) if should_speak && @speech_enabled end |