mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-08-07 22:53:15 +00:00
code passes flake8 now
This commit is contained in:
parent
343612874d
commit
3c94aae387
1 changed files with 22 additions and 16 deletions
|
@ -46,11 +46,13 @@ import subprocess
|
||||||
import re
|
import re
|
||||||
import hashlib
|
import hashlib
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
from urllib.error import URLError, HTTPError
|
||||||
import os
|
import os
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
bbbconf_path = "/usr/bin/bbb-conf"
|
bbbconf_path = "/usr/bin/bbb-conf"
|
||||||
|
|
||||||
|
|
||||||
def config():
|
def config():
|
||||||
""" autoconfig values """
|
""" autoconfig values """
|
||||||
print("graph_title BigBlueButton")
|
print("graph_title BigBlueButton")
|
||||||
|
@ -68,13 +70,14 @@ def bbb_stats():
|
||||||
URL = None
|
URL = None
|
||||||
secret = None
|
secret = None
|
||||||
|
|
||||||
## find out url and secret from local bbb instance
|
# find out url and secret from local bbb instance
|
||||||
if os.path.exists(bbbconf_path):
|
if os.path.exists(bbbconf_path):
|
||||||
## Ubuntu 16.04 with Python 3.5 is recommended for bbb 2.2.x
|
# Ubuntu 16.04 with Python 3.5 is recommended for bbb 2.2.x
|
||||||
if sys.version_info.major == 3 and sys.version_info.minor < 7:
|
if sys.version_info.major == 3 and sys.version_info.minor < 7:
|
||||||
tmp = subprocess.run([bbbconf_path, '--secret'], stdout=subprocess.PIPE, universal_newlines=True)
|
tmp = subprocess.run([bbbconf_path, '--secret'],
|
||||||
|
stdout=subprocess.PIPE, universal_newlines=True)
|
||||||
else:
|
else:
|
||||||
tmp = subprocess.run([bbbconf_path, '--secret'], capture_output=True, text=True)
|
tmp = subprocess.run([bbbconf_path, '--secret'], capture_output=True, text=True)
|
||||||
output = tmp.stdout
|
output = tmp.stdout
|
||||||
|
|
||||||
for line in output.splitlines():
|
for line in output.splitlines():
|
||||||
|
@ -90,13 +93,12 @@ def bbb_stats():
|
||||||
print('error getting URL and/or secret. Is "bbb-conf --secret" returning it?')
|
print('error getting URL and/or secret. Is "bbb-conf --secret" returning it?')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# prepare api request
|
||||||
## prepare api request
|
|
||||||
APIURL = URL + 'api/'
|
APIURL = URL + 'api/'
|
||||||
apimethod = 'getMeetings'
|
apimethod = 'getMeetings'
|
||||||
querystring = ''
|
querystring = ''
|
||||||
|
|
||||||
h = hashlib.sha1((apimethod+querystring+secret).encode('utf-8'))
|
h = hashlib.sha1((apimethod + querystring + secret).encode('utf-8'))
|
||||||
checksum = h.hexdigest()
|
checksum = h.hexdigest()
|
||||||
|
|
||||||
if len(querystring) > 0:
|
if len(querystring) > 0:
|
||||||
|
@ -104,21 +106,27 @@ def bbb_stats():
|
||||||
|
|
||||||
requesturl = APIURL + apimethod + '?' + querystring + 'checksum=' + checksum
|
requesturl = APIURL + apimethod + '?' + querystring + 'checksum=' + checksum
|
||||||
|
|
||||||
## make api request
|
# make api request
|
||||||
response = urllib.request.urlopen(requesturl)
|
response = urllib.request.urlopen(requesturl)
|
||||||
responsedata = response.read()
|
responsedata = response.read()
|
||||||
try:
|
try:
|
||||||
tree = ElementTree.fromstring(responsedata)
|
tree = ElementTree.fromstring(responsedata)
|
||||||
if tree.find('returncode').text != 'SUCCESS':
|
except HTTPError as e:
|
||||||
print('error getting API data')
|
|
||||||
sys.exit(1)
|
|
||||||
except:
|
|
||||||
print('There was an error with the recieved data from bbb api.')
|
print('There was an error with the recieved data from bbb api.')
|
||||||
|
print('Error code: ', e.code)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
except URLError as e:
|
||||||
|
print('There was an error with the recieved data from bbb api.')
|
||||||
|
print('Reason: ', e.reason)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
if tree.find('returncode').text != 'SUCCESS':
|
||||||
|
print('There was an error within the API data')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
meetings = tree.find('meetings')
|
meetings = tree.find('meetings')
|
||||||
|
|
||||||
## get numbers from api response
|
# get numbers from api response
|
||||||
num_meetings = 0
|
num_meetings = 0
|
||||||
num_users = 0
|
num_users = 0
|
||||||
num_video = 0
|
num_video = 0
|
||||||
|
@ -128,7 +136,6 @@ def bbb_stats():
|
||||||
|
|
||||||
for m in meetings.iter('meeting'):
|
for m in meetings.iter('meeting'):
|
||||||
meetname = m.find('meetingName').text
|
meetname = m.find('meetingName').text
|
||||||
meetid = m.find('meetingID').text
|
|
||||||
participants = m.find('participantCount').text
|
participants = m.find('participantCount').text
|
||||||
video = m.find('videoCount').text
|
video = m.find('videoCount').text
|
||||||
listeners = m.find('listenerCount').text
|
listeners = m.find('listenerCount').text
|
||||||
|
@ -136,7 +143,6 @@ def bbb_stats():
|
||||||
moderators = m.find('moderatorCount').text
|
moderators = m.find('moderatorCount').text
|
||||||
|
|
||||||
meta = m.find('metadata')
|
meta = m.find('metadata')
|
||||||
origin = meta.find('bbb-origin').text
|
|
||||||
if meta.find('bbb-context') is not None:
|
if meta.find('bbb-context') is not None:
|
||||||
meetname = meta.find('bbb-context').text + ' / ' + meetname
|
meetname = meta.find('bbb-context').text + ' / ' + meetname
|
||||||
|
|
||||||
|
@ -147,7 +153,7 @@ def bbb_stats():
|
||||||
num_speakers += int(speakers)
|
num_speakers += int(speakers)
|
||||||
num_moderators += int(moderators)
|
num_moderators += int(moderators)
|
||||||
|
|
||||||
## finally print everything
|
# finally print everything
|
||||||
print('meetings.value %2i' % (num_meetings))
|
print('meetings.value %2i' % (num_meetings))
|
||||||
print('users.value %2i' % (num_users))
|
print('users.value %2i' % (num_users))
|
||||||
print('videostreams.value %2i' % (num_video))
|
print('videostreams.value %2i' % (num_video))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue