ChatOps Bot: Query Node Info Without Manual Login

dennyzhang
Jul 23, 2017 · 2 min read

Try Your Best To Avoid Any SSH Operations. Yes, I deeply believe in this principle. But my reality is the automation is never so perfect. I still need to login and check system status sometimes. Though the chance is rare.
It may happen at nights or even when I’m on vacation. So what I can do? Just carry my laptop with me wherever I go? This is certainly bad, isn’t it?

We’re living in the world of ChatOps. And mobile phones dominate our daily life (Sadly!) So why don’t we implement a ChatOps bot for this? Here comes a slack command: /chatqueryhost. (Note: The solution is not limited to Slack)


Original Article: https://dennyzhang.com/chatqueryhost

1. Install node_usage.py For Each Nodes.

It will get status for each node as a json output.

  • OS resource utilization: RAM, CPU, and disk.
  • [Optional] Get service status, or tail log files.

(See why I choose Python over Shell: GoodBye Shell, Hello Python!)

2. Start A Web Server, Serving Slack Requests.

It will start a webserver with Python flask + uwsgi.

  • Get requests from Slack input.
  • Run remote ssh command, which is literally node_usage.py.

Code is GitHub. [1] (Warning. I admit: It’s not well documented. Just F.Y.I).

You can design and implement your own ChatOps solution for this.

And here are some suggestions I’ve for you, my friends:

  1. Slack command must return within 3 seconds.[2]
  2. Instead of running ssh commands, it’s safer to wrap py script as agents. Then the agent serves as a tcp or http server.
  3. Support find node by fuzzy match. Your env may have tens of nodes, if not hundereds of. So support people to identify node by giving part of hostname.

Footnotes:

[1] https://github.com/DennyZhang/chatops_slack

[2] https://api.slack.com/slash-commands#responding_to_a_command


Check more in My LinkedIn Discussion!

(Connect with me in LinkedIn)


dennyzhang

Written by

DevOps Guy & Blogger: https://www.dennyzhang.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade