Class: Sc4ry::Notifiers::Mattermost
- Inherits:
-
Object
- Object
- Sc4ry::Notifiers::Mattermost
- Defined in:
- lib/sc4ry/notifiers/mattermost.rb
Overview
Mattermost Notifier class
Class Method Summary collapse
-
.notify(options = {}) ⇒ Bool
send metrics to Prometheus PushGateway.
Class Method Details
.notify(options = {}) ⇒ Bool
send metrics to Prometheus PushGateway
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sc4ry/notifiers/mattermost.rb', line 13 def self.notify( = {}) config = Sc4ry::Notifiers.get(name: :mattermost)[:config] status = [:config][:status][:general] circuit = [:circuit] begin uri = URI.parse("#{config[:url]}/hooks/#{config[:token]}") = "notifying for circuit #{circuit}, state : #{status}." if Sc4ry::Helpers.verify_service url: config[:url] request = ::Net::HTTP::Post.new(uri) request.content_type = 'application/json' = { use_ssl: uri.scheme == 'https' } payload = { 'text' => "message : #{message} from #{Socket.gethostname}", 'username' => 'Sc4ry' } Sc4ry::Helpers.log level: :debug, message: "Mattermost Notifying : #{message}" request.body = ::JSON.dump(payload) ::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 rescue URI::InvalidURIError Sc4ry::Helpers.log level: :warn, message: 'Mattermost Notifier : URL malformed' end end |