Chatops: Troubleshooting a server with chatbot
Slackbot

Chatops: Troubleshooting a server with chatbot

ChatOps is a collaboration model that connects people, tools, process, and automation into a transparent workflow using chat conversation.

Here are few use cases:

  • If you are troubleshooting any problem, slack chatbot can be useful if you want everyone to see the specific logs/system metrics around the problem.
  • Chatbot can be useful for Alert validation, sometimes alerts trigger due to network fluctuation or routine tasks. Using ChatOps, you can verify whether an alert is, in fact, a threat requiring investigation or is something harmless.
  • You are an application developer and need to search for logs in staging/production for your app and are currently within the slack interface, without logging into the servers.
  • Troubleshooting a Server from your phone, when you are not on your keyboard.
I have created a chatbot using slack and python library SlackClient to 
implement the above mentioned use cases. It uses fabric module to execute the
command on remote hosts in AWS EC2.

How to Build a ChatOps Bot with Slack and Python

Slack is a messaging app that has exploded in popularity among all sorts of teams. The Slack platform allows developers to implement and integrate their own chatbots.

Slack has a variety of APIs that suit various purposes, but the one that I have used for creating bot is the Slack RTM (Real Time Messaging) API.

To write the bot using the Slack RTM API, I have used the official Slack client for python. RTM chatbots rely on WebSockets and long term connections. If you don't prefer to use long lived connection you can use other Slack API.

The following figure provides an overview of these different parts and how they interact together.

Requirements for Slackbot

  1. Python 3
  2. pip to handle Python application dependencies.
  3. Free Slack account with a team on which you have API access
  4. Official Python slackclient code library built by the Slack team and fabric3 library to execute the command on remote machine.
  5. Slack API testing token

You can find the code on Github.

Getting started with the slackbot

You can send messages to bot in following order:

@<slackbot> command <action> host <hostname>

  • To check Free Memory across AWS EC2 Instances.
  • To check Load Average
  • To display info about CPU architecture.
  • Search for pattern in the log file
  • Replying to the thread in slack.
  • Get information about the active process.

Your comments and suggestions are welcome.


To view or add a comment, sign in

More articles by Vivek Grover

  • IPTables vs IPVS in kubernetes

    Working in a large scale environment can bring some performance challenges when no of services grows beyond 1,000…

    3 Comments
  • Updating prometheus rules with golang in kubernetes

    Recently I have been looking into how multiple teams can update the prometheus rules from one place, I figured out by…

    2 Comments
  • Kubernetes Custom Scheduler in Python

    Kubernetes is a popular open source platform for container orchestration. It is highly configurable, extensible and…

    6 Comments
  • Managing Jenkins with Python

    Jenkins is an open source automation platform which allows continuous integration and continuous delivery. Sometimes…

    2 Comments
  • Jenkins Pipeline integration with Slack

    Recently adoption of CI/CD changed how developers and testers ship software. The CI/CD pipeline is one of the best…

    6 Comments

Others also viewed

Explore content categories