Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A munin plugin for to monitor channel count in Slack
#!/usr/bin/env python
"""
slack_channel_munin - A munin plugin for to monitor channel count in Slack
Copyright (C) 2015 Christian Stade-Schuldt
Author: Christian Stade-Schuldt
Like Munin, this plugin is licensed under the GNU GPL v2 license
http://www.opensource.org/licenses/GPL-2.0
Add the following section to your munin-node's plugin configuration:
[slack_*]
env.slack_token [slack_token]
This plugin supports the following munin configuration parameters:
#%# family=auto contrib
#%# capabilities=autoconf
"""
import os
import sys
import urllib3
from slacker import Slacker
urllib3.disable_warnings()
def get_channel_count():
slack = Slacker(os.environ['slack_token'])
response = slack.channels.list()
channels = response.body['channels']
channel_count = {}
for channel in channels:
if channel.get('is_archived'):
if 'is_archived' not in channel_count:
channel_count['is_archived'] = 0
channel_count['is_archived'] += 1
else:
if 'active' not in channel_count:
channel_count['active'] = 0
channel_count['active'] += 1
for s in ['is_archived', 'active']:
print '%s.value %s' % (s, channel_count[s])
def print_config():
print "graph_title Slack Channels"
print "graph_vlabel number of channels"
print "graph_category slack"
print "graph_order is_archived, active"
print "graph_info This graph shows the number of Slack channels."
print "graph_scale no"
print "is_archived.label is_archived"
print "is_archived.type GAUGE"
print "is_archived.draw AREA"
print "active.label active"
print "active.type GAUGE"
print "active.draw STACK"
if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print_config()
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
print 'yes'
elif len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == 'fetch':
# Some docs say it'll be called with fetch, some say no arg at all
try:
get_channel_count()
except:
sys.exit("Couldn't retrieve slack channel count")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.