Class: LogStash::Outputs::Pushover

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/pushover.rb

Overview

Event notification through Pushover. Currently only supports plain messages (event) and no further configuration options are submitted.

Instance Method Summary collapse

Instance Method Details

#receive(event) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/logstash/outputs/pushover.rb', line 55

def receive(event)
  return unless output?(event)

  @logger.info("Pushover event", :event => event)

  # If requested, add any logstash tags to the message
  message = event.to_s
  if @add_tags
    message += " tags: " + @tags.join(',') if @tags
  end

  begin
    request = Net::HTTP::Post.new(@api_uri.path)
    request.set_form_data({
      :token => @app_token,
      :user => @user_key,
      :message => event
    })
    # XXX: For any additional configuration keys, add them to the request.
    response = @client
    response.use_ssl = true
    response.verify_mode = OpenSSL::SSL::VERIFY_PEER
    response.start do |http|
      r = http.request(request)
      if status = r.body.match(/"status":(\d+)/)[1] != 1
        @logger.warn("API error", :status => status)
      end
    end
  rescue Exception => e
    @logger.warn("Failed to push notification", :event => event, :exception => e,
      :backtrace => e.backtrace)
  end
end

#registerObject



47
48
49
50
51
52
# File 'lib/logstash/outputs/pushover.rb', line 47

def register
  require 'net/https'
  require 'uri'
  @api_uri = URI.parse(@api_url)
  @client = Net::HTTP.new(@api_uri.host, @api_uri.port)
end