autobot

module
v1.0.0-beta.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2019 License: Apache-2.0

README

Autobot

Autobot

gopherbadger-tag-do-not-edit Build Status Go Report Card License Apache 2 Taylor Swift Volkswagen

Autobot is your nice and friendly bot. He is here to save you from the 👹 decepticons of #devops and other evil.

🙈 Contributions are welcome.

Features

  • Plugable architecture via Pub/Sub Plugins
  • Message queue for the bot inbox /outbox via embedded NATS Streaming
  • Protobuf for unified messages
  • Plugins (e.g. Slack) but many more that you can build

Architecture

Autobot is made of a server and plugins. The server starts an embedded Nats Streaming Server. The plugins subscribe and publish message to the provided queues. They can be run in their custom Docker containers. The plugins are started with an environment that exposes two channels for publishing and subscribing to messages and some more information. The plugins package exposed functions to subscribe to the inbox channel, which should be used to publish messages from message services and outbox which should publish to these services (e.g. Slack or Microsoft Teams).

    Slack /                                                                
 Microsoft Teams               +-----------------------------------+    
        ^                    +-|---------------------------------+ |    
        |                    | |            Server               | |    
        |                    | | +---------------+               | |    
 +------|---------\          | | |     NATS      |               | |    
 |   Plugin    |   -----\    | | |               |               | |    
 +-------------<-\       -----\| |+-------------+|               | |    
                  ----\    ------->   Inbox     ||               | |    
                   -------\  | | |+-------------+|               | |    
 +-------------<--/        ----\ |+-------------+|               | |    
 |   Plugin    |         --------->   Outbox    ||               | |    
 +----------------------/    | | |+-------------+|               | |    
                             | | +---------------+               | |    
                             | +-----------------------------------+    
                             +-----------------------------------+  
Clustering

NATS Streaming Server supports clustering and data replication. Because Autobot embedds the streaming server it supports clustering as the mechanism for high availability. Autobot supports the two modes of clustering. We recommend the "auto" mode in which you specify the list of peers to each started node. They elect a leader and start the replication. Because it uses the RAFT consensus algorithm it needs an uneven number of peers in the cluster. 3 or 5 are sufficient.

# this create a cluster consiting of 3 nodes
docker-compose up

Plugins

godoc.org for writing plugins

There are some example plugins

Plugins are either run and managed by the controller or they are run as individual processes in a container and are individually managed. The --plugins flag specifies directories or individual plugins to be run and managed by the controller.

Plugins can be either configured by the automatically exposed command line parameters or the prefixed environment variables.

Example for the Slack Plugin:

SLACK_TOKEN=
AUTOBOT_CLUSTER_ID=autobot
AUTOBOT_CLUSTER_URL=nats://controller:4222
AUTOBOT_LOG_FORMAT=json
AUTOBOT_LOG_LEVEL=info
AUTOBOT_DEBUG=true
AUTOBOT_VERBOSE=true

There are two log formats supported text (default) and json. The log levels reflect the logrus levels.

Example

The images are hosted on Docker Hub you should change .env for your specific setup

This example uses Docker Compose and you will need a Slack Bot Token (e.g. xob-xxxx).

You should provide this token in the .env file. Which is used to configure the plugins containers. Because Autobot is using pub/sub to communicate with its plugins they can be run independently in their own containers. Anders Normal contains the plugins in containers.

# start the containers
docker-compose up

You should now see your Slack Bot connect in your Workspace and can send him a direct message which he will respond to with hello world.

Development

we use Picasso for build automation

You can build the Protobuf by running

picasso proto

We use a specific version of proto package generator. In order to build it with this version you will have to install it as follows

GIT_TAG="v1.2.0" # change as needed
go get -d -u github.com/golang/protobuf/protoc-gen-go
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
go install github.com/golang/protobuf/protoc-gen-go

The server is build by running

picasso build/server

The options of the server can be shown by ./server --help.

License

Apache 2.0

Directories

Path Synopsis
pkg
plugins
Package plugins provides the functionality to subscribe, and publish message according to the plugin.proto.
Package plugins provides the functionality to subscribe, and publish message according to the plugin.proto.
plugins/filters
Package filters provides functionality to filter messages.
Package filters provides functionality to filter messages.
plugins/runtime
Package runtime contains functionality for runtime information of a plugin.
Package runtime contains functionality for runtime information of a plugin.
plugins
plugin-slack command
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL