Class: Sc4ry::Notifiers::Mattermost
- Inherits:
-
Object
- Object
- Sc4ry::Notifiers::Mattermost
- Defined in:
- lib/sc4ry/notifiers/mattermost.rb
Class Method Summary collapse
-
.notify(options = {}) ⇒ Bool
send metrics to Prometheus PushGateway.
Class Method Details
.notify(options = {}) ⇒ Bool
send metrics to Prometheus PushGateway
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sc4ry/notifiers/mattermost.rb', line 8 def Mattermost.notify( = {}) config = Sc4ry::Notifiers.get({name: :mattermost})[:config] status = [:config][:status][:general] circuit = [:circuit] status_map = {:open => 0, :half_open => 1, :closed => 2} uri = URI.parse("#{config[:url]}/hooks/#{config[:token]}") = "notifying for circuit #{circuit.to_s}, state : #{status.to_s}." if Sc4ry::Helpers::verify_service url: config[:url] then request = ::Net::HTTP::Post.new(uri) request.content_type = "application/json" = { use_ssl: uri.scheme == "https", } payload = { "text" => "message : #{ } from #{Socket.gethostname}", "username" => "Sc4ry" } Sc4ry::Helpers.log level: :debug, message: "Mattermost Notifier : #{}" request.body = ::JSON.dump(payload) response = ::Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end else Sc4ry::Helpers.log level: :warn, message: "Mattermost Notifier : can't notify Mattermost not reachable." end end |