bin/handler-freesmsalert.rb
##
# This methos is spawned when Sensu passes us an alert
#
# By default we'll use the free_sms_alert settings key. If you want different
# people getting alerts for different plugins, then use a different
# settings key in your handler config. Magic!
#
This methos is spawned when Sensu passes us an alert
By default we'll use the free_sms_alert settings key. If you want different
people getting alerts for different plugins, then use a different
settings key in your handler config. Magic!
This methos is spawned when Sensu passes us an alert By default we ' ll use the free_sms_alert settings key . If you want different people getting alerts for different plugins then use a different settings key in your handler config . Magic!
def handle
    @settings_key = 'free_sms_alert'
    @settings_key = ARGV[0] if ARGV.empty? == false
    smtp_address = settings['free_sms_alert']['smtp_address'] || 'localhost'
    smtp_port = settings['free_sms_alert']['smtp_port'] || '25'
    smtp_domain = settings['free_sms_alert']['smtp_domain'] || 'localhost.localdomain'
    mail_from = settings['free_sms_alert']['mail_from'] || 'sensu_alert@mydomain.com'
    Mail.defaults do
      delivery_method :smtp,
                      address: smtp_address,
                      port: smtp_port,
                      domain: smtp_domain,
                      openssl_verify_mode: 'none'
    end
    settings[@settings_key]['alert_recipients'].each do |user_id|
      mail_to = nil
      number = nil
      info = settings['free_sms_alert']['alert_recipient_mappings'][user_id]
      number = if info['carrier'] == 'email'
                 info['number']
               else
                 info['number'].gsub(/[^0-9]/, '')
               end
      settings['free_sms_alert']['carrier_portal'].each do |carrier, address|
        mail_to = address.gsub(/%number%/, number) if info['carrier'] == carrier
      end
      send_sms(user_id, mail_to, mail_from) if mail_to.nil? == false
    end
  end
def handle @settings_key = 'free_sms_alert' @settings_key = ARGV [ 0 ] if ARGV . empty? == false smtp_address = settings [ 'free_sms_alert' ] [ 'smtp_address' ] || 'localhost' smtp_port = settings [ 'free_sms_alert' ] [ 'smtp_port' ] || '25' smtp_domain = settings [ 'free_sms_alert' ] [ 'smtp_domain' ] || 'localhost.localdomain' mail_from = settings [ 'free_sms_alert' ] [ 'mail_from' ] || 'sensu_alert@mydomain.com' Mail . defaults do delivery_method :smtp , address : smtp_address , port : smtp_port , domain : smtp_domain , openssl_verify_mode : 'none' end settings [ @settings_key ] [ 'alert_recipients' ] . each do | user_id | mail_to = nil number = nil info = settings [ 'free_sms_alert' ] [ 'alert_recipient_mappings' ] [ user_id ] number = if info [ 'carrier' ] == 'email' info [ 'number' ] else info [ 'number' ] . gsub ( / [^0-9] / , '' ) end settings [ 'free_sms_alert' ] [ 'carrier_portal' ] . each do | carrier , address | mail_to = address . gsub ( / %number% / , number ) if info [ 'carrier' ] == carrier end send_sms ( user_id , mail_to , mail_from ) if mail_to . nil? == false end end
This methos is spawned when Sensu passes us an alert
By default we'll use the free_sms_alert settings key.
This methos is spawned when Sensu passes us an alert By default we ' ll use the free_sms_alert settings key .