Coder Social home page Coder Social logo

sensu-go-slack-bot's Introduction

Sensu-Go-Slack-bot

TravisCI: TravisCI Build Status

A simple slack bot create using slash commands integration to communicate with Sensu-Go API.

Now with insctructions when received a wrong command:

Go Installation

Install go

Install dependencies dep

Configure

dep ensure -update -v

Run

go build
./sensu-go-slack-bot

Create a App in Slack

Add feature Slash Command with these parameters:

  • Command: /sensu-go
  • Request URL: https://URL/sensu-go-bot/v1/events
  • Short Description: Talk with Monitoring System Sensu Go
  • Usage Hint: [get|execute|silence|describe] [check-name|check|entity] [check-name|server-name] [namespace]

TIP: instead namespace, configure with namespace itself, like: prod|stg.

Add feature "Bots" to this bot.

In Oauth permissions add:

  • CONVERSATIONS chat:write:bot
  • FILES files:write:user

Install these Application in a Channel.

Create an user in Sensu-Go

I create the sensu-go-slack-bot using these commands:

sensuctl user create sensu-go-bot --password "LONGPASSWORD"

sensuctl cluster-role create sensu-go-bot-role --verb get,list,create,update --resource checks,events,silenced,entities --namespace default

sensuctl cluster-role-binding create sensu-go-bot-rolebinding --cluster-role=sensu-go-bot-role --user=sensu-go-bot --namespace default

For test, use sensu-go in docker:

For more details, please consult sensu-go

$ docker run -d --name sensu-backend -p 2380:2380 -p 3000:3000 -p 8080:8080 -p 8081:8081 sensu/sensu:latest sensu-backend start
$ docker run --link sensu-backend -d --name sensu-agent sensu/sensu:latest sensu-agent start --backend-url ws://sensu-backend:8081 --subscriptions webserver,system --cache-dir /var/lib/sensu
$ sensuctl configure -n --username 'admin' --password 'DEFAULT' --namespace default --url 'http://127.0.0.1:8080'

Configure the Slack App to use Request URL in your local environment with ngrok.

Configuration

You need to configure these for local tests or real deployment.

Configure these environment variables:

  • SENSU_USER="sensu-go-bot": same user create in Sensu-Go API.
  • SENSU_URL="https://SENSU-URL:8080": Keep without a slash '/' in the end.
  • SENSU_SECRET: Sensu bot password
  • SLACK_TOKEN: App token from Oauth in Slack (start with xoxb-)
  • SLACK_SIGNING_SECRET: App Signing secret from Slack App.
  • SLACK_CHANNEL: Channel to listen.

In Kubernetes deployments you can use secrets for these 3 last variables.

Docker Build

docker build -t betorvs/sensu-go-slack-bot:test1 -f Dockerfile .

Deploy using Helm and Kubectl

A basic deploy:

kubect create ns sensu-go-slack-bot
kubectl apply -f deployment/sensu-go-slack-bot/secrets.yaml -n sensu-go-slack-bot
helm upgrade --install sensu-go-slack-bot deployment/sensu-go-slack-bot/ --namespace sensu-go-slack-bot

In prod

Configure a proper values-prod.yaml and run:

helm upgrade --install sensu-go-slack-bot deployment/sensu-go-slack-bot/ -f sensu-go-slack-bot/values-prod.yaml --namespace sensu-go-slack-bot

Private repositories

Include ImagePullSecrets in deployment/sensu-go-slack-bot/templates/deployment.yaml.

Extras

Create these extras checks on Sensu-Go to create a possibility to run a small troubleshooting from these slash command:

sensuctl check create list-process --command 'ps -ef' --publish=false --interval 60 --subscriptions linux --handlers default --namespace default

To run on Slack (that channel where it was installed):

/sensu-go execute list-process server-hostname default

To get the results:

/sensu-go get list-process server-hostname default

Executions in Slack

Execute a check:

Get a result:

Special Commands

Describe a entity (Server):

Describe an entity:

/sensu-go describe entity 2e0b36603488 default

Describe a check:

/sensu-go describe check list-process default

Get all checks:

/sensu-go get all check default

Get all entities:

/sensu-go get all entity default

Reference

https://medium.com/@emilygoldfein/creating-slack-slash-commands-using-go-3cea3b3f0920

https://api.slack.com/docs/verifying-requests-from-slack

https://github.com/nlopes/slack

sensu-go-slack-bot's People

Watchers

 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.