Giter VIP home page Giter VIP logo

marathon-slack's Introduction

marathon-slack

NSP Status Build Status

Listen to Marathon's Event Bus and send selected event types to a Slack WebHook!

Preparations

The only preparation that needs to be performed is to add a new WebHook for your Slack team. You can do this by adding an Incoming Webhook via the Add configuration button on the Slack configuration page.

In the next step after clicking the button, you'll have to select the Slack channel to which you want to post the Marathon Event Bus messaged to. Either choose an existing one, or create a new channel like #marathon.

After you did that, you'll be guided to an overview page for your new Slack Webhook. Please copy the Webhook URL, because you'll need it in the next step. If you want, you can go back to the Incoming Webhooks overview page and select the newly created Webhook again. Then, scroll down to the Integration settings and customize the name and the icon for this integration if you want. To add a name and icon is not mandatory to be able to use marathon-slack.

Usage

You can configure marathon-slack via environment variables.

Environment variables

  • MARATHON_HOST: The Marathon Host (hostname or ip address) where Marathon lives. Default is master.mesos, so if you don't use Mesos DNS you'll have to specify this. If you want to use basic auth with Marathon, use user:[email protected] as value.
  • MARATHON_PORT: The port under which Marathon is running. Default is 8080.
  • MARATHON_PROTOCOL: The protocol to access the Marathon API with. Can be either http or https. Default is http.
  • SLACK_WEBHOOK_URL: The Slack Webhook URL (mandatory).
  • SLACK_CHANNEL: The name of the Slack channel to send the messages to (must contain #). Default is #marathon.
  • SLACK_BOT_NAME: The name of the Slack bot to send the messages from. Default is Marathon Event Bot.
  • EVENT_TYPES: The comma-separated list of event types you want to have sent to Slack. By default, all the below events are activated.
  • TASK_STATUSES: The comma-separated list of Mesos TaskStatuses that you want to have sent to Slack. By default, the below statuses are activated if the environment variable PUBLISH_TASK_STATUS_UPDATES is set to true.
  • PUBLISH_TASK_STATUS_UPDATES: Can be set to true if the TaskStatus update message should be published. Default is false.
  • PORT: The port number on which the API should listen on. Normally, this will be automatically provided by Marathon. Default is 3000.
  • APP_ID_REGEXES: A string regular expression to filter events by their Marathon App Id. For example to send a slack message for only apps with id "*-production". If you want multiple regular expressions, you can concatenate them with a comma.

Event types

Each of the following event types is pushed to Slack if not configured via the EVENT_TYPES environment variables:

  • deployment_info
  • deployment_success
  • deployment_failed
  • deployment_step_success
  • deployment_step_failure
  • group_change_success
  • group_change_failed
  • failed_health_check_event
  • health_status_changed_event
  • unhealthy_task_kill_event

If PUBLISH_TASK_STATUS_UPDATES is set to true, the status_update_event event is handled as well. Please be aware that this may cause a lot of messages to be delivered to the specified Slack channel! If activated, you can use the TASK_STATUSES environment variable to specify the list of TaskStatuses you want to publish. If not, all the task status update messages will be published:

  • TASK_STAGING
  • TASK_STARTING
  • TASK_RUNNING
  • TASK_FINISHED
  • TASK_FAILED
  • TASK_KILLING
  • TASK_KILLED
  • TASK_LOST

An individual, formatted Slack message is currently only for these event types. If another event is received, it will be displayed with a default formatting of event type and timestamp.

Please also see the Marathon Event Bus docs.

Running

Installing on DC/OS as package

Via CLI

You need to create an options.json file locally, before you can install the package. This is because you have to add your individual Slack WebHook URL to the configuration.

An example:

{
  "marathon-slack": {
    "slack_webhook_url": "https://hooks.slack.com/services/...YOUR_WEBHOOK_URL..."
  }
}

The above is the minimal configuration necessary to start the marathon-slack package. You can also customize the Slack channel (property slack_channel) or the list of event types to be published (property event_types). For the full list of configuration options, see the marathon.json.mustache file.

Once you prepared the options.json file, you can install the package with the following command:

dcos package install marathon-slack --options options.json

You should then see the service marathon-slack running on the services tab in the DC/OS UI.

Via Universe

In the DC/OS Universe tab, either search for slack, or scroll down the list of package until you find the marathon-slack package. Then, click on the Install button. Once the modal window pops up, click on Advanced Installation. You can customize the settings for the package, the only thing you have to configure is the slack_webhook_url. This has to fit to the Slack WebHook's URL you created before. Then click on Review and Install, and if everything is ok, on Install.

You should then see the service marathon-slack running on the services tab in the DC/OS UI.

Installing via Marathon

You can run this on Marathon like this:

{
  "id": "/marathon-slack",
  "cpus": 0.1,
  "mem": 128,
  "disk": 0,
  "instances": 1,
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "tobilg/marathon-slack:0.4.5",
      "network": "HOST",
      "privileged": false,
      "forcePullImage": true
    }
  },
  "env": {
    "SLACK_WEBHOOK_URL": "YOUR_WEBHOOK_URL"
  },
  "labels":{
    "MARATHON_SINGLE_INSTANCE_APP": "true"
  },
  "upgradeStrategy":{
    "minimumHealthCapacity": 0,
    "maximumOverCapacity": 0
  },
  "portDefinitions": [
    {
      "port": 0,
      "protocol": "tcp",
      "name": "api"
    }
  ],
  "requirePorts": false,
  "healthChecks": [
    {
      "protocol": "HTTP",
      "portIndex": 0,
      "path": "/health",
      "gracePeriodSeconds": 5,
      "intervalSeconds": 20,
      "maxConsecutiveFailures": 3
    }
  ]
}

Please replace YOUR_WEBHOOK_URL with your real Webhook URL.

It's probably useful to limit the EVENT_TYPES to not receive a huge amount of messages. For example, deployment_info,deployment_success,deployment_failed,failed_health_check_event,health_status_changed_event,unhealthy_task_kill_event should cover the most important events, without adding too much details.

marathon-slack's People

Contributors

chadleeshaw avatar marcoreni avatar tobilg avatar vivekjuneja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

marathon-slack's Issues

Not able to deploy marathon-slack with latest version.

I'm trying to deploy marathon/slack latest version i.e. toblig/marathon-slack:0.4.3
image
but not able to deploy. Every time i'm trying to deploy with latest version, deployment gets suspended.
I checked in the log but couldn't figure out what's the issue

events.js:160
throw er; // Unhandled 'error' event
^

Error: Listen EADDRNOTAVAIL 172.31.29.125:31748
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at Server._listen2 (net.js:1245:19)
at listen (net.js:1294:10)
at net.js:1404:9
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:81:10)

npm ERR! Linux 3.13.0-119-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v6.10.3
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: node index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the marathon-slack package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs marathon-slack
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls marathon-slack
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/marathon-slack/npm-debug.log

Though i'm able to deploy the earlier version till toblig/marathon-slack:0.3.1 but after this version i'm not able to deploy.
I'm trying to use the APP_ID_REGEXES env variable to filter the events which is only available in the latest release

Any help regarding this issue would be appreciable.

Readme suggests MARATHON_HOST and image version 0.1.3 - However MARATHON_URL is used in version 0.1.3

In the Readme, we can see

### Environment variables

* `MARATHON_HOST`: The Marathon Host (hostname or ip address) where Marathon lives. Default is `leader.mesos`, so if you don't use Mesos DNS you'll have to specify this. 

Also:

### Installing via Marathon

You can run this on Marathon like this:

{
  "id": "/marathon-slack",
  "cpus": 0.1,
  "mem": 128,
  "disk": 0,
  "instances": 1,
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "tobilg/marathon-slack:0.1.3",
      "network": "HOST",
      "privileged": false,
      "parameters": [],
      "forcePullImage": true
    }
  },
  "env": {
    "SLACK_WEBHOOK_URL": "YOUR_WEBHOOK_URL"
  }
}

It's not obvious that tobilg/marathon-slack:0.1.3 is expecting MARATHON_URL environment variable, and that tobilg/marathon-slack:latest is expecting MARATHON_HOST. Furthermore Mesosphere Universe refers to 0.1.3 (https://github.com/mesosphere/universe/blob/version-3.x/repo/packages/M/marathon-slack/1/resource.json).

I think Readme should specify that depending on which image version is running marathon-slack, the environment variable is not the same. Would make it clearer even if the Readme of this commit https://github.com/tobilg/marathon-slack/tree/e5d89a6280791cfc86b61b868461ed06baeb3a49 is correct given that it's the commit refering to the 0.1.3 release.

Control Slack SPAM

Is there a way to filter the event if it's a repeat message? For example if a health check is failing it will SPAM Slack every time it fails the health check. Personally, I just want one message until it's health changes.

error in APP_ID_REGEXES

I gave APP_ID_REGEXES as . I am getting below error.

/usr/local/marathon-slack/lib/MarathonSlackBridge.js:71
console.log("The provided RegExp " + regExp + " isn't a valid regular expression!");
^

ReferenceError: regExp is not defined
at new MarathonSlackBridge (/usr/local/marathon-slack/lib/MarathonSlackBridge.js:71:54)
at Object. (/usr/local/marathon-slack/index.js:14:29)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3

npm ERR! Linux 3.10.0-514.26.2.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v6.11.0
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: node index.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the marathon-slack package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs marathon-slack
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls marathon-slack
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/marathon-slack/npm-debug.log

Suscribe error

Hi,

I'm getting this error when I start marathon-slack in DC/OS, this was working a while ago, and suddenly it stopped working.

> [email protected] start /usr/local/marathon-slack
> node index.js

Express server listening on port 11681 on 10.90.2.9
Subscribed to the Marathon Event Bus: {"timestamp":1556214433563,"message":"Subscribed to the Marathon Event Bus"}
Error: {"timestamp":1556214433.566,"message":{"type":"error"}}
Subscribed to the Marathon Event Bus: {"timestamp":1556214434581,"message":"Subscribed to the Marathon Event Bus"}
Error: {"timestamp":1556214434.582,"message":{"type":"error"}}
Subscribed to the Marathon Event Bus: {"timestamp":1556214435596,"message":"Subscribed to the Marathon Event Bus"}
Error: {"timestamp":1556214435.597,"message":{"type":"error"}}

Since then, I don't get any notifications in the channel where this is supposed to send the events.

If I send a curl request to listen to the events on mesos api, everything works fine and events are listed if any update happens.

Not sure what could be causing this, and / or how to debug it.

Add application information to deployment messages

It'd be helpful to see what application is being deployed when getting status messages. Currently it's hard to correlate the deployment IDs to underlying applications (especially if the deployment completes - it's difficult to find out information from the UI, you have to use the API - which is a lot of effort).

[11:10] 
Deployment success
The deployment `b5e6bf30-2455-4388-850f-963fe370fddc` was completed successfully at `2017-05-10 18:10:16.636`
Today at 11:10 AM```

Slack message shows step as: "undefined"

Seeing this in slack channel:

Deployment info
The deployment bec743f2-dc4f-42fd-b389-be6f096f5f4a triggered the following steps:

  1. undefined

Running on dc/os 1.7. Let me know if you need more info!

Does not work properly when forked

This issue is really strange to me - I hope I'm not missing something obvious.

I forked this repo and setup an automated docker build. However, when I run my version of the build I get:

Got an error on 1486081237.669:
{"type":"error"}
Got an error on 1486081238.7:
{"type":"error"}
Got an error on 1486081239.704:
{"type":"error"}
Got an error on 1486081240.724:
{"type":"error"}
Got an error on 1486081241.735:
{"type":"error"}
Got an error on 1486081242.754:
{"type":"error"}
Got an error on 1486081243.76:
{"type":"error"}

With your build, however, it works correctly and I see Subscribed to the Marathon Event Bus.

I tried building the 0.3.0 tag and ran into the same issue. The only line I'm changing in the marathon deploy file is:

-  "image": "tobilg/marathon-slack:0.3.0"
+  "image": "acook/marathon-slack:0.3.0"

Any ideas why?

Unable to start on marathon 1.5.2

I'm running Marathon 1.5.2 with Mesos 1.4.1

Trying to bring up marathon-slack 0.4.0 and its constantly failing to deply here are my stdout/stderr logs

--- stderr ---
I1208 18:02:29.702464 9335 exec.cpp:162] Version: 1.4.1
I1208 18:02:29.704879 9362 exec.cpp:237] Executor registered on agent f9eb53b4-b3dd-4731-a44c-7f1e39139d67-S2
I1208 18:02:29.705446 9349 executor.cpp:120] Registered docker executor on prod-mesos-slave-01.aws.octanelending.com
I1208 18:02:29.705591 9354 executor.cpp:160] Starting task marathon-slack.f4123b7e-dc41-11e7-9487-02707643caf4
I1208 18:03:46.645203 9362 executor.cpp:269] Received killTask for task marathon-slack.f4123b7e-dc41-11e7-9487-02707643caf4
I1208 18:03:47.891160 9364 process.cpp:1068] Failed to accept socket: future discarded

--- stdout ---

[email protected] start /usr/local/marathon-slack
node index.js

Event { type: 'error' }
Express server listening on port 31314 on 127.0.0.1
Event { type: 'error' }
Event { type: 'error' }
Event { type: 'error' }
Event { type: 'error' }
Event { type: 'error' }
Event { type: 'error' }
Event { type: 'error' }

{
  "id": "/marathon-slack",
  "cpus": 0.1,
  "mem": 128,
  "disk": 0,
  "instances": 1,
  "user": "octane",
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "tobilg/marathon-slack:0.4.0",
      "network": "HOST",
      "privileged": false,
      "forcePullImage": true
    }
  },
  "env": {
    "MARATHON_HOST": "marathon.mesos.prod",
    "MARATHON_URL": "marathon.mesos.prod",
    "SLACK_WEBHOOK_URL": "https://hooks.slack.com/services/xxx",
    "SLACK_CHANNEL": "#tech-infrastructure",
    "EVENT_TYPES": "deployment_info,deployment_success,deployment_failed,failed_health_check_event,health_status_changed_event,unhealt>
  },
  "labels":{
    "MARATHON_SINGLE_INSTANCE_APP": "true"
  },
  "upgradeStrategy":{
    "minimumHealthCapacity": 0,
    "maximumOverCapacity": 0
  },
  "portDefinitions": [
    {
      "port": 0,
      "protocol": "tcp",
      "name": "api"
    }
  ],
  "requirePorts": false,
  "healthChecks": [
    {
      "protocol": "HTTP",
      "portIndex": 0,
      "path": "/health",
      "gracePeriodSeconds": 5,
      "intervalSeconds": 20,
      "maxConsecutiveFailures": 3
    }
  ]
}

Unable to run the app with MESOS_HTTP health check

I tried to use the new best practice health check of marathon - MESOS_HTTP.
This health check delegate the health check to the mesos agent which execute the health check with localhost (127.0.0.1).

Currently, the app is listening to the IP address of the host only

ipAddress: process.env.HOST || "0.0.0.0",

The solution to support the new health check is to remove the IP address from here:

const server = app.listen(apiOptions.port, apiOptions.ipAddress, function () {

The marathon based health checks deprecated and will be removed by Marathon docs

Important: Marathon-based health checks are deprecated and will be removed in a future version. See the 1.4.0 release notes for more information.

Mattermost support

Any chance to having support for mattermost incoming webhook? I tried replacing the slack webhook URL with the mattermost and got the following error:

[email protected] start /usr/local/marathon-slack
node index.js

Express server listening on port 30143
Error: {"timestamp":1594352985.86,"message":{"type":"error","status":302}}

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.