diff --git a/bbbmon/bbbmon.py b/bbbmon/bbbmon.py index c3ec68689ea995e0ca2687e8067b40091c5910cf..391e78fddf885ea4df359756c96df67a8a393bee 100755 --- a/bbbmon/bbbmon.py +++ b/bbbmon/bbbmon.py @@ -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() diff --git a/bbbmon/configuration.py b/bbbmon/configuration.py index 961ebec0a38376f37fe321878ec686edfdabef19..70b47f415e6b14c60b9f788fcc987aa89e334f7f 100644 --- a/bbbmon/configuration.py +++ b/bbbmon/configuration.py @@ -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) diff --git a/bbbmon/meetings.py b/bbbmon/meetings.py index cbdb22740c224f2f6aeada7f1bc923a2eb7b8958..db01c367cfd04c05363ba7c951127058666ee14e 100644 --- a/bbbmon/meetings.py +++ b/bbbmon/meetings.py @@ -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"\ diff --git a/pyproject.toml b/pyproject.toml index 59c7305cc5dad987baa96b61e3b351f1d94a55a8..5fa874fd598d5c9d5245438bf4a07e35f5c74567 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [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>"]