Sha256: 9454de286692b4e5fb6a34097a1849013923593625ef3d73c95c09dd262501b2
Contents?: true
Size: 1.89 KB
Versions: 4
Compression:
Stored size: 1.89 KB
Contents
#!/usr/bin/env ruby # # Sensu Handler: clockworksms # # This handler send SMS via clockworksms API based on the severity of the check result. # # Requires: clockworksms gem # # Copyright 2014 Dejan Golja <dejan@golja.org> # # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. require 'sensu-handler' require 'clockwork' require 'timeout' # # Clcokwork Sms Notify # class ClockWorkSmsNotif < Sensu::Handler def event_name @event['client']['name'] + '/' + @event['check']['name'] end def send_sms(to, from, content) content[157..content.length] = '...' if content.length > 160 message = @api.messages.build message.to = to message.from = from message.content = content response = message.deliver # #YELLOW unless response.success # rubocop:disable GuardClause puts "#{response.error_code} - #{response.error_description}" end end def handle # rubocop:disable all key = settings['clockworksms']['key'] to = settings['clockworksms']['to'] from = settings['clockworksms']['from'] || 'SENSU' fail 'Please define a valid SMS key' if key.nil? fail 'Please define a valid set of SMS recipients to use this handler' if to.nil? || !to.is_a?(Hash) message = @event['check']['notification'] || @event['check']['output'] @api = Clockwork::API.new(key) to.each do |phone, severities| break unless severities.is_a?(Array) severities.map!(&:downcase) case @event['check']['status'] when 0 if severities.include?('ok') send_sms(phone, from, "OK-#{event_name} #{message}") end when 1 if severities.include?('warning') send_sms(phone, from, "WARN-#{event_name} #{message}") end when 2 if severities.include?('critical') send_sms(phone, from, "CRIT-#{event_name} #{message}") end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems