Public | Automated Build

Last pushed: 5 days ago
Short Description
Sends notifications to Flowdock about events happening in your OpenShift cluster.
Full Description

OpenShift Flowdock Notifier

Sends notifications to Flowdock about events happening in your OpenShift cluster.


This Go application is an OpenShift client that listen to events in the cluster, and post notifications to the inbox of your Flowdock flows.

How It Works

This application can be deployed on OpenShift - or anywhere else, but I guess you will want to run it in your OpenShift cluster.

It should run with a ServiceAccount that has enough rights to watch the events you want to forward to Flowdock. You have 2 solutions:

  • use the provided template that creates a specific ServiceAccount (flowdock-notifier) with the right role (view) - this is good if you want notifications for a single project, or for just a few projects (in this case you will need to add more rights to the ServiceAccount)
  • create a ServiceAccount with the cluster-reader role - this solution should be used if you want notifications for the whole cluster, but it requires admin rights to setup.

Based on a configuration file (or environment variables), it will watch pre-defined types of resources, and use the Flowdock API to send notifications to the Team Inbox of one (or more) flows.

It uses the Flow Token to send mail-like messages to the team inbox of a flow using the Team Inbox Push API. You can find the flows tokens in your account page.

Supported events

For the moment, the following events are supported:

  • Builds events: when a new build has been started, has successfully completed, has failed, has been cancelled, ...

More events are in the roadmap ;-)

Configuration

You can either use a few environment variables for a basic and simple configuration - it is the fastest to setup, but more limited - or you can use a configuration file, but it requires more work to setup.

Environment variables based configuration

This way of configuring the application is recommanded if you want to send the notifications of a single project to a single flow.

The following environment variables are supported:

  • NOTIFIERS_DEFAULT_TOKEN to configure the Flow Token for the flow that will receive the notifications - Go to your account page to retrieve the token.
  • NOTIFIERS_DEFAULT_SOURCE if you want to overwrite the name of the source in the notification - defaults to OpenShift.
  • NOTIFIERS_DEFAULT_FROM_NAME if you want to overwrite the name of the sender in the notification - defaults to OpenShift.
  • NOTIFIERS_DEFAULT_FROM_ADDRESS if you want to overwrite the address of the sender in the notification - defaults to build+ok@flowdock.com for successful builds or build+fail@flowdock.com for failed builds, or openshift@example.org for all other events. Note that this address is used to display an avatar from the Gravatar service - see the Flowdock Team Inbox API for more informations.
  • ENABLE_DEFAULT_BUILDS_WATCHER to enable the default builds watcher, that will

Running on OpenShift

If you want to deploy this application on an OpenShift cluster, you need to:

  • create a new application from the provided openshift-template-deploy-only.yml template, and overwrite some parameters:

    oc new-app -f openshift-template-deploy-only.yml -p FLOW_TOKEN=xxx
    

    Of course, replace xxx by the value of your GitHub Access Token. To create such a token, go to your GitHub Tokens Settings page, and create a new token with the admin:repo_hook scope.

  • optional - if you want to get notifications from more than 1 project:

    • either add the view role to the flowdock-notifier ServiceAccount in a different project (you will need to be admin in the other project):

      oc policy add-role-to-user view system:serviceaccount:$(oc project -q):flowdock-notifier -n PROJECT_NAME
      

      The $(oc project -q) is used to get the name of the current project, in which the flowdock-notifier ServiceAccount has been created. Don't forget to replace PROJECT_NAME with the name of the other project. This can be repeated for any number of projects.

    • or give the cluster-reader role to the flowdock-notifier ServiceAccount (you will need to be cluster admin for that):

      oadm policy add-cluster-role-to-user cluster-reader system:serviceaccount:$(oc project -q):flowdock-notifier
      

      The $(oc project -q) is used to get the name of the current project, in which the flowdock-notifier ServiceAccount has been created.

You can use either of the following templates:

Running locally

If you want to run it on your laptop:

  • Install Go (tested with 1.6) and setup your GOPATH
  • clone the sources in your GOPATH

    git clone https://github.com/vbehar/openshift-flowdock-notifier.git $GOPATH/src/github.com/vbehar/openshift-flowdock-notifier
    
  • install godep (to use the vendored dependencies)

    go get github.com/tools/godep
    
  • build the binary with godep:

    cd $GOPATH/src/github.com/vbehar/openshift-flowdock-notifier
    godep go build
    
  • configure the application, either with a config.yml file, or with some environment variables (see the configuration section)

  • start the application in verbose mode

    ./openshift-flowdock-notifier --v=3
    
  • enjoy!

License

Copyright 2016 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Docker Pull Command
Owner
vbehar

Comments (0)