Commit f98f0bf8 authored by David Huss's avatar David Huss 💬

Add --userconfig option and display load on server

parent 9e07d4bc
......@@ -38,7 +38,8 @@ class AliasedGroup(click.Group):
@click.group(context_settings=CONTEXT_SETTINGS, cls=AliasedGroup)
def main():
@click.option('--userconfig', '-u', is_flag=True, help="Use user config even if on server")
def main(userconfig):
"""BBBMON is a small CLI utility to monitor bbb usage
\b
......@@ -53,6 +54,7 @@ def main():
@main.command(context_settings=CONTEXT_SETTINGS)
@click.pass_context
@click.option('--userconfig', '-u', is_flag=True, help="Use user config even if on server")
@click.option('--endpoint', '-e', multiple=True, help="Filter by one or more endpoints as named in the user configuration (e.g. [servername]). Order is respected.")
@click.option('--watch', '-w', help="Run repeatedly with the given interval in seconds", type=click.IntRange(2, 2147483647, clamp=True))
@click.option('--leaderboards/--no-leaderboards', default=True, show_default=True, help="Hide or show the meeting leaderboards")
......@@ -64,7 +66,7 @@ def main():
@click.option('--twolines', '-2', is_flag=True, help="Print essentials on two lines")
@click.option('--all', '-a', 'all_', is_flag=True, help="Print all")
@click.option('--fancy/--no-fancy', default=True, show_default=True, help="Use fancy headers")
def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
def meetings(ctx, userconfig, short, all_, twolines, leaderboards, participants, presenter, watch, presenter_id, meetings, endpoint, fancy):
"""View currently active meetings"""
if short:
leaderboards = False
......@@ -75,7 +77,7 @@ def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter,
presenter_id = True
meetings = True
config = init_config()
config = init_config(userconfig)
config.filter_endpoints(endpoint)
if watch is not None:
while watch is not None:
......@@ -98,7 +100,7 @@ def meetings(ctx, short, all_, twolines, leaderboards, participants, presenter,
@click.option('--edit', is_flag=True, help="Open the config in the default editor")
@click.option('--print', 'print_', is_flag=True, help="Print the config to stdout")
@click.option('--path', is_flag=True, help="Print the path to the config")
def config(ctx, new, edit, path, print_):
def config(ctx, userconfig, new, edit, path, print_):
"""Print, show or edit the config"""
user_config_path = get_user_config_path()
......
......@@ -33,6 +33,7 @@ class Config():
def __init__(self):
self.endpoints = []
self.path = None
self.on_server = None
def from_server(self, path: str=SERVER_PROPERTIES_FILE) -> 'Config':
"""
......@@ -49,6 +50,7 @@ class Config():
endpoint = Endpoint(url=bbb_url, secret=secret)
self.endpoints.append(endpoint)
self.path = path
self.on_server = True
return self
def from_config(self, path: str) -> 'Config':
......@@ -66,10 +68,12 @@ class Config():
endpoint = Endpoint(url=bbb_url, secret=secret, name=section)
self.endpoints.append(endpoint)
self.path = path
self.on_server = False
return self
# Fallback for config files without sections
except configparser.MissingSectionHeaderError:
self = self.from_server(path)
self.on_server = False
return self
def filter_endpoints(self, endpoint_options: List[str]) -> 'Config':
......@@ -125,7 +129,7 @@ class Endpoint():
self.name = name
def init_config() -> Optional[Config]:
def init_config(userconfig: bool) -> Optional[Config]:
"""
Read the config either from the servers bigbluebutton.properties-file or from
the user config path. Display a message if neither of these files exist.
......@@ -134,7 +138,7 @@ def init_config() -> Optional[Config]:
user_config_path = get_user_config_path()
# Check if we are on the server and try to read that properties file first
if os.path.isfile(SERVER_PROPERTIES_FILE):
if os.path.isfile(SERVER_PROPERTIES_FILE) and not userconfig:
return Config().from_server()
elif os.path.isfile(user_config_path):
return Config().from_config(user_config_path)
......
......@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import time
import subprocess
import hashlib
from datetime import datetime, timedelta
import requests
......@@ -193,7 +194,7 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
# If there are no meetings, skip to next endpoint
if len(meeting) == 0:
lines = [
"{:^60}".format("bbb there are no meetings currently."),
"{:^60}".format("{} there are no meetings currently.").format(endpoint.name[:3]),
""
]
# Cut above 60 characters fill empty
......@@ -213,11 +214,21 @@ def meetings_twolines(config: Config, watch: int, fancy: bool):
avg_s = avg_s/60./60.
if not fancy:
lines = [
"{} rec / ses ppl mod vid mic ear".format(endpoint.name),
"stats {:>2} / {:<2} {:>3} {:>3} {:>3} {:>3} {:>3}"\
.format(n_recording, n_running, n_participants, n_moderator, n_video, n_voice, n_listeners)
]
if config.on_server:
# If on server get load
w = subprocess.run(["w | head -1 | awk '{print $10}' | sed -e 's/,$//'"], shell=True, stdout=subprocess.PIPE)
w = float(w.stdout.decode('utf-8'))
lines = [
"{} rec / ses ppl mod vid mic ear lod".format(endpoint.name[:3]),
"stats {:>2} / {:<2} {:>3} {:>3} {:>3} {:>3} {:>3} {:.1f}"\
.format(n_recording, n_running, n_participants, n_moderator, n_video, n_voice, n_listeners, w)
]
else:
lines = [
"{} rec / ses ppl mod vid mic ear".format(endpoint.name[:3]),
"stats {:>2} / {:<2} {:>3} {:>3} {:>3} {:>3} {:>3}"\
.format(n_recording, n_running, n_participants, n_moderator, n_video, n_voice, n_listeners)
]
else:
lines = [
"{}: There are {} people in {} meetings for {:.1f}h on average"\
......
[tool.poetry]
name = "bbbmon"
version = "0.1.14"
version = "0.1.15"
description = "A small CLI utility to monitor bbb usage"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
maintainers = ["David Huss <david.huss@hfbk-hamburg.de>"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment