Giter VIP home page Giter VIP logo

mattermost-notify's Introduction

mattermost-notify

A template based Mattermost (or Slack) notification docker image for use in CI steps

This project was created so our company could load in json files as needed and parse them using Jinja2 and then dump output into Mattermost using Gitlab CI. For example if you have a code scanning tool you can extract a json result from, simply put that file into /app/json-input and it will be available to display as you wish into mattermost such as the example below:

Possible mattermost output

Available Variables

These variables can be set when running the docker image to customize the functionality

Variable Default Description
MESSAGE_TEXT Test Mattermost Notification A value that will be sent to Mattermost after rendering through Jinja
MATTERMOST_HOOK_URL https://google.com The full url that the HTTP POST request will go to (usually requires the incoming hook token in it)
DEBUG False If set to True will enable additional output including a dump of all the variables run against Jinja
TEMPLATE_FILE default.jinja A file inside /app/templates that will rendered against to post the message. If Using MESSAGE_TEXT this will dump into the default.jinja file automatically
CARD_TEMPLATE_FILE A template file inside /app/templates that will be rendered and sent as the info card content if it's not empty
CHANNEL The channel to put notification into. If not set will use the default set up for incoming hook
PREPROCESS_PYTHON If set will run this python script prior to running the notification script. Allows you to add more advanced functionality if needed

Directories

Directory Description
/app/templates Jinja files for you to render against, use in conjunction with TEMPLATE_FILE variable
/app/json-input Place .json files in here to be automatically read in as the data variable in jinja

Parsing

JSON

Files put in the /json-input will be available as data under the filename (minus extension) on render so a file of /app/json-input/example-file.json with the contents {'test':'sample_text'} will be available as {{ data['example-file']['test] }}

Environment Vars

You can pass in simple data using environment variables to the docker image. This will be available when rendering under the env jinja variable. So something like Commit: {{ env['CI_COMMIT_SHORT_SHA'] }} will render something like Commit: a82b1ac7 (in this case using the built-in Gitlab CI variable)

Jinja Templates

If you just want a single line displayed you can use the MESSAGE_TEXT variable and it will render whatever jinja in that, else you will likely want copy/mount the files in /app/templates to be run against with the filename being specified using TEMPLATE_FILE (or CARD_TEMPLATE_FILE for card info)

Advanced Functionality

You can introduce a preprocess python script if you need to do more advanced functionality. This will run standalone before the regular script is called so you can process or import whatever json objects you need. You need to pass in the full path to a python3 compatible script.

mattermost-notify's People

Contributors

devonwarren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.