Class: Rds::S3::Backup::DataDog
- Inherits:
-
Object
- Object
- Rds::S3::Backup::DataDog
- Defined in:
- lib/rds-s3-backup/datadog.rb
Instance Method Summary collapse
-
#initialize(api_key) ⇒ DataDog
constructor
A new instance of DataDog.
- #make_dog_client ⇒ Object
- #send(msg, o = {}) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ DataDog
Returns a new instance of DataDog.
21 22 23 24 |
# File 'lib/rds-s3-backup/datadog.rb', line 21 def initialize(api_key) raise DataDogException.new("No DataDog API given") if api_key.nil? || api_key.empty? @api_key = api_key end |
Instance Method Details
#make_dog_client ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rds-s3-backup/datadog.rb', line 26 def make_dog_client() return unless @api_key begin Dogapi::Client.new(@api_key) rescue Exception => e unless e.is_a?(DataDogException) # no loops! raise DataDogException.new "Error setting up DataDog connection: #{e.class}: #{e}" end end end |
#send(msg, o = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rds-s3-backup/datadog.rb', line 38 def send(msg, o={}) return unless @api_key return if msg.nil? || msg.empty? = { :msg_title => 'Message from rds-s3-backup:', :alert_type => 'Error', :tags => [ "host:#{`hostname`}", "env:production" ], :priority => 'normal', :source => 'My Apps'}.merge(o) @dog_client ||= make_dog_client() begin @dog_client.emit_event(Dogapi::Event.new(msg, )) rescue Exception => e unless e.is_a?(DataDogException) # no loops! raise DataDogException.new "Error sending #{msg} to DataDog with options #{.inspect}: #{e.class}: #{e.}" end end end |