Skip to content

aldur/uwsgi-slack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

uWSGI-slack

uWSGI-slack is a plugin that allows alarms/hooks integration with the Slack service.

Features

uWSGI-slack provides the following features:

Installation

This plugin requires:

  • libcurl (to send HTTP requests with ease)
  • jansson (for JSON parsing)

Please follow the specific documentation on how to install them.

This plugin is 2.0 friendly. You can thus build it with:

$ git clone https://github.com/aldur/uwsgi-slack
$ uwsgi --build-plugin uwsgi-slack

Configuration

To use this plugin you'll need to setup an incoming webhook integration in your Slack team.

You can configure the alarms in your app as follows:

[uwsgi]
plugins = slack

; register a 'slackme' alarm
alarm = slackme slack:webhook_url=YOUR_SLACK_TEAM_WEBHOOK_URL,username=uWSGI Alarmer,icon_emoji=:heavy_exclamation_mark:
; raise alarms no more than 1 time per minute (default is 3 seconds)
alarm-freq = 60

; raise an alarm whenever uWSGI segfaults
alarm-segfault = slackme

; raise an alarm whenever /danger is hit
route = ^/danger alarm:slackme /danger has been visited !!!

; raise an alarm when the avergae response time is higher than 3000 milliseconds
metric-alarm = key=worker.0.avg_response_time,value=3000,alarm=slackme

; ...

The only mandatory key-value field we need to send an alarm is the webhook_url. In the previous example we've also set the Slack BOT username and it's icon (an emoji).

Hooks, on the other side, require the message text too:

[uwsgi]
plugins = slack

hook-post-app = slack:webhook_url=YOUR_SLACK_TEAM_WEBHOOK_URL,text=Your awesome app has just been loaded!,username=Your friendly neighbourhood Flip-Man,icon_emoji=:flipper:

; ...

Alarms/hooks key-value options

We support the entire Slack incoming webhook API. Available key-values options are:

  • text
  • channel
  • username
  • icon_emoji
  • icon_url

Unspecified settings will fallback to the Slack webhook defaults.

As an extra, you can specify a ; separated list of attachments as a value for the attachments key.

Attachments

You can define an attachment and send messages containing it by using the following configuration snippet:

[uwsgi]
plugins = slack

slack-attachment = name=groove,title=A slack attachment,color=#7CD197
hook-post-app = slack:webhook_url=YOUR_SLACK_TEAM_WEBHOOK_URL,attachments=groove,text=Hook text

; ...

As you can see we specify a mandatory attachment name, we setup the attachment and we link it to the uWSGI hook / alarm through the attachments key.

Note: the attachments' name lookup is done at runtime. A malformed attachment name will let uWSGI ignore the whole alarm / hook trigger.

Attachments key-value options are:

  • name (mandatory)
  • fallback
  • color
  • pretext
  • author_name
  • author_link
  • author_icon
  • title
  • title_link
  • text
  • image_url
  • thumb_url

A detailed explanation for each key can be found here. Again, unspecified settings will fallback to Slack defaults.

As an extra, you can link a ; separated list of fields to the attachment by using the fields key.

Fields

Fields are nested within attachments and will be displayed in a table.

Their configuration is should look familiar:

[uwsgi]
plugins = slack

slack-field = name=project,title=Project,value=Awesome Project,short=true
slack-field = name=environment,title=Environment,value=Production Project

slack-attachment = name=groove,title=A slack attachment,color=#7CD197,fields=project;environment

hook-post-app = slack:webhook_url=YOUR_SLACK_TEAM_WEBHOOK_URL,attachments=groove,text=Hook text

; ...

Fields key-value options are:

  • name (mandatory)
  • title
  • value
  • short (if anything is set will be considered True, False otherwise)

As usual, better documentation for each key can be found here.

uWSGI related key-value options

On the uWSGI/networking side you can set:

  • timeout: specifies the socket timeout.
  • ssl_no_verify: tells Curl to not verify the server SSL certificate.

Screens

An alarm-resulting example with attachments and fields in action.

Example

About

uWSGI plugin for Slack integration. (https://slack.com)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published