Skip to content

Instantly share code, notes, and snippets.

@bwurst
Created April 24, 2020 05:31
Show Gist options
  • Save bwurst/7f94e0392c75d273a08d1e686182fc5e to your computer and use it in GitHub Desktop.
Save bwurst/7f94e0392c75d273a08d1e686182fc5e to your computer and use it in GitHub Desktop.
Simple python script to show current usage of big blue button from root@localhost
#!/usr/bin/python3
import sys
import subprocess
import re
import hashlib
import requests
from xml.etree import ElementTree
###
## bbb-conf --secret
#
# URL: https://.../bigbluebutton/
# Secret: ....
#
verbose = False
if len(sys.argv) > 1 and sys.argv[1] == '-v':
verbose = True
tmp = subprocess.run(['/usr/bin/bbb-conf', '--secret'], stdout=subprocess.PIPE, universal_newlines=True)
#PYTHON 3.7 tmp = subprocess.run(['/usr/bin/bbb-conf', '--secret'], capture_output=True, text=True)
output = tmp.stdout
URL = None
secret = None
for line in output.splitlines():
m = re.search('URL: (?P<URL>.*/bigbluebutton/)', line)
if m:
URL = m.group('URL')
continue
m = re.search('Secret: (?P<secret>.*)$', line)
if m:
secret = m.group('secret')
if not URL or not secret:
print('error getting URL and/or secret. Is "bbb-conf --secret" returning it?')
APIURL=URL + 'api/'
apimethod='getMeetings'
querystring=''
h = hashlib.sha1((apimethod+querystring+secret).encode('utf-8'))
checksum = h.hexdigest()
if len(querystring) > 0:
querystring = querystring + '&'
requesturl = APIURL + apimethod + '?' + querystring + 'checksum=' + checksum
response = requests.get(requesturl)
tree = ElementTree.fromstring(response.content)
if tree.find('returncode').text != 'SUCCESS':
print('error getting API data')
sys.exit(1)
meetings = tree.find('meetings')
num_meetings = 0
num_users = 0
num_video = 0
for m in meetings.iter('meeting'):
meetname = m.find('meetingName').text
meetid = m.find('meetingID').text
participants = m.find('participantCount').text
video = m.find('videoCount').text
meta = m.find('metadata')
origin = meta.find('bbb-origin').text
if meta.find('bbb-context') is not None:
meetname = meta.find('bbb-context').text + ' / ' + meetname
print('--[ %s ]---< %s / %s >---' % (meetname, meetid, origin))
if verbose:
for a in m.find('attendees').iter('attendee'):
v = ' '
if a.find('hasVideo').text == 'true':
v = 'V'
audio = ' '
if a.find('hasJoinedVoice').text == 'true':
audio = 'A'
print(' +--[ %-10s ]--(%s%s)-> %s' % (a.find('role').text, v, audio, a.find('fullName').text))
print(' +==> %2s participants' % (participants,))
print(' +==> %2s videostreams' % (video,))
num_meetings += 1
num_users += int(participants)
num_video += int(video)
print('total: %2i meetings, %2i users, %2i videostreams' % (num_meetings, num_users, num_video))
@langfingaz
Copy link

Hey there, thanks a lot for this gist. It inspired me to write a python project for logging and plotting BBB meeting statistics:

https://codeberg.org/langfingaz/bbb-status

It can also be built and run as docker image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment