-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support send notification to Slack, RocketChat etc. using Webhooks #1
Comments
Or a webhook? That is a more flexible solution for integration. |
@brotandgames that's great. Definitely willing to jump in a bit here. I like the simplicity of the way that your email integration is set up and that can be more challenging given the structure of a webhook. What would you think about a default JSON format with something that can be overridden based on a configuration file in the image? Then, an environment var could trigger webook (and disable email) like ENABLE_WEBHOOK_NOTIFICATION, reading a set of environment variables to trigger the HTTP request. |
Should it be allowed to use more than one Notification target like Mail, Webhook::Slack or Webhook::RocketChat at the same time? Our opinion: yes. As of now if you don't specify a Webhooks should somehow be configurable through ENV variables to stay in the 12-factor app context. Furthermore there should be no updates on the app if we want to support another notification target since it's a webhook: calling an endpoint with a payload. What about having the following approach: 2 ENV variables per Webhook like:
The app reads the ENV vars on startup and configures the Notifier which is then triggered by a status change. |
Tested this a little bit:
require 'net/http'
require 'json'
require 'uri'
# Following ENV vars have to be set prior to executing this script
# export CIAO_WEBHOOK_ENDPOINT_1=https://chat.yourhost.com/hooks/*****
# export CIAO_WEBHOOK_PAYLOAD_1='{"username":"Brot & Games","icon_url":"https://avatars0.githubusercontent.com/u/43862266?s=400&v=4","text":"Example message","attachments":[{"title":"Rocket.Chat","title_link":"https://rocket.chat","text":"Rocket.Chat, the best open source chat","image_url":"/images/integration-attachment-example.png","color":"#764FA5"}]}'
endpoint = ENV["CIAO_WEBHOOK_ENDPOINT_1"]
payload = ENV["CIAO_WEBHOOK_PAYLOAD_1"]
uri = URI.parse(endpoint)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == "https"
request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
request.body = payload
response = http.request(request)
p response This has been tested with RocketChat (with the above payload
@jmcshane Do you currently have a Slack channel where you could test this? |
@brotandgames I can implement this in a simple dynamic way where the user will be able to CRUD multiple webhooks and the payload structure (basic templating) from the web UI. I can deliver it today evening! Should I go forward or any opinions? |
@tareksamni The basic idea of ciao is to keep everything configurable per ENV variables.
would be desirable. Keeping ciao's configuration stateless is keeping it simple. |
Good, then we go with ENV variables Something like:
You can define multiple webhooks with this regex: What do you think? |
Sounds good. We need an initializer
Something like this:
|
Yes, exactly what I had in mind :) but with slight templating abilities to the |
Perfect. |
@tareksamni @gnomus @mterron @jmcshane Is this a good timing to open a chat like gitter.im for this project? |
YES YES YES! would be way easier to discuss features, implementation strategies, etc. |
Here we go: https://gitter.im/brotandgames/ciao |
@tareksamni All WebhookNotification are instantiated in the initializer and saved in an Array (notifications). |
@tareksamni Thank you for your great work! Closed by #25. |
It appears that the notification integration is set here:
https://github.com/brotandgames/ciao/blob/master/app/models/check.rb#L52
It would be great to be able to send a notification to a slack channel instead of an email based on specific configuration. I would be interested in helping here using https://github.com/slack-ruby/slack-ruby-client.
Is this something the project is willing to support?
The text was updated successfully, but these errors were encountered: