Skip to content

Instantly share code, notes, and snippets.

@Tafkas
Last active April 7, 2022 20:53
Show Gist options
  • Save Tafkas/dc0bd9d847e881826ccfefa142063658 to your computer and use it in GitHub Desktop.
Save Tafkas/dc0bd9d847e881826ccfefa142063658 to your computer and use it in GitHub Desktop.
A munin plugin for to monitor online presence in Slack
#!/usr/bin/env python
"""
slack_user_munin - A munin plugin for to monitor online presence 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_online_presence():
slack = Slacker(os.environ['slack_token'])
response = slack.users.list(presence=True)
all_members = response.body['members']
status = {}
for member in all_members:
if not member.get('deleted') and not member.get('is_bot'):
presence = member.get('presence')
if presence not in status:
status[presence] = 0
status[presence] += 1
print 'online.value %s' % (status['active'])
def print_config():
print "graph_title Online Slack Users"
print "graph_vlabel number of users"
print "graph_category slack"
print "graph_info This graph shows the online Slack users."
print "graph_scale no"
print "online.label online"
print "online.type GAUGE"
print "online.draw AREA"
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_online_presence()
except:
sys.exit("Couldn't retrieve slack online presence")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment